Codeforces Round #443 (Div. 2) C. Short Program 【模拟】
来源:互联网 发布:怎么在手机淘宝买彩票 编辑:程序博客网 时间:2024/06/06 03:29
数字的范围为1-1023,所以用二进制表示需要10位。维护一个长度为10的数组a,分别代表每一位最后的值,取值一共有三种0,1和未知。
对于与操作,a数组对应位置上的数字置为0。对于或操作,a数组对应位置上的数字置为1。对于异或操作,如果a对应位置上的数字已经确定,则直接异或,否者另外用记录一下。最终答案由3种操作组成,或操作的数字是a数组中所有为1的位置表示的二进制数,与操作数是1023-a数组中所有为0的位置表示的二进制数的结果,异或是a数组中所有不确定位置上数需要异或的值组成的数字。
/* ***********************************************Author :xiang578Email :i@xiang578.comCreated Time :Sat Nov 4 07:52:30 2017File Name :cf879c.cpp************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;char s[1000000+5][10];int a[1000000+5];int b[20];int c[20];int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; scanf("%d",&n); memset(b,0xff,sizeof(b)); memset(c,0xff,sizeof(c)); for(int i=0;i<n;i++) { scanf("%s%d",s[i],&a[i]); if(s[i][0]=='|') { for(int j=0;j<10;j++) { if(a[i]&(1<<j)) {c[j]=-1;b[j]=1;} } } else if(s[i][0]=='&') { for(int j=0;j<10;j++) { if((a[i]&(1<<j))==0) {c[j]=-1;b[j]=0;} } } else{ for(int j=0;j<10;j++) { if(b[j]==-1) { if(c[j]==-1) c[j]=(a[i]>>j)&1; else c[j]^=(a[i]>>j)&1; } else if(a[i]&(1<<j)) { b[j]^=1; } else { b[j]^=0; } //printf("%d %d\n",j,c[j]); } } } int ans1=0; for(int j=0;j<10;j++) { if(b[j]==1) ans1+=1<<j; } int ans2=1023; for(int j=0;j<10;j++) { if(b[j]==0) ans2-=1<<j; } int ans3=0; for(int j=0;j<10;j++) { if(c[j]==1) ans3+=1<<j; } printf("3\n| %d\n& %d\n^ %d\n",ans1,ans2,ans3); //if(n<=5) //{ //printf("%d\n",n); //for(int i=0;i<n;i++) //printf("%s %d\n",s[i],a[i]); //return 0; //} return 0;}
阅读全文
0 0
- Codeforces Round #443 (Div. 2) C. Short Program 【模拟】
- Codeforces Round #443 (Div. 2): C. Short Program
- Codeforces Round #443 (Div. 2) C Short Program
- Codeforces Round #443 (Div. 2) C. Short Program
- Codeforces Round #443 (Div. 2) C. Short Program
- Codeforces Round #879 (Div. 2) C. Short Program
- Codeforces Round #443(Div.2) C.Short Program(位运算+思维)
- Codeforces #443 Div.2 C. Short Program 【位操作】
- Codeforces Round #443 (Div. 1) A. Short Program
- Codeforces Round #346 (Div. 2) C模拟
- Codeforces Round #325 (Div. 2) C 模拟
- Codeforces Round #316 (Div. 2) C 模拟
- Codeforces Round #306 (Div. 2) C 模拟
- Codeforces Round #126 (Div. 2) C 模拟
- Codeforces Round #373 (Div. 2) C 模拟
- Codeforces Round #377 (Div. 2) C 模拟
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) C 模拟
- Codeforces Round #138 (Div. 2) c 数据结构模拟
- 优先级队列PriorityQueue
- HTTPS证书验证流程及SSL证书生成步骤【附nginx开启https配置】
- JAVA基础(二)
- React 组件性能优化
- Caffe
- Codeforces Round #443 (Div. 2) C. Short Program 【模拟】
- JSP的学习(6)——九大隐式对象及其out对象
- C++11中的右值引用
- React高阶组件应用
- Eclipse中安装Java Swing图形界面开发插件windowbuilder
- UltraEdit & Beyond Compare Linux 无限shiyogn
- Java基础恶补——内存泄露、内存溢出
- 创建一个Springboot应用(二)
- G