[HDU 5090] Game with Pearls (贪心)】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 题目大意:给你n个数,问你给若干个数增加c*k(c>=0)能否组成1,2,3,4,5,...,n? 今天下午作比赛的时候,我先用了个dfs,看这个a[i]匹配的是1到n的哪个数. 后来TLE到死... 仔细想想,首先,如果这个数是小的数的话,那么它可以匹配很多种,因此如果先将它匹配掉了会浪费,因为它“能力”大. 因此就可以排个序,从大到小进行匹配. 我也不知道怎么用数学语言去证明... #in…
一道贪心的题,因为最小的不能由别的转化,所以每次贪心找最小的,其余的转化成大的. 从小到大,最小的如果不存在那么就break,否则减去一个,剩下的加k继续判断. #include<cstdio> #include<cstring> ; int cnt[maxn]; int main() { int T; scanf("%d",&T); int n,k; while(T--){ memset(cnt,,sizeof(cnt)); scanf("%…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 Problem Description Tom and Jerry are playing a game with tubes and pearls. The rule of the game is: 1) Tom and Jerry come up together with a number K.  2) Tom provides N tubes. Within each tube, th…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 题意:n个数,k,给n个数加上k的正倍数或者不加,问最后能不能凑成1 到 n的序列 题目分类:暴力 题目分析:因为每个数只能变大或者不变,并不能变小,所以要从小数开始往大凑.先排序,然后凑到1了之后然后再去凑2,这样一直往大凑 题目代码: #include<bits/stdc++.h> using namespace std; ]; int main() { int t,n,k; scanf…
Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1914    Accepted Submission(s): 671 Problem Description Tom and Jerry are playing a game with tubes and pearls. The rule of the…
题意: 给你N个数,a1,,,,an.代表第i个管子里有ai个珍珠. 规定只能往每根管里增加k的倍数个珍珠. 如果存在一套操作,操作完毕后可以得到1~N的一个排列,则Jerry赢,否则Tom赢. 问谁赢. 思路: 将a1...an从小到大排序,可知道每根管里的数只能增不能减.将最后的1...N中的每个数一定是由小于等于它的数加上若干个K得到来的. 额..直接看代码吧 代码: int a[1005]; int m,n,k; int main(){ //freopen("test.in",…
题目传送门 /* 题意:给n, k,然后允许给某一个数加上k的正整数倍,当然可以不加, 问你是否可以把这n个数变成1,2,3,...,n, 可以就输出Jerry, 否则输出Tom. 贪心:保存可能变成的值的方案数,当一个符合,其他所有可能方案减1 最大匹配 详细解释:http://blog.csdn.net/u012596172/article/details/40784773?utm_source=tuicool */ #include <cstdio> #include <algor…
hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define CLR(a,b) memset((a),(b),sizeof(…
http://acm.hdu.edu.cn/showproblem.php?pid=5090 给一段长度为n数列,问能否给任意个数加上k的倍数,使得加完之后恰好只有1~n 贪心,先排序,依次加出1~n,每次看能否从给定数列中找到一个未被标记的数使得其能加到当前的i,能则标记,最后能完成即输出Jerry #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #inclu…
Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer requires knowledge in many fields, because problems in this contest may use physics, biology, and even musicology as background. And now in this prob…