http://codeforces.com/contest/714/problem/C

看到这题目,想想,肯定不能暴力啊,如果用map,如何快速找到满足要求的数目,然后,长度18,我想,这不是熟悉的trie树么,还犹豫什么,把所有的输入都处理成长度为18的字符串,处理就行了,然后调试了一会,就交了,然后tle了,我就怀疑了,难道不是这样的套路么?!然后就开始查答案,一看官方题解,恍然大悟,这道题目有个很好的性质,就是插入11和插入33的效果是一样的,删除11和删除33的效果是一致的,同一种模型,我们不必具体的区分该位具体是什么,比如奇数(1,3,5,7,9)都可以简单用1来表示,偶数(0,2,4,6,8)都可以用0表示,这样题目就化简很多,还要trie树做什么,同一种模式可以归为一类,总共1 << 18种方式,然后单独统计,单独输出,就ok!就完了,感觉还是太笨了!也没仔细去分析。

 #include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = << ;
int a[maxn];
int n;
char ch[];
ll x;
ll d[];
void solve() {
d[] = ;
for (int i = ; i < ; i++) d[i] = d[i - ] * ;
scanf("%d", &n);
while(n--) {
scanf("%s", ch);
//cout << ch << endl;
if(ch[] == '?') {
scanf("%s", ch);
int l = strlen(ch);
int t = ;
for (int i = ; i < l; i++) {
if(ch[i] == '')
t |= ( << (l - i - ));
}
//cout << "ask " << t << endl;
printf("%d\n", a[t]);
} else {
scanf("%I64d", &x);
int t = ;
for (int i = ; i >= ; i--) {
int td = x / d[i];
x %= d[i];
if(td & ) t |= ( << i);
}
//cout << "test "<< t << endl;
if(ch[] == '+')
a[t]++;
else a[t]--;
}
}
}
int main() { //freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
solve();
return ;
}

C. Sonya and Queries的更多相关文章

  1. Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]

    C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces 714C. Sonya and Queries Tire树

    C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...

  3. codeforces 713A A. Sonya and Queries(状态压缩)

    题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input st ...

  4. Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题

    C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...

  5. Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩

    题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...

  6. Codeforces 713A. Sonya and Queries

    题目链接:http://codeforces.com/problemset/problem/713/A 题意: Sonya 有一个可放置重复元素的集合 multiset, 初始状态为空, 现给予三种类 ...

  7. Codeforces Round #371 (Div. 2) C. Sonya and Queries

    题目链接 分析:01trie树,很容易就看出来了,也没什么好说的.WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0.我没有晚上爬起来打,白天发现过的人极多. /******** ...

  8. [Codeforces_713A]Sonya and Queries

    题目链接 http://codeforces.com/problemset/problem/713/A 题意 三种操作: +  ai 集合里加一个整数ai,相同数记为多个.  -  ai 集合里减一个 ...

  9. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

随机推荐

  1. Visual C#使用DirectX实现视频播放

    Visual C#使用DirectX实现视频播放 visual|视频播放 - 很多人第一次接触到DirectX大都是通过游戏,至于安装.升级DirectX的原因无非是满足游戏运行的需要.Direct ...

  2. jsp值传到后台Struts2中的action三种方法

    Action接收表单传递过来的参数有3种方法: 如,登陆表单login.jsp: <form action="login" method="post" n ...

  3. HDU 2112 HDU Today -- from lanshui_Yang

    此题主要是要用到字符串向整数的映射 , 很自然的想到了 STL 中的map ,哎,贡献无数次WA,最后才发现每次运行时 map 忘了清空 !!!!本题,用dijkstra 和 spfa 均可 ,但是要 ...

  4. iOS 改变tableview cell的背景色

    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame]; cell.selectedBackgroundView ...

  5. android开发学习:打电话和发短信

    1.新建一个android项目 File--New--Other--android application project 填写application name(就是应用的名字.比方:天天酷跑) 填写 ...

  6. BZOJ 1022 SHOI2008 小约翰的游戏John 博弈论

    题目大意:反Nim游戏,即取走最后一个的人输 首先状态1:假设全部的堆都是1,那么堆数为偶先手必胜,否则先手必败 然后状态2:假设有两个堆数量同样且不为1,那么后手拥有控场能力,即: 若先手拿走一堆, ...

  7. Eclipse安装ADT失败解决办法

    Eclipse的版本是3.5.2,配置Android的开发环境时遇到问题…… 按照Android官方文档一步步安装,到了安装Eclipse的ADT插件时,提示“requires 'org.eclips ...

  8. visual studio 2013 有效序列号

    还没试过,可以参考下! visual studio 2013 有效序列号: BWG7X-J98B3-W34RT-33B3R-JVYW9

  9. eclipse中不能找到dubbo.xsd解决方法

    使用dubbo时遇到问题: org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'htt ...

  10. Unit Testing a zend-mvc application

    Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...