【codechef】Chef and A Large Permutation(技巧题)
来源:互联网 发布:java 启动定时器 编辑:程序博客网 时间:2024/06/06 01:56
Today is Chef's birthday. His mom gifted him a truly lovable gift, a permutation of first N positive integers.
She placed the permutation on a very long table in front of Chef and left it for him to play with it. But as there was a lot of people coming and wishing him. It was interfering with his game which made him very angry and he banged the table very hard due to which K numbers from the permutation fell down and went missing.
Seeing her son's gift being spoilt, his mom became very sad. Chef didn't want his mom to be sad as he loves her the most. So to make her happy, he decided to play a game with her with the remaining N - Knumbers on the table. Chef wants his mom to win all the games.
Chef and his mom play alternatively and optimally. In Xth move, a player can choose some numbers out of all the numbers available on the table such that chosen numbers sum up to X. After the move, Chosen numbers are placed back on the table.The player who is not able to make a move loses.
Now, Chef has to decide who should move first so that his Mom wins the game.
As Chef is a small child, he needs your help to decide who should move first. Please help him, he has promised to share his birthday cake with you :)
Input
- First Line of input contains a single integer T denoting the number of test cases.
- First line of each test case contains two space separated integers N and K denoting the size of
permutation and number of numbers fall down from the table. - Next line of each test case contains K space separated integers denoting the values of missing numbers.
Output
For each test case, print "Chef" if chef should move first otherwise print "Mom" (without quotes).
Constraints
- 1 ≤ T ≤ 105, 1 ≤ N ≤ 109
- 0 ≤ K ≤ min(105, N)
- All K numbers are distinct.
- Value of each of K number belongs to [1,N].
- Sum of K over all the test cases does not exceed 5*105.
Scoring
- Subtask 1 (13 pts): 1 ≤ T ≤ 100, 1 ≤ N ≤ 102, 1 ≤ K < N.
- Subtask 2 (17 pts): 1 ≤ T ≤ 100, 1 ≤ N ≤ 105, K = 0.
- Subtask 3 (70 pts): Original Constraints.
Example
Input25 23 55 11OutputMomChef
Explanation
For test case 1.
- Mom can choose {1} to make 1.
- Chef can choose {2} to make 2.
- Mom can choose {1,2} to make 3.
- Chef can choose {4} to make 4.
- Mom can choose {1,4} to make 5.
- Chef can choose {2,4} to make 6.
- Mom can choose {1,2,4} to make 7.
- Chef cannot make 8 out of the numbers on the table.
So,Chef loses and Mom wins.
http://www.codechef.com/problems/CLPERM
#include<iostream>#include<algorithm>#include<string>#include<map>#include<vector>#include<cmath>#include<string.h>#include<stdlib.h>#include<cstdio>#include <ctime>#include <cstdlib> #define ll long long#define mod 998244353using namespace std; ll x[10000001];int main(){int t;cin>>t;while(t--){ll n,m,a;cin>>n>>m;for(int i=0;i<m;++i)cin>>x[i];sort(x,x+m);ll p=0,s=0,u=0;for(int i=0;i<m;++i){p+=x[i];s=x[i]*(x[i]+1)/2-p; //最大能到达的数=总和-所有前面不出现的数字if(x[i]>s){s=x[i]-1;u=1;break;}}if(u==0)s=n*(n+1)/2-p;if(s%2==0)cout<<"Chef"<<endl;else cout<<"Mom"<<endl;}return 0;}
- 【codechef】Chef and A Large Permutation(技巧题)
- 【codechef】 Chef and Piano Scales (简单题)
- codechef(MAY15)第三题Chef and Prime Divisors
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- 【codechef】Chef and Polygons(灵活题,坑题)
- CodeChef:Chef and Problems(分块 & 二分)
- CodeChef:Chef and Subsequences(思维 & dfs)
- CodeChef Chef and Segments
- codechef Chef and sequence
- codechef Chef and Swaps
- Codechef Chef and Reversing
- Codechef Chef and Frogs
- Codechef Chef and Churu
- 【CodeChef】 Chef and Stones
- 【CodeChef】Chef and Interview
- codechef Chef and Churu
- 【codechef】Chef and Prime Divisors(判断A能否被B的所有素因子整除)
- codechef Chef and easy problem
- 关于EasyUI对话框,表格和菜单组件在IE下的兼容性处理方法
- unity3d在线更新资源(2)
- 递归与递推的区别
- linux 命令之tee
- 配置NTP服务器以及解决RAC安装过程的报错PRVF-5439 : NTP daemon does not have slewing option "-x"
- 【codechef】Chef and A Large Permutation(技巧题)
- js 删除前confirm确认提示代码
- Java语言高级--NIO入门
- JVM对final的支持
- Hibernate性能优化
- httpclient
- Python多线程thread与threading实现
- Windows常见数据类型(变量,常量)命名规律
- loadView/viewDidLoad/initWithNibName/awakeFromNib/initWithCoder的用法