HDU ACM 5090 Game with pearls-> binary graph Max match or?

Source: Internet
Author: User

Test instructions: Jerry, Tom play games, give you out of n boxes, a[i] for the initial, the number of small balls in the first. Jerry can then add a 0 or K-fold ball to each box, and after that, Jerry will rearrange the boxes, and if I have a small ball in the box I, Jerry will win, output "Jerry" or Output "Tom".

Analysis: First count each number of balls have how many boxes, then from small to Oita past, the rest of the box to i+k position, so scan the array, if more than one and more than a number of balls can not find the corresponding box Tom wins, otherwise Jerry wins.

#include <iostream>using namespace Std;int main () {int m,n,k,x,i;int cnt[105];bool F;ios::sync_with_stdio (False) ; Cin>>m;while (m--) {Cin>>n>>k;memset (cnt,0,sizeof (CNT)); for (i=0;i<n;i++) cnt[cin>>x,x ]++;f=true;for (i=1;i<=n;i++) {if (!cnt[i]) {f=false;break;} Cnt[i+k]+=cnt[i]-1;} if (f) cout<< "Jerry" <<endl;elsecout<< "Tom" <<ENDL;}    return 0;}


HDU ACM 5090 Game with pearls-> binary graph Max match or?

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.