设为首页 收藏本站
查看: 1052|回复: 0

[经验分享] 【codechef】Chef and A Large Permutation(技巧题)

[复制链接]

尚未签到

发表于 2015-11-26 07:57:03 | 显示全部楼层 |阅读模式

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


Input
2
5 2
3 5
5 1
1
Output
Mom
Chef


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 998244353
using 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;
sort(x,x+m);
ll p=0,s=0,u=0;
for(int i=0;i<m;++i){
p+=x;
s=x*(x+1)/2-p; //最大能到达的数=总和-所有前面不出现的数字
if(x>s){
s=x-1;
u=1;
break;
}
}
if(u==0)
s=n*(n+1)/2-p;
if(s%2==0)
cout<<&quot;Chef&quot;<<endl;
else
cout<<&quot;Mom&quot;<<endl;
}
return 0;
}




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143596-1-1.html 上篇帖子: DevOps-chef的多节点环境搭建 下篇帖子: The 11th Zhejiang Provincial Collegiate Programming Contest---Talented Chef
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表