Codeforces Round #281 (Div. 2 ),

Source: Internet
Author: User

Codeforces Round #281 (Div. 2 ),

A. Simulation questions

Link: http://codeforces.com/contest/493/problem/A

The name of the home team and the away team are given, and n pieces of information are given. each piece of information includes four values, the time, the team, and the number of the team, if you get a yellow card or a red card, if you get two yellow cards, you will automatically get a red card. We are concerned about the first time the players of the two teams get a red card, if a player is marked with a red card for the first time, the name of the player's team is displayed.

A yellow card is represented by 1, a red card is represented by 2, and two maps <int, int> are used to store the foul information of each player of two teams, if it is 2, it indicates that you have obtained a red card.

Code:

#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <stdlib.h>#include <cmath>#include <iomanip>#include <vector>#include <set>#include <map>#include <stack>#include <queue>#include <cctype>using namespace std;#define ll long longstring home,away;map<int,int>h;map<int,int>a;int main(){    cin>>home>>away;    int n;    cin>>n;    int time,no;    char tap,color;    while(n--)    {        cin>>time>>tap>>no>>color;        if(tap=='a')        {            if(a[no]==2)                continue;            else            {                if(color=='r')                {                    a[no]=2;                    cout<<away<<" "<<no<<" "<<time<<endl;                }                else                {                    a[no]++;                    if(a[no]==2)                        cout<<away<<" "<<no<<" "<<time<<endl;                }            }        }        else        {            if(h[no]==2)                continue;            else            {                if(color=='r')                {                    h[no]=2;                    cout<

 

B. Simulation questions

Link: http://codeforces.com/contest/493/problem/ B

N scores are given in sequence, or greater than 0, or less than or equal to 0. If greater than 0 represents a's score. If less than 0, its absolute value represents B's score, in the end, whoever has a high total score wins. If the total score is the same, the person with a high Lexicographic Order in the Score Sequence wins, for example, if a's fractional sequence is 15 20 22 and B's fractional sequence is 15 24 22, B's Lexicographic Order is high because 15 = 15, 20 <24. If the Lexicographic Order is the same, if the score sequence is the same, then the score of the last input in the input process will be won.

Score, if, else

Code:

# Include <iostream> # include <stdio. h> # include <algorithm> # include <string. h> # include <stdlib. h> # include <cmath> # include <iomanip> # include <vector> # include <set> # include <map> # include <stack> # include <queue> # include <cctype> using namespace std; # define ll long longconst int maxn = 200010; ll a [maxn]; ll B [maxn]; ll suma = 0; ll sumb = 0; int n; ll score; int last; int main () {cin> n; int lena = 0; int lenb = 0; for (int I = 1; I <= n; I ++) {cin> score; if (score> 0) {a [++ lena] = score; suma + = score;} else {B [++ lenb] =-score; sumb + = (-score);} if (I = n) // records who scored the last time {if (score> 0) last = 1; else last = 2 ;}}if (suma> sumb) // cout <"first" <endl; else if (sumb> suma) Where one party is higher than the other party) cout <"second" <endl; else // same score {int flag = 0; int len = min (lena, lenb); for (int I = 1; I <= len; I ++) {if (a [I]> B [I]) // determines who has a large Lexicographic Order {flag = 1; break ;} if (B [I]> a [I]) {flag = 2; break ;}}if (flag = 1) {cout <"first" <endl ;} else if (flag = 2) {cout <"second" <endl;} else // The Lexicographic Order is equal, whoever scored the last time wins {if (last = 1) cout <"first" <endl; else cout <"second" <endl ;}} return 0 ;}

 

C.

Link: http://codeforces.com/contest/493/problem/C

Question:

A and B are a short distance from the basket. a has shot n times, each time the distance is a [I], and B has shot m times. Each time the distance is B [I], given a boundary d, if the distance between the shot basket and d is less than or equal to 2 points, 3 points greater than d, find the optimal d, this maximizes the difference between a's score and B's score. If the difference is maximized, the group with the highest score is output. Finally, the scores of a and B are output.

The threshold is 0 at the beginning, that is, each person has a score of 3, and then sorts a [I] and B [I] in ascending order, then, from small to large, B [I] is used as d to calculate the total score of a in the intermediate process. The total score of B is used to update the score of a and B in the final answer.

Code:

# Include <iostream> # include <stdio. h >#include <algorithm> using namespace std; # define ll long longconst int maxn = 200002; int a [maxn]; int B [maxn]; int na, nb; ll scorea; ll scoreb; int main () {cin> na; for (int I = 0; I <na; I ++) scanf ("% d ", & a [I]); cin> nb; for (int I = 0; I <nb; I ++) scanf ("% d ", & B [I]); sort (a, a + na); sort (B, B + nb); scorea = na * 3; scoreb = nb * 3; ll ta = scorea, tb = scoreb; int before = 0; int cur; for (int I = 0; I <nb; I ++) {tb-= 1; // take B [I] as the boundary. cur = upper_bound (a, a + na, B [I])-; // find the first location greater than B [I] ta-= (cur-before); before = cur; if (scorea-scoreb <ta-tb | (scorea-scoreb = ta-tb & ta> scorea) {scorea = ta; scoreb = tb ;}} cout <scorea <":" <scoreb; return 0 ;}


D.

Link: http://codeforces.com/contest/493/problem/D

There is a board with n * n. The white side is at () in the upper left corner and the black side is at (1, n) in the upper right corner. The two can go up, down, and diagonal lines, if either party wins the other party, both parties adopt the optimal strategy. If the other party wins the game, black is output. If the other party wins the game, white is output first, and then the coordinates of the first step are output.

If n is an odd number, then whatever the way the white side goes, the black side is symmetric with it, and the black side is sure to win. If n is an even number, the white side only needs to go to the coordinates, if n is an odd number, the white side will win.

Code:

#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;#define ll long longint main(){    int n;    cin>>n;    if(n&1)        cout<<"black";    else    {        cout<<"white"<<endl;        cout<<"1 2";    }    return 0;}


 

 



 

 

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.