Codeforces Round #371 (Div. 2) C 大模拟
http://codeforces.com/contest/714/problem/C
题目大意:有t个询问,每个询问有三种操作
①加入一个数值为a[i]的数字
②消除一个数值为a[i]的数字
③给一个字符串s,s中分别表示0和1,0表示目前该位为偶数,1表示目前该位为奇数。然后询问目前数组中和s每一位能匹配的个数。如果数组中目前的该数字比s的len要短,那么我们就在s的左边一直加0。如果数组中的目前的数字比s的len长,那么就在该数组的左边一直加0就好了。问能和s匹配的有几个,并输出
思路:我是用map来标记奇偶的,因为有前导0,所以我们把0的val都改成2,首先dfs出所有的情况,并每次给他标上一个ID,然后每次询问的时候找ID就好了。
貌似看到别人用的是trie树来做。。。
//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha; printf("haha\n");
const int maxn = 1e6 + ;
int dfsclock;
map<LL, int> ID;
LL cnt[maxn], cnt2[maxn]; LL cal(LL x, int n){
LL res = ;
while (n){
if (n & ) res = res * x;
x = x * x;
n >>= ;
}
return res;
} void dfs(LL val, int cell){
if (cell == ) return ;
LL add = cal(10LL, cell);
for (LL i = ; i <= ; i++){
ID[val + add * i] = ++dfsclock;
dfs(val + add * i, cell + );
}
}
///1~18位,变成0~17位
int main(){
dfs(0LL, );
ID[] = ++dfsclock;
int t; cin >> t;
char ch[];
for (int i = ; i < t; i++){
char s[]; scanf("%s %s", s, ch);
int len = strlen(ch);
LL val = ;
if (s[] == '+') {
for (int j = len - ; j >= ; j--){
ch[j] -= '';
if (ch[j] % == ) {
val += * cal(10LL, len - - j);
}
else {
val += * cal(10LL, len - - j);
}
cnt[ID[val]]++;
}
for (int i = len; i <= ; i++){///扩张到18位的
val += * cal(10LL, i);
cnt[ID[val]]++;
}
}
else if (s[] == '-'){
for (int j = len - ; j >= ; j--){
ch[j] -= '';
if (ch[j] % == ) {
val += * cal(10LL, len - - j);
}
else {
val += * cal(10LL, len - - j);
}
cnt[ID[val]]--;
}
for (int i = len; i <= ; i++){
val += * cal(10LL, i);
cnt[ID[val]]--;
}
}
else if (s[] == '?'){
LL ans = ;
int pos = ;
for (int i = ; i <= len - ; i++){
if (ch[i] != '') {
pos = i; break;
}
}
for (int i = len - ; i >= ; i--){
if (ch[i] == '') val += * cal(10LL, len - - i);
else val += * cal(10LL, len - - i);
}
ans += cnt[ID[val]];
for (int i = len; i <= ; i++){
LL tmp = * cal(10LL, i);
ans += cnt[ID[val + tmp]] - cnt[ID[val]];///每次增加的匹配数一定是在前一个集合里面没有出现过的
val += tmp;
}
printf("%I64d\n", ans);
}
}
return ;
}
Codeforces Round #371 (Div. 2) C 大模拟的更多相关文章
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #398 (Div. 2) A. Snacktower 模拟
A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #543 (Div. 2) D 双指针 + 模拟
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...
- 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 ...
- Codeforces Round #371 (Div. 2)B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...
- Codeforces Round #371 (Div. 2) - B
题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...
随机推荐
- sdk是啥
SDK 英文名称 software development kit ,即 软件开发工具包,就好第三方服务商提供的实现软件某功能的工具包
- 未知的生成错误 因为没有预加载,所以无法解析程序集 GalaSoft.MvvmLight
使用wpf开发时,在ViewModel中引用了DevExpress注册的GalaSoft.MvvmLight命名空间,使用其ViewModelBase,在View界面中绑定事件时出现错误: 错误 13 ...
- CSU 1640 机智的刷题方式
完全背包 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- [妙味JS基础]第二课:for应用、this关键字
知识点总结 getElementsByTagName(动态方法) 与 getElementById(静态方法) 的区别 1.ID前面只能跟document,不能跟其他元素,比如:document.ge ...
- 《JS权威指南学习总结--第九章 类和模板》
内容要点: 一. 1.第六章详细介绍了JS对象,每个JS对象都是一个属性集合,相互之间没有任何联系.在JS中也可以定义对象的类,让每个对象都共享某些属性,这种"共享"的特性是非常有 ...
- HDU 1335 Basically Speaking(进制转换)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335 Problem Description The Really Neato Calculator ...
- vim 替换
摘自: vim替换命令 替換(substitute) :[range]s/pattern/string/[c,e,g,i] range 指的是範圍,1,7 指從第一行至第七行,1,$ 指從第一行至最後 ...
- bootstrap复习:组件
一.下拉菜单 1.实例:将下拉菜单触发器和下拉菜单都包裹在 .dropdown 里,或者另一个声明了 position: relative; 的元素.然后加入组成菜单的 HTML 代码.为下拉菜单的父 ...
- Openjudge-计算概论(A)-短信计费
描述: 用手机发短信,一条短信资费为0.1元,但限定一条短信的内容在70个字以内(包括70个字).如果你一次所发送的短信超过了70个字,则会按照每70个字一条短信的限制把它分割成多条短信发送.假设已经 ...
- There was a problem parsing the package(android)
android phone when you install the application there will inevitably be "a problem parsing the ...