Codeforces Round #318 (Div. 2) (A,B,C,D)

Source: Internet
Author: User
Tags acos bitset

Question A:
Title Address: Bear and elections
Test instructions: The minimum number of transformations can make the first digit larger than all subsequent digits.
Idea: The number of the following n-1, let the first and last number comparison, and then increase or decrease. Knowing that the first number is greater than the last number

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#include <bitset>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-6;using namespace STD;inta[ the];intMain () {intNintCnt while(~scanf("%d", &n)) { for(intI=0; i<n;i++)scanf("%d", &a[i]); Cnt=0; while(1) {sort (A +1, a+n);if(a[0]<=a[n-1]) {a[0]++; a[n-1]--;            cnt++; }Else                 Break; }printf("%d\n", CNT); }return 0;}

Question B:
Title Address: Bear and Three Musketeers
Test instructions: give you a figure and then determine if you can make a triangle, if you can, output the smallest number of points triangle, if not output-1

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#include <bitset>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-6;using namespace STD;Const intmaxn=4010;intVIS[MAXN][MAXN];intDEG[MAXN];intMain () {intN,m;intx, y; while(~scanf("%d%d", &n,&m)) {memset(Vis,0,sizeof(VIS));memset(DEG,0,sizeof(deg)); while(m--) {scanf("%d%d", &x,&y);            deg[x]++;            deg[y]++; vis[x][y]=vis[y][x]=1; }intMin=inf; for(intI=1; i<=n;i++) { for(intj=i+1; j<=n;j++) {if(Vis[i][j]) { for(intk=j+1; k<=n;k++) {if(Vis[k][j]&&vis[k][i]) {Min=min (min,deg[i]+deg[j]+deg[k]-6); }                    }                }            }        }if(Min==inf)puts("-1");Else            printf("%d\n", Min); }return 0;}

Question C:
Title Address: Bear and Poker
Test instructions: An array of length n, each of which can become 2 or 3 times times its own, asking if you can change the n number to a number.
Idea: Divide each number by 2 and 3 until there is no quality factor of 2 and 3, and then add to set, if only one number is left in the set then you can, otherwise you cannot.

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#include <bitset>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-6;using namespace STD;Const intmaxn=1e5+Ten; Set<int >QintMain () {intN,x; while(~scanf("%d", &n)) { while(n--) {scanf("%d", &x); while(%2==0) x/=2; while(%3==0) x/=3;        Q.insert (x); }if(q.size () = =1)puts("Yes");Else            puts("No"); }return 0;}

Question d:
Title Address: Bear and Blocks
Test instructions: Give a sequence of rows, each time the outer block is removed, ask the total minimum number of steps.
Idea: To find the minimum number of steps for each one from the back, to find the minimum number of steps from the rear to the next, and then to find the minimum number of steps for each, then the two compare to find the current minimum. And then find all the biggest inside (because to meet all the circumstances)

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#include <bitset>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-6;using namespace STD;Const intmaxn=1e5+Ten;intH[MAXN];intDP1[MAXN],DP2[MAXN];intRES[MAXN];intMain () {intN while(~scanf("%d", &n)) { for(intI=0; i<n;i++)scanf("%d", &h[i]); dp1[0]=1; for(intI=1; i<n;i++) Dp1[i]=min (dp1[i-1]+1, H[i]); dp2[n-1]=1; for(inti=n-2; i>=0; i--) Dp2[i]=min (dp2[i+1]+1, H[i]); for(intI=0; i<n;i++) {res[i]=min (dp1[i],dp2[i]); } sort (res,res+n);printf("%d\n", res[n-1]); }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces Round #318 (Div. 2) (A,B,C,D)

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.