problemscpp
A collection of my answers to algorithm problems in c++.
| 函数
acwing::acwing143 命名空间参考

  1. 最大异或对
更多...

struct  TrieNode
 

函数

int main (istream &cin, ostream &cout)
 
 TEST (acwing143, case1)
 

详细描述

  1. 最大异或对

函数说明

◆ main()

int acwing::acwing143::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing.cpp6958 行定义.

6958 {
6959 int n;
6960 cin >> n;
6961 vector<string> vec(n);
6962 TrieNode tn;
6963 for(int j = 0; j < n; j++) {
6964 unsigned a;
6965 cin >> a;
6966 ostringstream oss;
6967 for(int i = 30; i >= 0; i--) {
6968 oss << ((a & 1 << i) != 0U ? '1' : '0');
6969 }
6970 string str = oss.str();
6971 vec[j] = str;
6972 tn.insert(str, 0);
6973 }
6974 unsigned maximum = 0;
6975 for(const auto &str: vec) {
6976 const TrieNode *current = &tn;
6977 unsigned ans = 0;
6978 for(int i = 0; i <= 30; i++) {
6979 ans <<= 1;
6980 if(current->next[str[i] - '0' == 0] != nullptr) {
6981 current = current->next[str[i] - '0' == 0];
6982 ans += 1;
6983 } else {
6984 current = current->next[str[i] - '0'];
6985 }
6986 }
6987 maximum = max(maximum, ans);
6988 }
6989 cout << maximum;
6990 return 0;
6991 }
int vec[100010]
Definition: pat.cpp:5095
void insert(const string &str, int i)
Definition: acwing.cpp:6993
字典树节点
Definition: templates.h:9

引用了 acwing::acwing143::TrieNode::insert(), acwing::acwing143::TrieNode::next , 以及 pat::a::a7_2::vec.

被这些函数引用 TEST().

◆ TEST()

acwing::acwing143::TEST ( acwing143  ,
case1   
)

在文件 acwing_test.cpp3263 行定义.

3263 {
3264 istringstream in("3\n"
3265 "1 2 3");
3266 auto out = ostringstream();
3267 main(in, out);
3268 const auto ans = out.str();
3269 ASSERT_EQ("3", ans);
3270 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().