Codeforces Round #351 (VK Cup Round 3, Div. 2 Edition)

Source: Internet
Author: User

A. Bear and Game

Test instructions: A sports program, it may be interesting in a minute, other time is very boring, if it lasts 15 minutes is very boring, then bear will turn off the TV, ask when will turn off the TV.

Puzzle: Use the first interesting time minus the i-1 interesting time, if the difference is greater than 15 minutes then output the first I interesting time +15. Note that the first interesting time is 0, and the last one is 90.

Code:

1 /*A*/2#include <cstdio>3 using namespacestd;4 5 Const intmaxn= the;6 7 intMain ()8 {9     intN;Ten      while(SCANF ("%d", &n)! =EOF) One     { A         intA[MAXN]; -a[0]=0; -          for(intI=1; i<=n;i++) thescanf"%d",&a[i]); -a[n+1]= -; -         intans= -; -          for(intI=1; i<=n+1; i++) +         { -             if((a[i]-a[i-1]) > the) +             { Aans=a[i-1]+ the; at                  Break; -             } -         } -         if(ans> -) ans= -; -printf"%d\n", ans); -     } in     return 0; -}
View Code

B. Problems for Round

Test instructions: There are a number of topics to be divided into Div1 and div2 two parts. These conditions are also met:

1. The number of topics in each section cannot be 0.

2. Each topic only belongs to one part.

3. Each div1 topic is more difficult than the div2.

4. If the two topics are similar, then they will belong to two parts respectively.

gives the topic number n, a similar question logarithm. The difficulty factor for n topics is 1~n.

The problem: According to the similar topic, we can judge the two simple in the div2, difficult in Div1 at the same time can also know that more simple than the simple topic of all the topics will be in div2, difficult to the same. For example: There are 5 topics, then the difficulty factor is 1,2,3,4,5 now gives 4, 2, is similar, then 2 certainly in the div2,4 certainly in Div1, because each div1 topic is more than DIV2 the topic is simple, so 1 certainly also in Div2, 5 certainly in Div1. That means we just have to find the most difficult topic in Div2 Max and div1 The simplest topic min, and then you can be sure than Max Simple is in the div2, more difficult than Min is div1. If the max>=min, indicating there is a crossover, is certainly not possible, then output 0. If max<min we can find out the d=min-max-1, that is, the middle has not been determined in which part of the topic, using the partition method can know that there are d+1 ways. But because each part has the question, so when d==n the answer to be 2.

Code:

1 /*B*/2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intmaxn=100000+ -;7 8 intMain ()9 {Ten     intn,m; One      while(SCANF ("%d%d", &n,&m)! =EOF) A     { -         intb; -         intmax=0; the         intmin=n+1; -         intflag=1; -          for(intI=0; i<m;i++) -         { +scanf"%d%d",&a,&b); -             if(a>b) +             { Aa=a+b; atb=a-b; -a=a-b; -             } -             if(a>max) -max=A; -             if(b<min) inmin=b; -             if(min<=max) toflag=0; +         } -         if(flag==0) theprintf"0\n"); *         Else $         {Panax Notoginseng             intd=min-max-1; -             intAns=d+1; the             if(d==N) +ans-=2; Aprintf"%d\n", ans); the         }     +     } -     return 0; $}
View Code

C. Bear and Colors

Test instructions: There is a different color of the ball, each color is a number. Now define the main color in a paragraph (subsequence), which is the color with the highest number of colors in a paragraph, and if the number is the same, the one with the smallest number. Now ask how many segments each color is the primary color.

Key: Use two for loop to calculate the main color from I to J in this segment. Use an array to record the number of each color, while updating the MAXT (quantity), and Maxp (color), to derive a period of the main color, and finally update to the ANS array.

Code:

1 /*C*/2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intmaxn= the+Ten;7 8 intMain ()9 {Ten     intN; One      while(SCANF ("%d", &n)! =EOF) A     { -         intT[MAXN]; -          for(intI=0; i<n;i++) thescanf"%d",&t[i]); -         intANS[MAXN]; -         intA[MAXN]; -memset (ans,0,sizeof(ans)); +         intmaxt=0, Maxp; -          for(intI=0; i<n;i++) +         { AMemset (A,0,sizeof(a)); atmaxt=0; maxp=0; -              for(intj=i;j<n;j++) -             { -a[t[j]]++; -                 if(a[t[j]]>maxt) -                 { inmaxt=A[t[j]]; -maxp=T[j]; to                 } +                 Else if(a[t[j]]==maxt) -                 { the                     if(t[j]<Maxp) *maxp=T[j]; $                 }Panax Notoginsengans[maxp]++; -             }  the         } +printf"%d", ans[1]); A          for(intI=2; i<=n;i++) theprintf"%d", Ans[i]); +printf"\ n"); -     } $     return 0; $}
View Code

Codeforces Round #351 (VK Cup Round 3, Div. 2 Edition)

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.