implementation的几道CF题

本文涵盖了Codeforces上的一些有趣编程题目,包括镜像文字判断、淘汰赛数学建模、时间顺序把握、足球赛事矩阵记录及数据一致性验证等算法挑战。通过实例解析,深入浅出地介绍了解题思路与技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有时一些Codeforces上的implementation题也挺有意思的(给我等菜鸟继续刷题的信心啊!!生气

codeforces 420 A. Start Up

http://codeforces.com/problemset/problem/420/A

大意:给一字符串,求解是否是镜像串。

(读懂题了就行)

镜像文字: 逆序看和原来是一样的。所以对单个字母也是有要求的,比如S wrong,A right。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e5+10;
char s[N];
char str[15]="AHIMOTUVWXY";
bool check(int len){
    int left=0,right=len-1;
    while(left<=right){
        if(s[left]!=s[right]){
            return 0;
        }
        left++;
        right--;
    }
    return 1;
}
int main()
{
    //freopen("cin.txt","r",stdin);
    //str="AHIMOTUVWXY";
    while(~scanf("%s",s)){
        int len=strlen(s);
        bool ans=0;
        if(check(len)){
            ans=1;
            for(int i=0;i<len;i++){
                bool tag=0;
                for(int j=0;j<11;j++){
                    if(s[i]==str[j]){
                        tag=true;
                        break;
                    }
                }
                if(tag==0){
                    ans=0;
                    break;
                }
            }
        }
        if(ans) puts("YES");
        else puts("NO");
    }
    return 0;
}

codeforces 417 A. Elimination
http://codeforces.com/problemset/problem/417/A

读懂题后,建立方程,然后暴力解方程:

#include <iostream>
#include <cstdio> 
using namespace std;

int main()
{
    int c,d,n,m,k;
    while(~scanf("%d%d%d%d%d",&c,&d,&n,&m,&k)){
        int len1=m,len2=n*m,ans=1<<29;  //直接暴力解方程
        for(int x=0;x<=len1;x++){
            for(int y=0;y<=len2;y++){
                if(n*x+y+k>=len2){
                    ans=min(ans,c*x+d*y);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


codeforces 417B - Crash

http://codeforces.com/problemset/problem/417/B

把握好题意:时间顺序。chronological order

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e5+10;
int f[N];
int main()
{
    //freopen("cin.txt","r",stdin);
    int n,x,k;
    while(cin>>n){
        memset(f,-1,sizeof(f));
        bool flag=1;
        for(int i=0;i<n;i++){
            scanf("%d%d",&x,&k);
            if(x==f[k]+1)  f[k]++;
            else if(x>f[k]+1) flag=0;
        }
        if(flag) puts("YES");
        else puts("NO");
    }
    return 0;
}

codeforces 418 A. Football

http://codeforces.com/problemset/problem/418/A

矩阵记录相通的信息。(邻接矩阵的思想)

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
bool map[1005][1005];
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k)){
        memset(map,0,sizeof(map));
        bool flag=1;
        for(int i=1;i<=n;i++){
            for(int j=i+1,d=0;d<k;d++,j++){
                j=(j%n==0?n:j%n);
                map[i][j]=1;
                if(map[j][i]==1){
                    flag=0;
                    break;
                }
            }
            if(!flag) break;
        }
        if(flag){
            printf("%d\n",n*k);
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    if(map[i][j])  printf("%d %d\n",i,j);
                }
            }
        }
        else printf("-1\n");
    }
    return 0;
}


codeforces 413 A. Data Recovery

http://codeforces.com/problemset/problem/413/A

If the data is consistent 是否合理,是否一致

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[110];
int main()
{
    //freopen("cin.txt","r",stdin);
    int n,m,maxm,minm;
    while(~scanf("%d%d%d%d",&n,&m,&minm,&maxm)){
        for(int i=1;i<=m;i++) scanf("%d",&a[i]);
        sort(a+1,a+m+1);
        a[0]=minm;
        a[m+1]=maxm;
        int sum=m;
        if(a[m+1]>a[m]) sum++;
        if(a[0]<a[1]) sum++;
        if(a[m+1]<a[m]||a[0]>a[1]) sum=-1;

        if(sum<0||sum>n) puts("Incorrect"); //
        else puts("Correct");
    }
    return 0;
}

codeforces 413 B. Spyke Chatting

http://codeforces.com/problemset/problem/413/B

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=2e4+10;
int g[N][12];  //employee接听
LL h[12];  //chat接收
LL f[N];   // employee 发出
LL fa[N][12];
int main()
{
    //freopen("cin.txt","r",stdin);
    int n,m,k;
    while(~scanf("%d%d%d",&n,&m,&k)){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%d",&g[i][j]);
            }
        }
        memset(h,0,sizeof(h));
        memset(f,0,sizeof(f));
        memset(fa,0,sizeof(fa));
        int a,b;
        for(int i=0;i<k;i++){
            scanf("%d%d",&a,&b);
            h[b]++;
            f[a]++;
            fa[a][b]++;
        }
        LL sum=0;
        for(int i=1;i<=n;i++){
            sum=0;
            for(int j=1;j<=m;j++){
                if(g[i][j]){
                    sum+=h[j];
                    if(fa[i][j]) sum-=fa[i][j];
                }
            }
            if(i<n)printf("%I64d ",sum);
            else printf("%I64d\n",sum);
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值