AGC 016B. Colorful Hats (IDEA)

Source: Internet
Author: User

Topic links

For a discussion of an element's classification, it is possible to know the total number of colors of n elements.
For example, the a[1] category discussion:

If the color of 1 is the same as an element, the total number of colors is a[1]. A[i] is either equal to a[1] (i is the same color as an element, with a count of a), or equal to a[1]+1 (i is the only color, the number is B).
To satisfy: B is not equal to n-1 (must have an I and 1 colors the same); maximum number of colors = (a+1)/2+b is greater than or equal to a[1], and there is an upper bound limit! That is, the minimum number of colors =1+b to be less than or equal to a[1].

If the color of 1 is unique, the total number of colors is a[1]+1. A[i] is either equal to a[1] (the color of I is unique, count to a), or equal to a[1]+1 (the same color as an element, the number of counts is B).
To satisfy: B cannot be 1 (can be greater than 1 can also be 0); The maximum number of colors =1+A+B/2 is greater than or equal to a[1]+1, and there is an upper bound limit! That is, the minimum number of colors =1+a+ (b!=0) is less than or equal to a[1]+1.

Of course This classification discusses how many of the minimum values are actually written by others (only one check is performed). I'm not saying that I wrote a problem. In fact, it is similar.

2ms 896kb#include <cstdio> #include <cctype> #include <algorithm>//#define GC () GetChar () #define Maxin 300000#define GC () (ss==tt&& (tt= (ss=in) +fread (In,1,maxin,stdin), SS==TT)? eof:*ss++) typedef long LONG ll;const int n=1e6+5;int a[n];char in[maxin],*ss=in,*tt=in;inline int read () {int Now=0;reg    Ister Char C=GC (); for (;!    IsDigit (c); C=GC ());    for (; IsDigit (c); now=now*10+c-' 0 ', C=GC ()); return now;}    BOOL Check1 (const int n) {int a=0,b=0;        for (int i=2,a1=a[1]; i<=n; ++i) if (A[I]==A1) ++a;        else if (a[i]==a1-1) ++b;    else return 0; Return b<n-1&& (a+1>>1) +b>=a[1]&&b<a[1];//upper bound limit ah ah}bool Check2 (const int n) {int a=0,b=    0;        for (int i=2,a1=a[1]; i<=n; ++i) if (A[I]==A1) ++a;        else if (a[i]==a1+1) ++b;    else return 0; Return b!=1&&a+ (b>>1) >=a[1]&&a+ (b!=0) <=a[1];}    int main () {int n=read ();    for (int i=1; i<=n; ++i) A[i]=read (); Puts (Check1 (n)|| Check2 (n)? "    Yes ":" No "); return 0;}

AGC 016B. Colorful Hats (IDEA)

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.