Codeforces Round #316 (Div. 2) A B C

Source: Internet
Author: User

A. electionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

The country of Byalechinsk is running elections involving N candidates. The country consists of m cities. We know how many people in each city voted for each candidate.

The electoral system in the country is pretty unusual. At the first stage of elections the votes was counted for each city:it was assumed that in each city won the candidate Got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner Is the one with a smaller index.

At the second stage of elections the winner was determined by the same principle over the cities:the winner of the Electio NS is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the Winn Er is the one with a smaller index.

Determine who'll win the elections.

Input

The first line of the input contains the integers n,m (1?≤? N,? M.≤?100)-the number of candidates and of cities, respectively.

Each of the next m lines contains n non-negative integers, the J -th number in The I -th line a IJ (1?≤? J ? ≤? n , 1?≤? I ? ≤? m , 0?≤? A ij ? ≤?10< Span style= "font-size:12px" >9 ) denotes the number of votes for candidate J in city i .

It is guaranteed, the total number of people in all the cities does not exceed9.

Output

Print a single number-the index of the candidate who won the elections. The candidates is indexed starting from one.

Sample Test (s) Input
3 31 2 32 3 11 2 1
Output
2
Input
3 410 10 35 1 62 2 21 5 7
Output
1

Note

Note to the first sample test. At the first stage City 1 chosen candidate 3, City 2 chosen candidate 2, City 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.

Note to the second sample test. At the first stage in City 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 have a smaller index, So the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone had the same number of votes, and 1 has the the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1 and the one with the smaller index.



Test instructions is a pit, the main idea is every city to vote for each candidate, row is the city, the list is a candidate. Each vote is only the largest, and the number is small, for the same number of candidates votes, the same, the selected number is small.
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <    Queue>using namespace Std;typedef Long long ll;int main () {int n,m;    ll a[105][105];    int b[105];        while (cin>>m>>n) {memset (a,0,sizeof (a));        Memset (b,0,sizeof (b));        int i,j;            For (I=1, i<=n; i++) for (j=1; j<=m; J + +) {cin>>a[i][j];        } int k;        int max1;            for (I=1; i<=n; i++) {max1=-1;                    for (j=1; j<=m; J + +) {if (A[I][J]&GT;MAX1) {max1=a[i][j];                K=j;        }} b[k]++;        } max1=-1;                    for (I=1; i<=100; i++) if (b[i]>max1) {k=i;                Max1=b[i];    } cout<<k<<endl; } return 0;}





B. Simple Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

One day Misha and Andrew were playing a very simple game. First, each player chooses a integer in the range from1 to n. Let's assume that Misha chose numberm, and Andrew chose number a.

Then, by using a random generator they choose a random integer C in the range between 1 and n ( Any integers from 1 to N are chosen with the same probability), after which the winner is the player, whos E number is closer toC. The boys agreed that if m and a is located on the same distance fromC, Misha wins.

Andrew wants to win very much, so he asks your to help him. You know the number selected by Misha, and numbern. You need to determine which value of a Andrew must choose, so that the probability of he victory is the highes T possible.

More formally, need to find such integer a (1?≤? A? ≤? n), that the probability-is-maximal, whereC is the equiprobably chosen integer from 1 To N (inclusive).

Input

The first line contains integers n andm (1?≤? M≤? n? ≤?109)-the range of numbers in the game, and the number selected by Misha respectively.

Output

Print a single Number-such value a, that probability, which Andrew wins is the highest. If There is multiple such values, print the minimum of them.

Sample Test (s) Input
3 1
Output
2
Input
4 3
Output
2
Note

In the first sample Test:andrew wins if C are equal to2 or 3. The probability that Andrew wins is2?/?3. If Andrew chooses a? =?3, the probability of winning would be1?/?3. If a? =?1, the probability of winning is0.

The second sample Test:andrew wins if C is equal to1 and 2. The probability that Andrew wins is1?/?2. For other choices of the probability of winning are less.





