14-15 the preliminary draft of ACM Rookie Cup, Southwest Jiaotong University J

Source: Internet
Author: User

problem A Dull Donggua
Written by: Hacker_vision
The main idea: n number of 1,2,3,4......,n; give you the number of occurrences of each count, to determine if there is a sequence of n number consisting of the adjacent element 22 is different.
intervening spaces in combinatorial mathematics, it can be proved that as long as the most frequently occurring element can be separated by all elements (the empty energy of the composition is fully inserted)

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <climits>#include <map>#include <vector>#include <list>#include <stack>#include <queue>#define EPS 1e-10#define CLR (k,v) memset (k,v,sizeof (k));using namespace STD;typedef Long LongllConst intSZ =1<< -;Const intmaxn=2e6+Ten;structfastio{CharINBUF[SZ];CharOutbuf[sz];fastio () {//input/output HookSetvbuf (STDIN,INBUF,_IOFBF,SZ); Setvbuf (Stdout,outbuf,_iofbf,sz);}} IointA[MAXN];intMain () {//freopen ("Input.txt", "R", stdin);   intTscanf("%d", &t); while(t--) {intNscanf("%d", &n); ll sum=0; for(intI=0; i<n;i++) {scanf("%d", a+i);    Sum+=a[i]; }intMaxx=*max_element (A,a+n);if(sum-maxx>=maxx-1)puts("Yes");Else puts("No");//Can fill all the empty}return 0;}

problem D How many possibilities
Written by: Hacker_vision
A sequence a1.a2....an is known to give you an integer c to find the number of pairs (I,J) that satisfy all ai+aj==k
The first thought is two points to find Binary_search (), each time the query time-consuming O (Nlogn), but because the number of queries will time out; no, mark, open tag array vis[j] record the number of occurrences of the integer j, traverse all elements a[i], accumulate vis[ C-a[i]], notice that the array is out of bounds.

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <climits>#include <map>#include <vector>#include <list>#include <stack>#include <queue>#define EPS 1e-10#define CLR (k,v) memset (k,v,sizeof (k));using namespace STD;typedef Long LongllConst intSZ =1<< -;Const intmaxn=2e3+Ten;structfastio{CharINBUF[SZ];CharOutbuf[sz];fastio () {//????????? 3?1??Setvbuf (STDIN,INBUF,_IOFBF,SZ); Setvbuf (Stdout,outbuf,_iofbf,sz);}} IointVIS[MAXN],A[MAXN*MAXN];intMain () {//freopen ("Input.txt", "R", stdin);    intTscanf("%d", &t); while(t--) {CLR (Vis,0);intNscanf("%d", &n);//cout<< "~!!! \ n ";       for(intI=0; i<n;++i) {scanf("%d", a+i);      vis[a[i]]++; } sort (a,a+n);intQ;scanf("%d", &q); while(q--) {intCscanf("%d", &c);if(c> -) {puts("0");Continue;}//If C is too large to exceed the VIS maximum subscript, the other address will be accessedll res=0; for(intI=0; i<n;i++) {if(A[I]&GT;C) Break;//array out of bounds, dangerous!          if(A[i]==c-a[i]) res+=vis[c-a[i]]-1;ElseRes+=vis[c-a[i]]; }printf("%lld\n", res); }    }return 0;}

problem H A + b≥k problem
Written by: Hacker_vision
The main topic: a sequence known as a1.a2....an, give you an integer k, find the number of pairs (I,J) to meet all ai+aj>=k
Troubleshooting: binary search for STL library function Binary_search,lower_bound,upper_bound
Bestcoder, conversion to a[j]>=k-a[i], in a[i]~a[n] binary search for the first element greater than or equal to K-a[i] a[j], to the end of the array all the elements are solved, add up can be.

Sort (a,a+n);
★bool Binary_search tried to find the element value in the sorted [first, last]. Returns true if it is found, or false if it does not return a lookup location.
★iterator lower_bound (const key_type &key): Returns an iterator that points to the first element of the key value >= key. (That is, the address returned)
★iterator upper_bound (const key_type &key): Returns an iterator that points to the first element of a key value > keys. (That is, the address returned)

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <climits>#include <map>#include <vector>#include <list>#include <stack>#include <queue>#define EPS 1e-10#define CLR (k,v) memset (k,v,sizeof (k));using namespace STD;typedef Long LongllConst intSZ =1<< -;Const intmaxn=2e5+Ten;structfastio{CharINBUF[SZ];CharOutbuf[sz];fastio () {//input/output HookSetvbuf (STDIN,INBUF,_IOFBF,SZ); Setvbuf (Stdout,outbuf,_iofbf,sz);}} IointN,K,A[MAXN];intMain () {//Freopen ("Input.txt", "R", stdin);   while(scanf("%d%d", &n,&k)!=eof) { for(intI=0; i<n;i++)scanf("%d", a+i);    Sort (a,a+n); ll ans=0; for(intI=0; i<n;i++) {ans+=n-(Lower_bound (a+i+1, A+n,k-a[i])-a);//cout<<ans<<endl;}printf("%lld\n", ans); }return 0;}

problem J Can JM bear being happy?
Written by: Hacker_vision
To give you a string of length n does not determine whether the string is legal (that must contain all 26 English letters)
Puzzle: mark array vis[26] Mark occurrences of letters, note pre-processing: string case conversion

string S;
Lowercase converted to uppercase: transform (S.begin (), S.end (), S.begin (),:: ToUpper);
Uppercase converted to lowercase: transform (S.begin (), S.end (), S.begin (),:: ToLower);

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <climits>#include <map>#include <vector>#include <list>#include <stack>#include <queue>#define EPS 1e-10#define CLR (k,v) memset (k,v,sizeof (k));using namespace STD;typedef intllConst intSZ =1<< -;Const intmaxn=2e3+Ten;structfastio{CharINBUF[SZ];CharOutbuf[sz];fastio () {//input/output HookSetvbuf (STDIN,INBUF,_IOFBF,SZ); Setvbuf (Stdout,outbuf,_iofbf,sz);}} IostringSBOOLvis[ -];intMain () {//Freopen ("Input.txt", "R", stdin);   intN while(scanf("%d", &n)!=eof) {Cin>>s; Transform (S.begin), S.end (), S.begin (),::ToLower);//cout<<s<<endl;CLR (Vis,false); for(intI=0; i<n;i++) vis[s[i]-' A ']=true;//puts (s);    BOOLok=true; for(intI=0;i< -; i++)if(vis[i]==false) {ok=false; Break;}if(OK)puts("YES");Else puts("NO"); }return 0;}

14-15 the preliminary draft of ACM Rookie Cup, Southwest Jiaotong University J

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.