2017ACM/ICPC广西邀请赛-重现赛1005 CS course
2017-08-31 16:19:30
writer:pprp
这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前
的训练都是面向题解编程的缘故吧,以后不能这样了,另外这几天要学习一下动态规划,
先普及两个小知识点,这个点很简单很简单但是却卡了我很久很久,
现在作为模板记录下来:
1、将二进制数转化为十进制数
//转化为十进制
//test:ok
ll twoTen(int a[])
{
ll ans = ;
for(int i = ; i < N ; i++)
{
ans += ( << i ) * a[i];
}
return ans;
}
2、将十进制数转化为二进制数(bt是一个全局的数组)
//转化为二进制
//test:ok
void tenTwo(int tmp)
{
memset(bt,,sizeof(bt));
int i = ;
while(tmp)
{
bt[i++] = tmp%;
tmp /= ;
}
}
CS Course
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework.
Here is the problem:
You are giving n non-negative integers a1
,a
2
,⋯,a
n
, and some queries.
A query only contains a positive integer p, which means you
are asked to answer the result of bit-operations (and, or, xor) of all the integers except ap
.
Each test case begins with two positive integers n and p
in a line, indicate the number of positive integers and the number of queries.
2≤n,q≤105
Then n non-negative integers a1
,a
2
,⋯,a
n
follows in a line, 0≤ai
≤10
9
for each i in range[1,n].
After that there are q positive integers p1
,p
2
,⋯,p
q
in q lines, 1≤pi
≤n
for each i in range[1,q].
in a line.
#include <bits/stdc++.h> using namespace std; typedef long long ll;
const int maxn = 1e5;
const int N = ;
int arr[maxn];
int bt[N]; //转化为十进制
//test:ok
ll twoTen(int a[])
{
ll ans = ;
for(int i = ; i < N ; i++)
{
ans += ( << i ) * a[i];
}
return ans;
}
//转化为二进制
//test:ok
void tenTwo(int tmp)
{
memset(bt,,sizeof(bt));
int i = ;
while(tmp)
{
bt[i++] = tmp%;
tmp /= ;
}
} int main()
{
// freopen("out.txt","r",stdin);
ios::sync_with_stdio(false);
int record0[N];
int record1[N];
int a, b;
int tmp;
int ansAnd[N];
int ansOr[N];
while(cin >> a >> b)
{
memset(ansAnd,,sizeof(ansAnd));
memset(ansOr,,sizeof(ansOr));
memset(record0,,sizeof(record0));
memset(record1,,sizeof(record1));
memset(bt,,sizeof(bt));
memset(arr,,sizeof(arr));
int ansXor = -;
//用来处理对0对1处理的计数
for(int i = ; i < a ; i++)
{
cin >> tmp;
arr[i] = tmp;
tenTwo(tmp);
//对异或的处理
if(ansXor == -)
ansXor = tmp;
else
ansXor ^= tmp;
//对和还有或的处理
for(int j = ; j < N ; j++)
{
if(bt[j] == )
{
record0[j]++;
}
else
{
record1[j]++;
}
}
} int tmpXor = ansXor;
for(int i = ; i < b ; i++)
{
ansXor = tmpXor;
cin >> tmp;
//将这个值从记录中取出来--ok
tmp = arr[tmp-];
//先对异或情况进行处理--ok
ansXor ^= tmp;
//对剩下两种情况进行处理--ok
memset(bt,,sizeof(bt));
tenTwo(tmp);
//将对应为的值减去
for(int j = ; j < N ; j++)
{
if(bt[j] == )
record0[j]--;
else
record1[j]--;
}
//判断或还有和的情况
for(int i = ; i < N ; i++)
{
if(record0[i] > )
ansAnd[i] = ;
else
ansAnd[i] = ; if(record1[i] > )
ansOr[i] = ;
else
ansOr[i] = ;
} cout << twoTen(ansAnd) << " " << twoTen(ansOr) << " " << ansXor << endl; for(int j = ; j < N ; j++)
{
if(bt[j] == )
record0[j]++;
else
record1[j]++;
}
}
}
return ;
}
总结:
1、这个也是采用每次一调试的办法来做的,但是这次调试中出现了重大失误,由于对以上两个函数调试的不严谨,
判断数据过小,导致小的数据可以过,但是大一点的数据就会失败的情况,这也是这么多次wa的原因
2、还是没有习惯用printf,所以以后写代码就加上fast_io,以后写代码尽量使用带加速到cin函数
3、数据生成器用另外一个project来写,用生成的数据进行对拍,这次发现错误考的就是对拍,没有对拍就很难改下去了,
这道题的对拍比较好些,虽然我用的是别人的代码做的对拍,但是这个对拍很容易写出来,就是运行时间有点长
4、这次还有重大错误就是作用域问题,使用memset的时候要看清作用的范围,还有各种初始化条件,都要关心每一遍的
遍历的作用
5、另外在面对一个循环中的多次询问,要保证每次的询问对下次的询问没有影响,恢复现场才可以。
6、hdu可以用bits/stdc++.h头文件
2017ACM/ICPC广西邀请赛-重现赛1005 CS course的更多相关文章
- 2017ACM/ICPC广西邀请赛-重现赛
HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...
- 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
- 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree
Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...
- 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
Problem Description Bob's school has a big playground, boys and girls always play games here after s ...
- 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem
2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...
- 2017ACM/ICPC广西邀请赛 1005 CS Course
CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 2017ACM/ICPC广西邀请赛 CS Course
题意:删除指定数字,求剩下数字的与或非值 解法:保存一下前缀和后缀 #include <iostream> #include <stdio.h> #include <ve ...
- HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...
随机推荐
- python脚本前两行
1. 第一行指定解释器路径 推荐写法: #!/usr/bin/env python 详细说明: #!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python ...
- setup.py
from distutils.core import setup # 使用说明 # 执行以下命令 # python3 setup.py build # python3 setup.py sdist(这 ...
- IDOC 实例测试
这份文档主要是自己学习IDOC的一些练习过程及心得,可能讲的不全面,但应该可以帮助大家了解IDOC的一些工作方式. IDOC或者说是ALE,事实上,是SAP用于分布和集成数据的一种方式.所以,我个人就 ...
- 新建虚拟机与本机ping不通(一招解决)
初始新建虚拟机或者复制虚拟机后,发现虚拟机能ping通内外网,但是本机无法ping通虚拟机,xshell也无法连接虚拟机 这时候就很头疼了,因为要上传很多文件到虚拟机上面 解决办法: 1.关闭虚拟机后 ...
- Go实现查找目录下(包括子目录)替换文件内容
[功能] 按指定的目录查找出文件,如果有子目录,子目录也将进行搜索,将其中的文件内容进行替换. [缺陷] 1. 没有过滤出文本文件 2. 当文件过大时,效率不高 [代码] package main i ...
- Oracle 常见问题汇总
1.Listener refused the connection with the following error 安装之后如果遇到如下问题状态: 失败 -测试失败: Listener refuse ...
- Linux-vim与ssh客户端
一.vim使用 Linux系统下标准的编辑器,他就相当于windows系统中的记事本一样,它的强大不逊色于任何最新的文本编辑器. (1)vim安装 (2)vim使用:操作模式 一般模式(默认模式,不 ...
- YYModel源代码阅读--基础知识
这段时间因为工作需要,阅读了YYModel这个开源框架,至于它能做什么,最直白的讲述就是JSON与Model之间的相互转化. 源代码在Github,大家可以自行git clone或者download. ...
- WebBrowser自动填充打开文件对话框
WebBrowser自动填充打开文件对话框 在使用WebBrowser编写自动表单填写软件的时候,不知道大家是否遇到国填写文件选择表单的情况.遇到这种情况的时候,无法直接队Html元素赋值,必须模 ...
- python阳历转阴历,阴历转阳历
#!/usr/bin/env python # coding:utf8 # author:Z time:2019/1/16 import sxtwl # 日历中文索引 ymc = [u"十一 ...