zoukankan      html  css  js  c++  java
  • hdu 5090 Game with Pearls

    题目链接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 a[200];
    
    int main()
    {
        int t,n,k;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %d",&n,&k);
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
            }
            sort(a+1,a+n+1);
            bool flag=0;
    
            for(int i=1;i<=n;i++)
            {
                if(a[i]==i)
                    continue;
                if(a[i]>i)
                {
                    flag=1;
                    break;
                }
                a[i]+=k;
                sort(a+1,a+n+1);
                i--;
            }
            if(flag)
                printf("Tom
    ");
            else
                printf("Jerry
    ");
        }
        return 0;
    }
    anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
  • 相关阅读:
    Best Time to Buy and Sell Stock II
    Subsets II
    Subsets I
    Combinations
    Permutation Sequence
    Next Permutation
    Anagrams
    Combination-Sum II
    Combination-Sum I
    Permutations II
  • 原文地址:https://www.cnblogs.com/gaoss/p/4966269.html
Copyright © 2011-2022 走看看