Codeforces Round #316 (Div. 2) (ABC题)
A - Elections
题意:
每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利。
最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序),第一位获得胜利。
求最后选举获胜者。
思路:
直接模拟就可以。
代码:
/*
* @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_back
typedef long long lint;
typedef long long ll;
typedef long long LL;
const int maxn = 105;
struct C{
int v;
int no;
}c[maxn][maxn];
int cnt[maxn];
bool cmp(C a , C b){
if(a.v != b.v) return a.v < b.v;
return a.no > b.no;
}
int main(){
//freopen("input.txt","r",stdin);
int n,m;
while( cin >> n >> m){
cls(cnt);
for(int i = 1 ; i <= m ; i++){
for(int j = 1 ; j <= n ; j++){
c[i][j].no = j;
scanf("%d",&c[i][j].v);
}
sort(c[i]+1 , c[i]+n+1 , cmp);
for(int j = 1 ; j <= n ; j++){
}
cnt[c[i][n].no]++;
}
int ans = n;
int tmp = cnt[n];
for(int i = n ; i >= 1 ; i--){
if(tmp <= cnt[i]){
ans = i;
tmp = cnt[i];
}
}
cout << ans << endl;
}
return 0;
}
B - Simple Game
题意:
Misha 与 Andrew 玩游戏,两人在1~n范围内各选一个数字(可同样),然后在1~n范围内随机出一个数字x,Misha 和 Andrew 的数字减去x的绝对值较小者获胜。若一致,则 Misha 获胜,如今已知 n 与 Misha 选择的数字,求 Andrew 胜率最高(同等胜率取最小)的数字。
思路:
分类讨论,仅仅须要考虑 Misha 左右的位置就可以。
注意 n = 1 时的情况特判。
代码:
/*
* @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_back
typedef long long lint;
typedef long long ll;
typedef long long LL;
int main(){
// freopen("input.txt","r",stdin);
int m,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 << m-1 << endl;
}
continue;
}
int ans;
if(n&1){
int tmp = (n+1) / 2;
if(m < tmp){
ans = m+1;
}
else if(m > tmp)
ans = m-1;
else if(m == tmp)
ans = m-1;
}
else{
int tmp = n / 2;
if(m < tmp){
ans = m+1;
}
else if(m > tmp)
ans = m-1;
else if(m == tmp)
ans = m+1;
}
cout << ans << endl;
}
return 0;
}
C - Replacement
题意:
输入一个含 ‘.’ 与小写英文字母的字符串。
定义一种操作为: 将字符串中的 “..” 替代为 “.” ;
定义字符串的价值等于最大操作次数。
如今有 m 个询问 , 每个询问都将改变字符串指定位置上的字符为指定字符,计算询问后的字符串价值。
思路:
这题神似线段树的风格(用线段树也确实能够做。
这题的关键是简化不同情况的分类讨论。我之前的想法一直是记录每个 ‘.’ 区间的情况,然后询问时二分在哪个区间就可以,结果发现写起来思路混乱毫无逻辑。又是set又是map的。。
直到在standing榜看到第二名的神牛的代码。
。怒删原来代码重写了一份。简单了非常多非常多。
代码:
/*
* @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_back
typedef long long lint;
typedef long long ll;
typedef long long LL;
int main(){
//freopen("input.txt","r",stdin);
int n , m ;
string s;
cin >> n >> m >> s;
int cnt = 0;
for( int i = 1 ; i < s.length() ; i++ ){
if( s[i] == '.' && s[i-1] == '.') cnt ++;
}
for( int i = 1 ; i <= m ; i++ ){
int p ;
char c ;
scanf( "%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;
}
Codeforces Round #316 (Div. 2) (ABC题)的更多相关文章
- B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #247 (Div. 2) ABC
Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/Wa ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #556 (Div. 2)-ABC(这次的题前三题真心水)
A. Stock Arbitraging 直接上代码: #include<cstdio> #include<cstring> #include<iostream> ...
随机推荐
- 如何在Linux的桌面上创建快捷方式或启动器
如果在Linux桌面系统中你经常使用一个程序,你可能想去创建一个“桌面快捷方式”,以便于你在桌面只要点击一下快捷方式就可以启动它.虽然不少带有图形界面的程序会在安装时自动在桌面上创建快捷方式,还有一些 ...
- 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---16
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- phpexcel--导入excel表格
最近在做一个小项目,就是一个管理信息的小系统:要求有导入和导出的信息为excel的功能,研究过导入导出功能的肯定知道导出要比导入的简单多了,导入用的phpexcel,当时对phpexcel是完全不了解 ...
- SQLite中特殊的INSERT语句
SQLite中特殊的INSERT语句 在SQLite中,INSERT是基本语句,用来向表中插入数据.但是当表中存在字段存在唯一.非空.检查.主键等约束时,插入的数据很容易和约束冲突,造成插入操作失 ...
- 关于bug的沟通
关于BUG的沟通 一个人要去做一件事情,一般来说是按照自己的意愿去做的,如果不是自己想做而是被要求这么做的话,心里一定会留下点不愉快,特别是那种有自信有自己主见的人,比如说开发人员,当测试人员发现一个 ...
- Spring Cloud Stream介绍-Spring Cloud学习第八天(非原创)
文章大纲 一.什么是Spring Cloud Stream二.Spring Cloud Stream使用介绍三.Spring Cloud Stream使用细节四.参考文章 一.什么是Spring Cl ...
- go语言学习之路六:接口详解
Go语言没有类和继承的概念,但是接口的存在使得它可以实现很多面向对象的特性.接口定义了一些方法,但是这些方法不包含实现的代码.也就是说这些代码没有被实现(抽象的方法).同时接口里面也不包含变量. 看一 ...
- 一次程序bug的排查
这周准备下一个QA测试的版本,把版本发到测试环境就开始发现各种问题,修修补补搞了一周,总算告一段落了. 分析一下几个bug的问题,都集中在程序模块的整合中.一个模块的一个小的修改,造成另一个模块的 ...
- ef SaveChanges()报"更新条目时出错,有关详细信息请参见内部异常"
报这个错误是因为表没有设置主键,设完主键后再重新更新Entity,就可以添加了
- OpenSceneGraph 3.2 版本修改点
OpenSceneGraph-3.2.0稳定版本发布了,改善了对iOS.Android的支持,支持OpenGL的更多新特性.可以通过 下载版块来进行下载. OpenSceneGraph 3.2 发布. ...