Codeforces Round #316 (Div. 2) (ABC question)

Source: Internet
Author: User
Tags cmath

A-elections Test Instructions:

The result of each city election, the first keyword is the number of votes (descending), the second keyword is ordinal (ascending), the first to win;
The final election results, the first keyword is the number of winning cities (descending), the second keyword is ordinal (ascending), the first to win;
The winner of the final election.

Ideas:

Direct simulation can be done.

Code:
/** @author freewifi_novicer* language:c++/c*/#include <cstdio>#include <iostream>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <string>#include <map>#include <set>#include <vector>#include <queue>using namespace STD;#define CLR (x, y) memset (x,y,sizeof (x) )#define CLS (x) memset (x,0,sizeof (x) )#define MP Make_pair#define PB Push_backtypedef Long LongLinttypedef Long Longlltypedef Long LongLL;Const intMAXN = the;structc{intVintNo;} C[MAXN][MAXN];intCNT[MAXN];BOOLCMP (c A, C b) {if(A.V! = B.V)returnA.V < B.V;returna.no > b.no;}intMain () {//freopen ("Input.txt", "R", stdin);    intN,m; while(Cin>> n >> m) {CLS (CNT); for(inti =1; I <= m; i++) { for(intj =1; J <= N; J + +) {c[i][j].no = J;scanf("%d", &AMP;C[I][J].V); } sort (c[i]+1, c[i]+n+1, CMP); for(intj =1; J <= N;        J + +) {} cnt[c[i][n].no]++; }intans = n;intTMP = Cnt[n]; for(inti = n; I >=1; i--) {if(tmp <= Cnt[i])                {ans = i;            TMP = Cnt[i]; }        }cout<< ans << Endl; }return 0;}
B-simple Game Test Instructions:

Misha and Andrew play games, the two people in the range of 1~n Select a number (can be the same), and then in the 1~n range randomly out a number X,misha and Andrew's number minus the absolute value of x less wins, if consistent, then Misha wins, now known as N and Misha selected Number, the number of Andrew winning the highest (the same percentage to take the smallest).

Ideas:

Classification discussion, only need to consider the position of Misha around,
Note that n = 1 o'clock is a special case.

Code:
/** @author freewifi_novicer* language:c++/c*/#include <cstdio>#include <iostream>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <string>#include <map>#include <set>#include <vector>#include <queue>using namespace STD;#define CLR (x, y) memset (x,y,sizeof (x) )#define CLS (x) memset (x,0,sizeof (x) )#define MP Make_pair#define PB Push_backtypedef Long LongLinttypedef Long Longlltypedef Long LongLL;intMain () {//Freopen ("Input.txt", "R", stdin);    intM,n; while(Cin>> n >> m) {if(M = =1){if(n = =1)cout<<1<< Endl;Else{cout<< m+1<< Endl; }Continue; }if(M = = N) {if(n = =1)cout<<1<< Endl;Else{cout<< m1<< Endl; }Continue; }intAnsif(n&1){intTMP = (n+1) /2;if(M < TMP) {ans = m+1; }Else if(M > tmp) ans = m1;Else if(m = = tmp) ans = m1; }Else{intTMP = n/2;if(M < TMP) {ans = m+1; }Else if(M > tmp) ans = m1;Else if(m = = tmp) ans = m+1; }cout<< ans << Endl; }return 0;}
C-replacement Test Instructions:

Enter a string with a '. ' and a lowercase English letter.
Define an action to replace ".." In a string with ".";
Defines the value of a string equal to the maximum number of operations.
Now there are M queries, each of which will change the character at the specified position of the string to the specified character, and calculate the value of the string after the query.

Ideas:

This is the style of the line tree (the line tree is also really possible.)
The key to this problem is to simplify the classification of different situations, my previous idea has been to record each '. ' interval, and then ask when the two points in which interval can be, the results found that the confusion of writing ideas is not logical, but also set is a map.
Until you see the code of the second God Ox in the standing list. Anger delete the original code rewrite a copy, a lot easier.

Code:
/** @author freewifi_novicer* language:c++/c*/#include <cstdio>#include <iostream>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <string>#include <map>#include <set>#include <vector>#include <queue>using namespace STD;#define CLR (x, y) memset (x,y,sizeof (x) )#define CLS (x) memset (x,0,sizeof (x) )#define MP Make_pair#define PB Push_backtypedef Long LongLinttypedef Long Longlltypedef Long LongLL;intMain () {//freopen ("Input.txt", "R", stdin);    intN, M;stringSCin>> N >> m >> s;intCNT =0; for(inti =1; I < s.length (); i++) {if(S[i] = ='. '&& s[i-1] =='. ') CNT + +; } for(inti =1; I <= m; i++) {intP;CharCscanf("%d%c", &p, &c); p--;if(P >0&& S[p] = ='. '&& S[p-1] =='. ') cnt--;if(P < s.length () && s[p] = ='. '&& S[p +1] =='. ') cnt--; S[P] = c;if(P < s.length () && s[p] = ='. '&& S[p +1] =='. ') cnt++;if(P >0&& S[p] = ='. '&& S[p-1] =='. ') cnt++;cout<< CNT << Endl; }return 0;}

Copyright notice: Bo Master said authorized all reproduced:)

Codeforces Round #316 (Div. 2) (ABC question)

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.