Codeforces Round #316 (Div. 2) A B C
1 second
256 megabytes
standard input
standard 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 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 the
i-th line aij (1 ≤ j ≤ n,
1 ≤ i ≤ m,
0 ≤ aij ≤ 109) denotes the number of votes for candidate
j in city i.
It is guaranteed that the total number of people in all the cities does not exceed
109.
Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.
3 3
1 2 3
2 3 1
1 2 1
2
3 4
10 10 3
5 1 6
2 2 2
1 5 7
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 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.
#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]>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;
}
1 second
256 megabytes
standard input
standard output
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from
1 to n. Let's assume that Misha chose number
m, 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 integer from 1 to
n is chosen with the same probability), after which the winner is the player, whose number was closer to
c. The boys agreed that if
m and a are located on the same distance from
c, Misha wins.
Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number
n. You need to determine which value of
a 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, where
c is the equiprobably chosen integer from
1 to n (inclusive).
The first line contains two integers n and
m (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 to
2 or 3. The probability that Andrew wins is
2 / 3. If Andrew chooses a = 3, the probability of winning will be
1 / 3. If a = 1, the probability of winning is
0.
In the second sample test: Andrew wins if c is equal to
1 and 2. The probability that Andrew wins is
1 / 2. For other choices of
a the probability of winning is less.
#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;
}
2 seconds
256 megabytes
standard input
standard output
Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of
replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string
s, 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 string s contains no two consecutive periods, then nothing happens.
Let's define f(s) as the minimum number of operations of
replacement 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 string
s is assigned value
ci. After each operation you have to calculate and output the value of
f(s).
Help Daniel to process all queries.
The first line contains two integers n and
m (1 ≤ n, m ≤ 300 000) the length of the string and the number of queries.
The second line contains string s, consisting of
n lowercase English letters and period signs.
The following m lines contain the descriptions of queries. The
i-th line contains integer
xi and
ci (1 ≤ xi ≤ n,
ci — a lowercas English letter or a period sign), describing the query of assigning symbol
ci to position
xi.
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 h
3 c
9 f
4
3
1
4 4
.cc.
2 .
3 .
2 a
1 a
1
3
1
1
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 <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;
}
Codeforces Round #316 (Div. 2) A B C的更多相关文章
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement set
C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...
- Codeforces Round #316 (Div. 2) C. Replacement
题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符, ...
- Codeforces Round #316 (Div. 2) B. Simple Game
思路:把n分成[1,n/2],[n/2+1,n],假设m在左区间.a=m+1,假设m在右区间,a=m-1.可是我居然忘了处理1,1这个特殊数据.被人hack了. 总结:下次一定要注意了,提交前一定要看 ...
- Codeforces Round #316 (Div. 2) D计算在一棵子树内某高度的节点
题:https://codeforces.com/contest/570/problem/D 题意:给定一个以11为根的n个节点的树,每个点上有一个字母(a~z),每个点的深度定义为该节点到11号节点 ...
- Codeforces Round #316 (Div. 2) D. Tree Requests dfs序
D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #316 (Div. 2)
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #316 (Div. 2) D、E
Problem D: 题意:给定一棵n个点树,每个点有一个字母,有m个询问,每次询问某个节点x的子树中所有深度为k的点能否组成一个回文串 分析:一堆点能组成回文串当且仅当数量为奇数的字母不多于1个,显 ...
- Codeforces Round #316 (Div. 2C) 570C Replacement
题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...
- Codeforces Round #316 (Div. 2B) 570B Simple Game 贪心
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...
随机推荐
- PHP -Casbin: 支持 ACL、RBAC、ABAC 多种模型的 PHP 权限管理框架
PHP-Casbin 是一个用 PHP 语言打造的轻量级开源访问控制框架( https://github.com/php-casbin... ),目前在 GitHub 开源.PHP-Casbin 采用 ...
- 紫书 习题 10-4 UVa 1644(素数筛)
素数筛没什么好说的 #include<cstdio> #include<vector> #include<cstring> #define REP(i, a, b) ...
- Unity C# 设计模式(二)简单工厂模式
定义: 简单工厂模式是属于创建型模式,又叫做静态工厂方法(Static Factory Method)模式,但不属于23种GOF设计模式之一. 简单工厂模式是由一个工厂对象决定创建出哪一种产品类的实例 ...
- java无依赖读取Excel文件
说到Java读取Excel文件,用得多的当然是POI或jxls,但今天在看一本书的时候.当中提到使用JdbcOdbcDriver这个驱动类在不依赖第三方库的情况下也能够完毕对Excel文件的读取操作, ...
- Java编程手冊-Collection框架(下)
建议先看Java编程手冊-Collection框架(上) 5. Set<E>接口与实现 Set<E>接口表示一个数学的集合,它不同意元素的反复,仅仅能包括一个null元素. ...
- 自己主动化脚本ssh以及telnet发送命令并退出(windows和linux都适用)
须要安装putty,用到的命令是plink: PuTTY Link: command-line connection utility Unidentified build, Jun 23 2015 1 ...
- HDU 5389 Zero Escape(DP + 滚动数组)
Zero Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- HDU 2435 There is a war Dinic 最小割
题意是有n座城市,n号城市不想让1号城市可达n号,每条道路有一条毁坏的代价,1号还可以修一条不能毁坏的道路,求n号城市所需的最小代价最大是多少. 毁坏的最小代价就直接求一遍最大流,就是最小割了.而可以 ...
- Git 操作笔记
¥先放个地址:这个视频超详细 https://www.bilibili.com/video/av10475153 分了2部分: 1是GitHub的功能介绍:2是pc端+doc命令的操作+发布个人网站 ...
- Ace在线编辑器使用requirejs配置
Ace代码在线编辑器如果需要在requirejs里使用,注意需要使用github上lib/ace目录的文件. 如果使用ajaxorg/ace-builds下面的代码再使用requirejs会报错,不能 ...