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

A:
题目地址:Elections
题意: 一个国家有n个候选人,m个城市,每个城市先投票选出一个候选人,得票多的胜出,得票相同时,下标小的胜出,接着在城市选出的候选人中选出一个胜者,同样是得票相同时,下标小的胜出。
思路:直接模拟一下。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
using namespace std;
int has[110];
int main()
{
    int n,m,k,sum,x;
    int Max,ans;
    while(~scanf("%d %d",&n,&m)) {
        memset(has,0,sizeof(has));
        for(int i=0; i<m; i++) {
            k=1;
            sum=-1;
            for(int i=1; i<=n; i++) {
                scanf("%d",&x);
                if(sum<x) {
                    sum=x;
                    k=i;
                }
            }
            has[k]++;
        }
        Max=0;
        ans=1;
        for(int i=1; i<=n; i++) {
            if(has[i]>Max) {
                Max=has[i];
                ans=i;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

B:
题目地址:Simple Game
题意:两人在1~n内任选出一个数m,a,再随机产生一个1~n的数c,两人谁的离这个数相近就胜出,现在一人已经选了m,且两人距离相同时这人胜出,求另一个人选哪个数有最大的概率胜出,如果有多种情况,输出最小的那个。
思路: 如果m>=n/2,肯定选m-1,如果m

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
using namespace std;
int n,m;

int main()
{
    while(~scanf("%d%d",&n,&m)) {
        if(n == 1) {
            printf("1\n");
        } else if(2*m<=n) {
            printf("%d\n",m+1);
        } else {
            printf("%d\n",m-1);
        }
    }
    return 0;
}

C:
题目地址:Replacement
题意:给你一个字符串,由‘.’和小写字母组成。把两个相邻的‘.’替换成一个‘.’,算一次变换。现在给你一些操作,操作内容是把某个位置的字符变成给定的字符,求出每次操作后,需要多少次变换才能把原串所有相的‘.’变成一个‘.’。每次操作是累加的,即一次操作就会把原串替换一个字符。
思路:先把原串中操作次数记录下来,然后看当前的替换操作是什么,然后各种乱搞就好了。我简直太蠢了。。sad

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef __int64  LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-7;
const int Maxn=300010;
char str[Maxn];
int main()
{
    int n,m,i,x;
    char c[2];
    int cnt=0;
    int ans=0;
    scanf("%d %d",&n,&m);
    scanf("%s",str+1);
    for(i=1;i<=n;i++){
        if(str[i]=='.')
            cnt++;
        else{
            if(cnt>0)
                ans+=cnt-1;
            cnt=0;
        }
    }
    if(cnt>0)
        ans+=cnt-1;
    while(m--){
        scanf("%d %s",&x,c);
        if(c[0]=='.'){
            if(str[x]!='.'){
            cnt=0;
            if(x>1){
                if(str[x-1]=='.')
                 cnt++;
            }
            if(x<n){
                if(str[x+1]=='.')
                    cnt++;
            }
            str[x]='.';
            ans+=cnt;
            }
        }
        else{
            if(str[x]=='.'){
                cnt=0;
                if(x>1){
                    if(str[x-1]=='.')
                      cnt++;
                }
               if(x<n){
                    if(str[x+1]=='.')
                        cnt++;
               }
               str[x]=c[0];
               ans-=cnt;
            }
        }
        printf("%d\n",ans);
    }
    return 0;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rocky0429

一块也是爱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值