ACM-ICPC Shanghai 2014

Source: Internet
Author: User

A.

Test instructions: Given a sequence, you can add any number of them to the integer multiples of K, after which the sequence needs to be changed from small to large rows 1,2,3,4,5,6

Answer: The most intuitive method is a match, but think 500*100*100*100 may be super-

But you can see that A can change to B when a%k = = B%k && A <= K

Then we'll have a priority queue for every possible remainder, sweep it all over again.

You're going to be a fool for yourself, Qaq.

Break out Qaq When you're done emptying.

#include <cstdio>#include<iostream>#include<cstring>#include<Set>#include<queue>using namespacestd;Const intN = the; typedefstructnode{intxi,v; BOOL operator< (ConstNode &a)Const{            if(xi = = A.XI)returnV <A.V; Else returnXi >A.xi; }}node;node NewNode (intXinty)    {node tmp; Tmp.xi=x; TMP.V=y; returntmp;}intn,m,k;intA[n],b[n],tmpa[n],tmpb[n]; priority_queue<node>Q[n];intMain () {intT CIN >>T;  while(t--) {cin>> N >>K;  for(inti =1; I <= n;i++) scanf ("%d",&A[i]);  for(inti =1; I <= n;i++) b[i] =i;  for(inti =1; I <= n;i++) Q[a[i]%k].push (NewNode (a[i),1));  for(inti =1; I <= n;i++) Q[b[i]%k].push (NewNode (b[i],-1)); intFlag =0;intCNT =0;  for(intt =0; t < k;t++,cnt =0){           while(!(Q[t].empty ())) {Node U=Q[t].top ();                  Q[t].pop (); CNT+=U.V; if(CNT <0) flag =1; }                if(CNT! =0) flag =1; }                if(flag) printf ("tom\n"); Elseprintf"jerry\n"); }    }

ACM-ICPC Shanghai 2014

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.