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/不变,最 ...
随机推荐
- openstack私有云布署实践【4.2 上层代理haproxy+nginx配置 (办公网测试环境)】
续上一节说明 一开始我也是使用haproxy来做的,但后来方式改了,是因为物理机controller的高配置有些浪费,我需要1组高可用的上层nginx代理服务器来实现其它域名80代理访问,很多办公网测 ...
- win10下安装Django
Django的核心(1.4+)可以运行在从2.5到2.7之间的任何Python版本. 我的电脑是操作系统是window10 ,内存是4G. 1.下载django 官网地址:https://www.dj ...
- 第18天 ajax技术和javascript加强(json)
第18天 ajax技术和javascript加强(json) 复习: B/S架构实现文件上传的思路? 使用a标签实现文件下载功能,有什么问题? 使用Servlet实现文件下载的思路? 今日任务 ...
- hdu1015
#include <stdio.h>#include <string.h>#include <stdlib.h> int cmp(void* a, void* b) ...
- Swift逃逸闭包之见解
Swift 逃匿闭包顾名思义,就是闭包想要逃跑.当闭包作为参数传给一个方法时,在这个方法被调用完后闭包却还没有被执行,而是等到方法执行完后才调用 基本都是跨线程的时候才会有逃逸闭包这个说法.因为异步 ...
- Hierarchyid(层次结构)数据类型
实例表结构 CREATE TABLE [dbo].[Emp]( ,), ), [Org] [hierarchyid], ) INSERT INTO Emp(Name,Org) VALUES('吴xx' ...
- LINQ里的“equals”和“==”的区别
对于值类型,如果对象的值相等,则相等运算符 (==) 返回 true,否则返回 false.对于string 以外的引用类型,如果两个对象引用同一个对象,则 == 返回 true.对于 string ...
- 针对IE的CSS样式hack
针对IE的CSS样式hack,如下: 例子:background:#000: 1.只针对IE6的hack方式(_):_background:#000: 2.只针对IE7的hack方式(+):+back ...
- openwrt 更改 debug 等级(hostapd)
https://wiki.openwrt.org/doc/devel/debugging 调试hostapd,其中hostapd的调试等级如下: # Levels (minimum value for ...
- HDU 2955 Robberies(01背包)
Robberies Problem Description The aspiring Roy the Robber has seen a lot of American movies, and kno ...