CodeChef 补题
CodeChef 做题记录
The XOR-OR Dilemma
Chef has an array AA of length NN such that Ai=iAi=i.
In one operation, Chef can pick any two elements of the array, delete them from AA, and append either their bitwise XOR or their bitwise OR to AA.
Note that after each operation, the length of the array decreases by 11.
Let FF be the final number obtained after N−1N−1 operations are made. You are given an integer XX, determine if you can get F=XF=X via some sequence of operations.
In case it is possible to get F=XF=X, print the operations too (see the section Output format for more details), otherwise print −1−1.
给定1~n,你可以进行两种操作:
- 1 x y if you want replace x and y with x OR y.
- 2 x y if you want replace x and y with x XOR y
然后将x,y移除并将新值插入。给定x,求使得最终剩下的值为x的方案
构造的思路就是把所有的数全部或起来,然后和最终的数做异或得到tmp。然后用二进制拼接出tmp,用或操作,然后把剩下的没用到的数或起来最终两数异或便是答案。期间,特判不存在的解。
const int N=200010,M=N*2,mod=1e9+7;
int n,m,k,a[N];
struct Op{int op,a,b;
};void solve(){n=read(),m=read();int all=0;rep(i,1,n) all|=i;if(all<m){print(-1);return ;}int tmp=(all^m);if(tmp==0){int last=1;for(int i=2;i<=n;++i){printf("1 %d %d\n",i,last);last|=i;}return ;}vector<Op> vec(0);vector<int> temp;map<int,int> mp;for(int i=0;(1<<i)<=tmp;++i)if(tmp>>i&1){mp[1ll<<i]=1;temp.push_back(1ll<<i);}int cnt=0,last=0;for(int i=1;i<=n;++i){if(mp.count(i)) continue;if(cnt==0) {cnt++;last=i;}else {vec.push_back({1,last,i});last|=i;}}if(last!=all){print(-1);return ;}int u=0;for(int i=0;i<temp.size();++i){if(i==0) u=temp[i];else vec.push_back({1,u,temp[i]}),u|=temp[i];}vec.push_back({2,last, u});for(auto u:vec){printf("%d %d %d\n",u.op,u.a,u.b);}
}
Codecherf START51 Div4 Chef & Cook Game
H
There is a non-negative integer array AA of length NN. Chef and Cook will play a game on the array with Chef starting first.
In one turn the player will perform the following operation:
- Choose two indices i,j such that 1≤i<j≤N1 \le i \lt j \le N1≤i<j≤N and Ai>0A_i \gt 0Ai>0.
- Set Ai←Ai−1A_i \gets A_i-1Ai←Ai−1 and Aj←Aj+1A_j \gets A_j+1Aj←Aj+1,subtract 1 from AiA_iAi and add 1 to AjA_jAj
The player who is unable to perform the operation loses. If both Chef and Cook play optimally, who will win?
解法
首先,对于a[i]是偶数的位置,我们很容易想出来对照操作:只要你选了这个位置,我也选,因此对于偶数的位置我们不需要考虑。因此单独考虑a[i]为奇数的位置,我们可以将其转化为Nim游戏,对于i位置,可以移动到大于i的任意位置,因此可以看作可以取1~N-i个石子,所以我们把奇数位置的所有N-i异或起来,如果异或和不为0,则为先手必胜,否则先手必败。
void solve(){cin>>n;rep(i,1,n) cin>>a[i];if(n==1){cout << "Cook\n";return ;}LL sum=0;rep(i,1,n){if(a[i]&1) sum^=(n-i);}cout << (sum?"Chef":"Cook") << "\n";
}
September Lunchtime 2022 (Rated for All) (Based on EJOI)
- remove all elements from the array AA that are divisible by B_iB**i,
- remove all elements from the array AA that are not divisible by B_iB**i.
首先观察到尽管AiA_iAi的范围非常的大,但是如果在m比较大的情况下,最终答案直接是0.那么m在什么范围下答案直接是0呢?
Code:https://www.codechef.com/viewsolution/75158402
Adjacent Pairs
看别人代码写的,有点神奇的剪枝…
Code:https://www.codechef.com/viewsolution/75309277
Alternative Sufferings
K - Beautiful Permutation
Code:https://www.codechef.com/submit/KBPER?tab=statement
CodeChef 补题相关推荐
- 山东省第十届ACM浪潮杯补题
第一次参加省赛,可能也是最后一次了..有点遗憾,但是收获还是很多的.济南大学真大,饭菜也很好吃,志愿者小姐姐也很漂亮.上来题出的很快,差不多不到一个半小时就出了五道题,然后wa了两发.后面三个半小时全 ...
- Codeforces Round #701 (Div. 2)赛后补题报告(A~D)
Codeforces Round #701 (Div. 2)赛后补题报告(A~D) A. Add and Divide 原题信息 http://codeforces.com/contest/1485/ ...
- [nk] 2022牛客寒假算法基础集训营1 补题|题解
目录 前言 L.牛牛学走路 MyCode OtherCode J.小朋友做游戏 MyCode A.九小时九个人九扇门 MyCode F. 中位数切分 MyCode 前言 根据难度系数补题,大概会补 A ...
- 2018ACM-ICPC焦作站 补题
补题: A - Xu Xiake in Henan Province 题目大意:签到题,让你去做徐霞客qwq 代码: #include<iostream> #include<cstr ...
- [题单]多校补题 2017-2012
仅做初步了解并筛除了不大可能会解的题目 (一般都会咕的) hard表示榜单过题人数少于50或20(大概)的题目 ****2017**** 6034 贪心 6035 树形DP OO 6038 组合数学 ...
- xcpc近年铜牌题补题路
放弃幻想,准备打铁 随缘补题,学业繁重,补了就更. 45届上海站(2020) 4题铜牌,B,D,G,M G. Fibonacci 链接 鉴定为纯纯签到 给一个斐波那契数列,定义一个二元函数 g ( x ...
- QLU—新生训练赛002补题
I.十进制中的二进制 解题方法:直接把给定范围内的有0和1组成的数暴力输出,然后开个数组把这些数放进去,进而在数组中找要求的范围内符合条件的数就行了(一开始做的时候还以为有什么规律...一直在找规律, ...
- 杭电多校第六场个人补题6 7 9 10 12
杭电多校第六场个人补题6 7 9 10 12 6 题意 给定一棵有n结点的树,点权为1~n,求对所有结点子树的mex操作和的最大值 思路 其实就是从最底部开始网上找,由于0是唯一的一个,所欲最好给在最 ...
- 2020牛客国庆集训派对day2 补题J
2020牛客国庆集训派对day2 补题J:VIRUS OUTBREAK 题目描述 The State Veterinary Services Department recently reported ...
最新文章
- 2022-2028年成都餐饮业投资分析及前景预测报告
- 获取网页各种宽高的值
- dec++如何查看机器指令_机器指令到汇编再到高级编程语言!
- java面试题_1000道Java工程师面试题+答案PDF485页
- [WinAPI] API 14 [获取、设置文件属性和时间]
- C#面向对象基础(四) 静态成员与实例成员
- jquery图片预加载+自动等比例缩放插件
- linux条件变量唤醒丢失,多线程编程精髓(三)
- Hbase常用数据库操作类
- 卡巴斯基病毒库离线更新教程(转)
- 在vue中使用wow动画插件(下载,配置,使用,参数)
- linux 程序网速监控软件,Linux实时网速监控软件ifstat简易教程
- Steinitz exchange lemma
- MemCache详解
- ionic 服务器消息推送,Ionic3 本地消息推送
- pe中怎么卸载服务器系统更新,如何卸载win7系统更新用pe装win7
- 文本特征选择的关键算法总结
- 【Blog】Hexo_Next_博客搭建记 (by onlychristmas)
- 【文本分类】文本分类流程及算法原理
- oracle 单记录函数,SQL中的单记录函数