HDU 5090 Game with Pearls

Source: Internet
Author: User

Direct greedy on it, receive when the 0 plus K, each time from the smallest number to find, if there are more than the same, then keep one, the others are plus K

#include <stdio.h> #include <algorithm>using namespace Std;int a[105];int main () {#ifndef online_ Judgefreopen ("In.txt", "R", stdin), #endifint t,n,k;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&k); for ( int i=0;i<n;i++) {scanf ("%d", &a[i]), if (a[i]==0) a[i]+=k;} Sort (a,a+n); int flag=1;for (int i=0;i<n;i++) {if (a[i]==i+1) {int j=1;while (A[i+j]==a[i]) {a[i+j]+=k;j++;} Sort (a+i,a+n);} else{flag=0;printf ("tom\n"); break;}} if (flag==1) printf ("jerry\n");}}


HDU 5090 Game with Pearls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.