HDU 5536 Chip Factory
来源:互联网 发布:知らない打ち合わせ 编辑:程序博客网 时间:2024/05/29 18:26
这题我做了三次,三次都把异或看成了与,真心无语
一道基础字典树,记住初始化根
#include <cstdio>#include <algorithm>using namespace std;struct Trie{ Trie *next[2]; int cnt;};Trie *root = new Trie;void init(Trie *p){ p->next[0] = p->next[1] = NULL; p->cnt = 1;}void insert(char *p, int add){ Trie *now = root, *newnode; while(*p != '\0' && now ->next[*p - '0'] != NULL) { now = now->next[*p++ - '0']; now->cnt += add; } while(*p != '\0') { newnode = new Trie; init(newnode); now->next[*p++ - '0'] = newnode; now = newnode; }}int query(char *p){ Trie *now = root; int res = 0; while(*p != '\0') { res <<= 1; int t = (*p++ - '0') ^ 1; if(now->next[t] != NULL && now->next[t]->cnt != 0) now = now->next[t], res++; else now = now->next[t^1]; } return res;}int a[1005];char s[35];void toString(int t){ for(int i = 31; i >= 0; i--) s[i] = '0' + (t & 1), t >>= 1; s[32] = '\0';}int main(){ int T; scanf("%d", &T); while(T--) { init(root); int n; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &a[i]); toString(a[i]); insert(s, 1); } int Max = 0; for(int i = 0; i < n; i++) { toString(a[i]); insert(s, -1); for(int j = i + 1; j < n; j++) { toString(a[j]); insert(s, -1); toString(a[i] + a[j]); Max = max(Max, query(s)); toString(a[j]); insert(s, 1); } toString(a[i]); insert(s, 1); } printf("%d\n", Max); } return 0;}
0 0
- hdu 5536 Chip Factory
- HDU 5536 Chip Factory
- 【HDU】 5536 Chip Factory
- HDU 5536 Chip Factory
- hdu 5536 Chip Factory (暴力)
- hdu 5536 Chip Factory 字典树
- HDU 5536 Chip Factory 01字典树
- HDU-5536 Chip Factory(字典树)
- Chip Factory(HDU 5536 纯暴力)
- hdu 5536 Chip Factory 01 Trie
- HDU 5536 Chip Factory (01Trie)
- HDU 5536 Chip Factory (字典树)
- HDU 5536 Chip Factory(01字典树)
- HDU 5536 Chip Factory (枚举+01Trie)
- 01trie树 HDU 5536Chip Factory
- hdu 5536 Chip Factory(字典树)
- HDU 5536 Chip Factory 01trie
- HDU 5536 Chip Factory 【01字典树】
- Linux虚拟文件系统之文件系统卸载(sys_umount())
- 无法启动openfire服务器
- Note
- Linux虚拟文件系统之文件打开(sys_open())
- Mobiscroll脚本破解,去除Trial和注册时间限制
- HDU 5536 Chip Factory
- timestamp 的两个属性:CURRENT_TIMESTAMP 和ON UPDATE CURRENT_TIMESTAMP
- Linux虚拟文件系统之文件读取(sys_read())
- nginx url重写
- 1065. A+B and C (64bit) (20)
- oracle number数据类型的精度
- dreamweaver cs6 mac 破解版
- 关于vs开发windows程序过程中内存检查二三事
- Android - 电话拦截