贪心 HDOJ 5090 Game with Pearls

题目传送门

 1 /*
 2     题意:给n, k,然后允许给某一个数加上k的正整数倍,当然可以不加,
 3         问你是否可以把这n个数变成1,2,3,...,n, 可以就输出Jerry, 否则输出Tom。
 4     贪心:保存可能变成的值的方案数,当一个符合,其他所有可能方案减1
 5     最大匹配 详细解释:http://blog.csdn.net/u012596172/article/details/40784773?utm_source=tuicool
 6 */
 7 #include <cstdio>
 8 #include <algorithm>
 9 #include <iostream>
10 #include <cstring>
11 #include <cmath>
12 #include <string>
13 #include <vector>
14 #include <queue>
15 #include <map>
16 #include <set>
17 #include <ctime>
18 #include <cstdlib>
19 using namespace std;
20
21 const int MAXN = 1e2 + 10;
22 const int INF = 0x3f3f3f3f;
23 int a[MAXN];
24 int cnt[MAXN];
25 int n, k;
26
27
28 int main(void)        //HDOJ 5090 Game with Pearls
29 {
30     //freopen ("A.in", "r", stdin);
31
32     int t;    scanf ("%d", &t);
33     while (t--)
34     {
35         memset (cnt, 0, sizeof (cnt));
36         scanf ("%d%d", &n, &k);
37         for (int i=1; i<=n; ++i)
38         {
39             scanf ("%d", &a[i]);
40             for (int j=a[i]; j<=n; j+=k)
41                 cnt[j]++;
42         }
43         bool win = true;
44         for (int i=1; i<=n; ++i)
45         {
46             if (!cnt[i])    {win = false;    break;}
47             for (int j=i; j<=n; j+=k)    cnt[j]--;
48         }
49
50         if (win)    puts ("Jerry");
51         else    puts ("Tom");
52     }
53
54     return 0;
55 }
56
57 /*
58 Jerry
59 Tom
60 */
时间: 2024-07-30 20:55:56

贪心 HDOJ 5090 Game with Pearls的相关文章

HDOJ 5090 Game with Pearls 二分图匹配

简单的二分图匹配: 每一个位置的数可能边成那些数连边即可 Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 122    Accepted Submission(s): 85 Problem Description Tom and Jerry are playing a game with tubes a

贪心 HDOJ 4726 Kia&#39;s Calculation

题目传送门 1 /* 2 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 3 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 4 5 注意:1. Both A and B will have same number of digits 两个数字位数相同 6 2. which is no larger than 10 6 不是大小,而是长度不超过1e6 7 */ 8 #include <cstdio> 9 #include <iostream&g

枚举+贪心 HDOJ 4932 Miaomiao&#39;s Geometry

题目传送门 1 /* 2 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 3 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则往右边放, 4 判断一下,取最大值.这题二分的内容少 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #include <cmath> 10 using n

[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到死... 仔细想想,首先,如果这个数是小的数的话,那么它可以匹配很多种,因此如果先将它匹配掉了会浪费,因为它“能力”大. 因此就可以排个序,从大到小进行匹配. 我也不知道怎么用数学语言去证明... 1 #

HDOJ 题目5090 Game with Pearls(二分图)

Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 919    Accepted Submission(s): 353 Problem Description Tom and Jerry are playing a game with tubes and pearls. The rule of the g

HDU 5090 Game with Pearls(二分匹配)

题目链接: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, the

线段树+树状数组+贪心 HDOJ 5338 ZZX and Permutations

题目传送门 1 /* 2 题意:不懂... 3 线段树+树状数组+贪心:贪心从第一位开始枚举,一个数可以是循环节的末尾或者在循环节中,循环节(循环节内部是后面的换到前面,最前面的换到最后面).线段树维护最大值,树状数组维护区间是否是循环节,查找前面最左边不是循环节的可用二分.我还是云里雾里的,看懂了网上的解题报告但还是不是完全明白题意:( 4 详细解释:http://blog.csdn.net/qq_24451605/article/details/47173933 5 */ 6 /******

hdu 5090 Game with Pearls 同余类

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 题目大意是有n个数 给一个k 每次你只能给其中一个数加上“k的非负整数倍的值”(包括0) 问最终能否让这堆数变成从1到n各有一个 简单排序完贪心是不对的 正确的思想是同余类 因为实质上每次只能加k,所以模k同余的可归为一类 然后分别对每一个同余类是否有可能合法 不合法的情形有两种 a.该同余类内的数不够多或太多 b.该同余类内的对应位置的数不够小 如果按这种想法走还需特判一下模k得0的情况 总

ACM--田忌赛马--贪心--HDOJ 1052--Tian Ji -- The Horse Racing

HDOJ题目地址:传送门 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25520    Accepted Submission(s): 7506 Problem Description Here is a famous story in Chinese history. "Th