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 Numbers

Two players are playing a game. They are given an array A_1, A_2, \ldots, A_NA1,A2,…,A**N as well as an array B_1, B_2, \ldots, B_MB1,B2,…,B**M.

The game consists of MM rounds. Players are participating in rounds alternatively. During the ii-th round (for ii from 11 to MM) the corresponding player (first player, if ii is odd, and second if ii is even) has to do exactly one of the following:

The first player wants to minimize the sum of the remaining elements in the array AA after all MM rounds, and the second wants to maximize it. Find the sum of the remaining elements in the array AA after all MM rounds if both players are playing optimally.

题解:

首先观察到尽管AiA_iAi​的范围非常的大,但是如果在m比较大的情况下,最终答案直接是0.那么m在什么范围下答案直接是0呢?

假设对于想要让数组尽可能小的那个人操作,对于他操作的集合首先尽量满足每个数都不一样,然后由于Ai≤1014A_i \le 10^{14}Ai​≤1014而且18!>101418! \gt 10^{14}18!>1014所以对于这个人当他操作18次或者以上的时候一定能把数组变成全部都是0.因此对于两个人而言,如果数组容量大于36,则答案一定是0.对于数组容量小于36的情况直接搜索即可。

Code:https://www.codechef.com/viewsolution/75158402

Adjacent Pairs

看别人代码写的,有点神奇的剪枝…
Code:https://www.codechef.com/viewsolution/75309277

Alternative Sufferings

这道题蛮有意思是的。首先我们得先做一遍整个字符串的操作。然后对于每个位置找到他第一次变成1的时间,然后变成1之后它后面的变化规律就是10101010…直接可以通过奇偶性来判断了。
Code:https://www.codechef.com/viewsolution/76198290

K - Beautiful Permutation

一道比较典的DP题,看数据范围可以设出状态dp[i][j][k][0/1]表示前i个位置分成j段其中选择了k个奇数,上一个选择的是奇/偶的方案数。
我们需要预先处理一下even[i]和odd[i]表示已经确定的位置的偶数和奇数的前缀和,便于转移。然后转移过程见代码。

Code:https://www.codechef.com/submit/KBPER?tab=statement

CodeChef 补题相关推荐

  1. 山东省第十届ACM浪潮杯补题

    第一次参加省赛,可能也是最后一次了..有点遗憾,但是收获还是很多的.济南大学真大,饭菜也很好吃,志愿者小姐姐也很漂亮.上来题出的很快,差不多不到一个半小时就出了五道题,然后wa了两发.后面三个半小时全 ...

  2. Codeforces Round #701 (Div. 2)赛后补题报告(A~D)

    Codeforces Round #701 (Div. 2)赛后补题报告(A~D) A. Add and Divide 原题信息 http://codeforces.com/contest/1485/ ...

  3. [nk] 2022牛客寒假算法基础集训营1 补题|题解

    目录 前言 L.牛牛学走路 MyCode OtherCode J.小朋友做游戏 MyCode A.九小时九个人九扇门 MyCode F. 中位数切分 MyCode 前言 根据难度系数补题,大概会补 A ...

  4. 2018ACM-ICPC焦作站 补题

    补题: A - Xu Xiake in Henan Province 题目大意:签到题,让你去做徐霞客qwq 代码: #include<iostream> #include<cstr ...

  5. [题单]多校补题 2017-2012

    仅做初步了解并筛除了不大可能会解的题目 (一般都会咕的) hard表示榜单过题人数少于50或20(大概)的题目 ****2017**** 6034 贪心 6035 树形DP OO 6038 组合数学 ...

  6. xcpc近年铜牌题补题路

    放弃幻想,准备打铁 随缘补题,学业繁重,补了就更. 45届上海站(2020) 4题铜牌,B,D,G,M G. Fibonacci 链接 鉴定为纯纯签到 给一个斐波那契数列,定义一个二元函数 g ( x ...

  7. QLU—新生训练赛002补题

    I.十进制中的二进制 解题方法:直接把给定范围内的有0和1组成的数暴力输出,然后开个数组把这些数放进去,进而在数组中找要求的范围内符合条件的数就行了(一开始做的时候还以为有什么规律...一直在找规律, ...

  8. 杭电多校第六场个人补题6 7 9 10 12

    杭电多校第六场个人补题6 7 9 10 12 6 题意 给定一棵有n结点的树,点权为1~n,求对所有结点子树的mex操作和的最大值 思路 其实就是从最底部开始网上找,由于0是唯一的一个,所欲最好给在最 ...

  9. 2020牛客国庆集训派对day2 补题J

    2020牛客国庆集训派对day2 补题J:VIRUS OUTBREAK 题目描述 The State Veterinary Services Department recently reported ...

最新文章

  1. 2022-2028年成都餐饮业投资分析及前景预测报告
  2. 获取网页各种宽高的值
  3. dec++如何查看机器指令_机器指令到汇编再到高级编程语言!
  4. java面试题_1000道Java工程师面试题+答案PDF485页
  5. [WinAPI] API 14 [获取、设置文件属性和时间]
  6. C#面向对象基础(四) 静态成员与实例成员
  7. jquery图片预加载+自动等比例缩放插件
  8. linux条件变量唤醒丢失,多线程编程精髓(三)
  9. Hbase常用数据库操作类
  10. 卡巴斯基病毒库离线更新教程(转)
  11. 在vue中使用wow动画插件(下载,配置,使用,参数)
  12. linux 程序网速监控软件,Linux实时网速监控软件ifstat简易教程
  13. Steinitz exchange lemma
  14. MemCache详解
  15. ionic 服务器消息推送,Ionic3 本地消息推送
  16. pe中怎么卸载服务器系统更新,如何卸载win7系统更新用pe装win7
  17. 文本特征选择的关键算法总结
  18. 【Blog】Hexo_Next_博客搭建记 (by onlychristmas)
  19. 【文本分类】文本分类流程及算法原理
  20. oracle 单记录函数,SQL中的单记录函数

热门文章

  1. JS删除对象中的某一属性
  2. 蜻蜓FM信息流推荐探索与实践
  3. 快递对接京东,菜鸟,顺丰过程备忘录
  4. displaytag的使用
  5. java swing 创建一个简单的QQ界面
  6. 小程序图片加载不出来(显示)
  7. 程序员端午过了回杭州的一点思考
  8. 好马配好鞍,Windows 8配神马电脑
  9. python 文件读取错误之FileNotFoundError: [Errno 2] No such file or directory:,顺便学习斜杠/和反斜杠\的用法
  10. 函数柯里化(curry)