Codeforces Round #316 (Div. 2)
来源:互联网 发布:误删数据库怎么恢复 编辑:程序博客网 时间:2024/05/22 04:31
A题
题目大意:
一个城市有m个城市,每个城市先投票选出一个候选人,得票多的胜出,得票相同时,下标小的胜出,接着在城市
选出的候选人中选出一个胜者。
解题思路:
按照题意模拟就好了。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=15000;int d[maxn];int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=0;i<m;i++) { int maxx=-1,maxi=0; int x; for(int j=1;j<=n;j++) { scanf("%d",&x); if(x>maxx) { maxx=x; maxi=j; } } //cout<<maxi<<endl; d[maxi]++; } int ans=1; for(int i=1;i<=n;i++) { if(d[i]>d[ans]) { ans=i; } } printf("%d\n",ans); return 0;}
B题
题目大意:
两人在1~n内任选出一个数,再随机产生一个1~n的数,两人谁的离这个数相近就胜出,现在一人已经选了m,且两人距离相同时这人胜出,求另一个人选哪个数有最大的概率胜出。
解题思路:
如果m>n/2,肯定选m-1,如果m<n/2,肯定选m+1,n=1时要特殊处理。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int n,m,ans; scanf("%d%d",&n,&m); if(m>n/2) ans=m-1; else ans=m+1; if(n==1) ans=1; cout<<ans<<endl; return 0;}
C. Replacement
题目大意:
其实就是统计每次改变字符串内的一个元素,还有多少个不同的子串".."。
解题思路:
先统计有多少个"..",接着进行取代操作,这是有2种情况,'.'取代字母,字母取代'.',无论哪种情况,我们只需
考虑操作的左边与右边的情况,拿'.'取代字母的情况,如果'.'的左边是'.‘,则多了1种'..'的子串,如果右边也是'.',也
多了一种。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=300000+1000;char s[maxn];int main(){ int n,q; scanf("%d%d",&n,&q); scanf("%s",s+1); int ans=0; int cur=0; for(int i=1;i<=n;i++) { if(s[i]=='.') { cur++; } else { if(cur>0) { ans+=(cur-1); } cur=0; } } if(cur>0) ans+=(cur-1); for(int i=0;i<q;i++) { int x; char op[5]; scanf("%d%s",&x,op); if(op[0]=='.') { if(s[x]!='.') { int temp=0; if(x>1) { if(s[x-1]=='.') temp++; } if(x<n) { if(s[x+1]=='.') temp++; } ans+=temp; s[x]='.'; } } else { if(s[x]=='.') { int temp=0; if(x>1) { if(s[x-1]=='.') temp++; } if(x<n) { if(s[x+1]=='.') temp++; } ans-=temp; s[x]=op[0]; } } printf("%d\n",ans); } return 0;}
0 1
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- 【codeforces】Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)-C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2) A. Elections
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2)ProblemC
- Codeforces Round #316 (Div. 2) A. Elections
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2)A. Elections
- Codeforces Round #316 (Div. 2)(ABCD)
- “Software Architect” Has Only Lowercase a’s; Deal with It
- asp.net的Request.ServerVariables参数说明
- 设计模式--观察者模式
- centos 7 忘记root密码修改过程
- 编程之美2.17之数组循环移位
- Codeforces Round #316 (Div. 2)
- 随笔-Xcode6新框架的屏幕适配,屏幕上下有黑条,iphone6上不能全屏,只能在左上角显示。
- SYBASE的select into与insert into使用和区别
- jsp页面foreach循环,表单提交,批量处理数据,
- 如何让tomcat在同一个DOS窗口启动
- Java注解
- 两层查询词扩展描述的简单排序
- VS2010,C语言编程调用函数sqrt
- git学习笔记