SRM 653 Countrygrouphard

Source: Internet
Author: User

SRM 653 Countrygrouphard

Test instructions

n the individual sits in a row, sitting with the people of the same country, the reporter asks some people how many people they have in their country, and they all answer the right message. There is an AI person in the country where each message is known as the Pi position, and it is known whether the information can infer the situation of the country in which all people belong.

Analysis:

F[i] Indicates the number of scenarios to the first position. Then enumerate how many people in the back belong to a country. When the f[i]>2, set to 2 on the line. Initializes the f[n]=1.

Code:

1 /*2 * @Author: MJT3 * @Date: 2018-10-17 20:55:424 * @Last Modified BY:MJT5 * @Last Modified time:2018-10-17 21:37:106 */7#include <cstdio>8#include <algorithm>9#include <cstring>Ten#include <cmath> One#include <iostream> A#include <cctype> -#include <Set> -#include <vector> the#include <queue> -#include <map> - #defineFi (s) freopen (S, "R", stdin); - #defineFo (s) freopen (S, "w", stdout); + using namespacestd; -typedefLong LongLL; +  AInlineintRead () { at     intx=0, f=1;CharCh=getchar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; -      for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0';returnx*F; - } -  - classcountrygrouphard{ -  Public: in     intf[ the]; -     stringSolve (Vector <int>a) { to         intn =a.size (); +F[n] =1; -          for(inti = n-1; I >=0; --i) { the             if(A[i] = =0) { *                 intOK =-1; $                  for(intj =1; (i + j) <= N; ++j) {Panax Notoginseng                     if(A[i + J-1] !=0) {//the last few places . -                         if(OK! =-1&& OK! = a[i + J-1]) Break; the                         ElseOK = a[i + J-1]; +                     } A                     if(OK = =-1|| OK = = j) F[i] + + f[i +j]; the                 } +             } -             Else { $                 BOOLOK = (i + a[i] > N);//requires a[i] equal to the back $                  for(intj = i; J < N && J < i + a[i]; ++j) -                     if(A[j] && a[j]! = a[i]) OK =true; -                 if(!ok) F[i] = F[i +A[i]]; the             } -             if(F[i] >=2) F[i] =2;Wuyi         } the         returnf[0] >1?"Insufficient":"sufficient"; -     } Wu  -};

SRM 653 Countrygrouphard

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.