YY out of the code--
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Queue>using namespace Std;typedef Long long ll;int main () {    int  n,m;    while (cin>>n>>m)    {        if (n==1 &&m==1)         {             cout<<1<<endl;             Continue;         }        if (n>=m)        {            if (n/2>=m)            m+=1;            else            m-=1;            cout<<m<<endl;        }        else        {        if (m/2>=n)          n+=1;          else          n-=1;          cout<<n<<endl;        }    }    return 0;}




C. Replacementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Daniel has a string s , consisting of lowercase 中文版 letters and period signs (characters ' '). Let ' s define the operation Ofreplacement as the following sequence of Steps:find a Substring "" (consecutive periods) in String s , of all occurrences of the substring let's Cho OSE the first one, and replace this substring with string ". ". In other words, during the replacement operation, the first and consecutive periods is replaced by one. If string s contains no, consecutive periods, then nothing happens.

Let's define F(s) as the minimum number of operations ofreplacement to perform, so tha t the string does not has any of the consecutive periods left.

You need to process m queries, the i-th results in that the character at position xi (1?≤? Xi? ≤? n) of strings is assigned value cI. After each operation you has to calculate and output the value ofF(s).

Help Daniel to process all queries.

Input

The first line contains integers n andm (1?≤? N,? m≤?300?000) The length of the string and the number of queries.

The second line contains string s, consisting ofn lowercase 中文版 letters and period signs.

The followingmLines contain the descriptions of queries. TheI-th Line contains integer xi and Ci (1?≤? x i? ≤? N , Ci -a Lowercas 中文版 letter or a period sign), describing the query of assigning symbol Ci To position xi .

Output

Print m numbers, one per line, the i-th of these numbers must is equal to the value of F( s) after performing the i-th assignment.

Sample Test (s) Input
3.b.. Bz.... 1 H3 C9 F
Output
431
Input
4 4.cc.2.3.2 A1 A
Output
1311
Note

Note to the first sample test (replaced periods is enclosed in square brackets).

The original string is ". B.. BZ .... "

  • after the first query F ( HB ... BZ .... = 4     ("hb[...] BZ .... " ?→? "hb.bz[...": " ?→? "hb.bz[...". " ?→? "hb.bz[...] " ?→? "hb.bz. ")
  • After the second query F(hbс.bz .... ) = 3 ("hbс.bz[...]." ? →? "hbс.bz[..." ? →? "hbс.bz[..." ? →? "hbс.bz.")
  • After the third query F(hbс.bz. F. ) = 1 ("hbс.bz[...] F." ? →? "hbс.bz.f.")

Note to the second sample test.

The original string is ". cc.".

  • After the first query: F(... C. ) = 1 ("[...] C." ? →? ". C.")
  • After the second query: f(..... ) = 3 ("[...]..." ? →? "[..]." ? →? "[..]" ? →? ".")
  • After the third query: F(. A.). ) = 1 (". a[..]" ? →? ". A.")
  • After the fourth query: F(aa). ) = 1 ("aa[..]" ? →? "aa.")



Test instructions: Two consecutive points to calculate a contribution, asked is how many contributions. To figure out the total contribution, we consider changing the character before and after the situation and judging whether it is added or minus.
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <    Queue>using namespace Std;typedef Long long ll;int main () {int n,m;    Char s[300005];    Char s1[2];        while (cin>>n>>m) {scanf ("%s", s+1);        int i;        int x;        int L=strlen (s+1);        int ans=0; for (I=1; i<=l; i++) {if (s[i]== '. ')                &&s[i+1]== '. ')        ans++;            } while (m--) {cin>>x>>s1[0]; if ((s1[0]== '. ') &&s[x]== '. ') | | (s1[0]!= '. ')            &&s[x]!= '. '))                {cout<<ans<<endl;            Continue            } S[x]=s1[0];                if (s1[0]!= '. ' &&s[x-1]== '. ')            ans--;                if (s1[0]!= '. ' &&s[x+1]== '. ')            ans--;                if (s1[0]== '. ' &&s[x+1]== '. ')            ans++; if (s1[0]== '. ')          &&s[x-1]== '. ')      ans++;        cout<<ans<<endl; }} return 0;}



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

Codeforces Round #316 (Div. 2) A B C

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.