CHD in-school trials and problems

Source: Internet
Author: User

Topic link A. Currency System in Geraldion

At 1 o'clock, all numbers greater than or equal to 1 can be made up of 1. No 1 o'clock, the smallest unfortunate number is 1.

1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 voidsolve () {6     intn,x;7scanf"%d",&n);8     intFlag =0;9      for(inti =1; i<=n; i++){Tenscanf"%d",&x); One         if(x = =1) flag =1; A     } -     if(flag) printf ("-1\n"); -     Elseprintf"1\n"); the } - intMain () - { - solve (); +     return 0; -}

Topic Link: B. Gerald is into Art

God's teammate, eight if condition sec a,orz ...

The last two rectangles each long and wide turn over, there are four kinds of situations. There are eight cases in which the first rectangle matched to the given one.

1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 voidsolve () {6    inta1,b1,a2,b2,a3,b3;7Cin>>a1>>b1>>a2>>b2>>a3>>B3;8    intFlag =0;9    if(A2+A3&LT;=A1 && Max (B2,B3) <=b1) flag =1;Ten    if(A2+A3&LT;=B1 && Max (B2,B3) <=a1) flag =1; One    if(A2+B3&LT;=A1 && Max (B2,A3) <=b1) flag =1; A    if(A2+B3&LT;=B1 && Max (B2,A3) <=a1) flag =1; -    if(B2+A3&LT;=A1 && Max (A2,B3) <=b1) flag =1; -    if(B2+A3&LT;=B1 && Max (A2,B3) <=a1) flag =1; the    if(B2+B3&LT;=A1 && Max (A2,A3) <=b1) flag =1; -    if(B2+B3&LT;=B1 && Max (A2,A3) <=a1) flag =1; -    if(flag) printf ("yes\n"); -    Elseprintf"no\n"); + } - intMain () + { A solve (); at     return 0; -}

Topic Link: c.making a String

Test instructions: Given the number of AI that appears for each letter, make up a longest string of letters.

The conditions that this letter string satisfies:

1. The total number of occurrences of each letter does not exceed the AI.

2. The number of occurrences of each letter must be different.

Problem: This question is greedy directly. Starting with the maximum value, take the first set of samples, 2 5 5 For example

After sorting 2 5 5, we find the local optimal solution starting from the last 5.

1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 inta[ -];6 voidsolve () {7    intN;8scanf"%d",&n);9     for(inti =0; i<n; i++) scanf ("%d",&a[i]);TenSort (a,a+n); One    intMAXN = 1e9+7; A    Long Longsum =0; -     for(inti = n1; i>=0; i--){ -     if(MAXN = =0) Break; the     if(maxn>=A[i]) { -Sum + =A[i]; -MAXN = A[i]-1; -     } +     Else{ -Sum + =MAXN; +maxn--; A     } at    }  -printf"%i64d\n", sum); - } - intMain () - { - solve (); in     return 0; -}

Topic Links: D.bear and elections

Remember the winter vacation did this water problem, I found that I saw the problem I have done ...

The first person votes have been compared with the following largest, if the person is the largest less than the largest, he will have another vote, the biggest one on the back of a vote, ans+1, sort, until the back there is no bigger than it. The data is small and does not time out, and I have not grasped the dichotomy that Siro said.

1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 inta[ the];6 voidsolve () {7    intN,ans =0;8scanf"%d",&n);9     for(inti =0; i<n; i++) scanf ("%d",&a[i]);Ten     while(1){ OneSort (A +1, A +n); A     if(a[n-1]<a[0]) Break; -a[n-1]--; -a[0]++; theans++; -    } -printf"%d\n", ans); - } + intMain () - { + solve (); A     return 0; at}

CHD in-school trials and problems

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.