codeforces#316 div2
来源:互联网 发布:淘宝店铺怎么设置打折 编辑:程序博客网 时间:2024/05/22 04:49
点击打开题目链接
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 are counted for each city: it is assumed that in each city won the candidate who 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 is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.
Determine who will win the elections.
The first line of the input contains two 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 thei-th lineaij (1 ≤ j ≤ n,1 ≤ i ≤ m,0 ≤ aij ≤ 109) denotes the number of votes for candidatej in cityi.
It is guaranteed that the total number of people in all the cities does not exceed109.
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
3 31 2 32 3 11 2 1
2
3 410 10 35 1 62 2 21 5 7
1
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 has 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 has the same number of votes, and 1 has 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, the one with the smaller index.
1001 简单的模拟题,根据题意直接模拟就好(两轮选举);1、每行选最大的(有相同的按小标小的取~~)2、被选举最多的输出~同样有相同按小标小的输出:
代码:
#include<iostream>#include <stdio.h>#include<string.h>using namespace std;#define N 110int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { long long int a[N]; int b; memset(a,0,sizeof(a)); for(int i=1;i<=m;i++) { long long max2=0; int pos=1; for(int j=1;j<=n;j++) { scanf("%d",&b); if(max2<b) { max2=b; pos=j; } } a[pos]++; } long long int max1=0; int pos=1; for(int i=1;i<=n;i++) { if(max1<a[i]) { max1=a[i]; pos=i; } } printf("%d\n",pos); } return 0;}
点击打开题目链接
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from1 ton. Let's assume that Misha chose numberm, and Andrew chose numbera.
Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer toc. The boys agreed that ifm and a are located on the same distance fromc, Misha wins.
Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and numbern. You need to determine which value ofa Andrew must choose, so that the probability of his victory is the highest possible.
More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that is maximal, wherec is the equiprobably chosen integer from1 to n (inclusive).
The first line contains two integers n andm (1 ≤ m ≤ n ≤ 109) — the range of numbers in the game, and the number selected by Misha respectively.
Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.
3 1
2
4 3
2
In the first sample test: Andrew wins if c is equal to2 or3. The probability that Andrew wins is2 / 3. If Andrew choosesa = 3, the probability of winning will be1 / 3. Ifa = 1, the probability of winning is0.
In the second sample test: Andrew wins if c is equal to1 and2. The probability that Andrew wins is1 / 2. For other choices ofa the probability of winning is less.
数学题:直接判断 左右区间大小即可,注意特殊数据的判断
代码:
#include<iostream>#include <stdio.h>#include<string.h>using namespace std;#define N 110int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { if(n==m) { printf("%d\n",n==1?1:n-1); continue; } int a=n-m; printf("%d\n",a>m-1?m+1:m-1); } return 0;}
点击打开题目链接
Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation ofreplacement as the following sequence of steps: find a substring ".." (two consecutive periods) in strings, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If strings contains no two consecutive periods, then nothing happens.
Let's define f(s) as the minimum number of operations ofreplacement to perform, so that the string does not have any two 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 valueci. After each operation you have to calculate and output the value off(s).
Help Daniel to process all queries.
The first line contains two 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 English letters and period signs.
The following m lines contain the descriptions of queries. Thei-th line contains integerxi andci (1 ≤ xi ≤ n,ci — a lowercas English letter or a period sign), describing the query of assigning symbolci to positionxi.
Print m numbers, one per line, the i-th of these numbers must be equal to the value of f(s) after performing the i-th assignment.
10 3.b..bz....1 h3 c9 f
431
4 4.cc.2 .3 .2 a1 a
1311
Note to the first sample test (replaced periods are 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.")
简单题:注意在数据查询处理时只需要看改变位置的前后是否是'.'即可~不用再遍历一遍~~
代码:
#include<iostream>#include <stdio.h>#include<string.h>#include<string>using namespace std;#define N 100010char a[3*N];char b[3*N];int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { scanf("%s",a); int ans=0; for(int i=0; i<n-1; i++) { if(a[i]=='.'&&a[i+1]=='.')ans++; } int pos; char c; for(int i=0; i<m; i++) { scanf("%d %c",&pos,&c); if(n==1) { printf("0\n"); } else if(a[pos-1]=='.'&&c!='.') { if(pos>=2&&pos<n) printf("%d\n",(ans-=((a[pos-2]=='.')+(a[pos]=='.')))); else if(pos<n) printf("%d\n",(ans-=(a[pos]=='.'))); else if(pos>=2&&pos>=n) printf("%d\n",(ans-=(a[pos-2]=='.'))); } else if(a[pos-1]!='.'&&c=='.') { if(pos>=2&&pos<n) printf("%d\n",(ans+=((a[pos-2]=='.')+(a[pos]=='.')))); else if(pos<n) printf("%d\n",(ans+=(a[pos]=='.'))); else if(pos>=2&&pos>=n) printf("%d\n",(ans+=(a[pos-2]=='.'))); } else printf("%d\n",ans); a[pos-1]=c; } } return 0;}
- Codeforces #316 DIV2
- codeforces#316 div2
- codeforces #78 div2 C
- codeforces 83div2
- 【codeforces #91 div2】
- codeforces 105 div2 A
- codeforces 105 div2 B
- CodeForces #120 DIV2
- Codeforces---125--div2--总结
- Codeforces-127-div2
- codeforces-div2-128
- codeforces-div2-134
- Codeforces 135 div2
- codeforces 137 div2
- Codeforces #137 div2
- Codeforces #49 div2
- codeforces 145 div2 A
- codeforces #147(div2)
- 视音频技术零基础学习笔记(一)
- OC - Menory(High)
- Linux 网络配置
- 文件权限管理及ACL设置
- 黑马程序员——java复习总结——GUI和网络编程
- codeforces#316 div2
- hdu 1250 高精度+斐波那契
- centos7下安装adagios
- 谷歌技术"三宝"之谷歌文件系统
- ThreadLocal用法和实现原理
- Google后Hadoop时代的新“三驾马车”
- 华为OJ题目:24点运算
- 配置python环境
- UIAlertController用法大全