2022.04.12(Codeforces Round #781 (Div. 2))

Problem - A - Codeforces

说明:直接输出n-3,1,1,1即可

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int gcd(int x,int y){
    if(x<y){
        swap(x,y);
    }
    if(x%y==0){
        return y;
    }
    return gcd(y,x%y);
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        if(n%4==0){
            printf("%d %d %d %d\n",n/4,n/4,n/4,n/4);
        }else{
            for(int i=1;i<n-2;i++){
                if(gcd(i,n-2-i)==1){
                    printf("%d %d 1 1\n",i,n-2-i);
                    break;
                }
            }
        }
    }

}
View Code

Problem - B - Codeforces

说明:直接模拟即可,首先肯定是数组中最多的数字,通过有限次的复制数组然后交换,一直循环

wa掉的点:(1)循环写的有问题,应该是模拟每一步,不应该简单统计;

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int maxx=1e5+10;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        int a[maxx]={0};
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        int sum[maxx]={0};
        int now=a[0];
        int t=0;
        for(int i=0;i<n;i++){
            if(a[i]==now){
                sum[t]++;
            }else{
                now=a[i];
                t++;
                sum[t]=1;
            }
        }
        sort(sum,sum+t+1);
        int p=sum[t];
        if(t==0){
            printf("0\n");
            continue;
        }
        now=sum[t];
        int ans=0;
        p=sum[t];
        while(1){
            if(now==n){
                break;
            }
            if(now>n){
               // ans+=n-p;
                break;
            }
            if(now<n){
                //printf("变换前:ans:%d p:%d now:%d\n",ans,p,now);
                ans++;
                p=now;
                ans+=min(p,n-p);
                now*=2;
                //printf("变换后:ans:%d p:%d now:%d\n",ans,p,now);
            }

        }
        printf("%d\n",ans);
    }

}
View Code

 

posted @ 2022-04-12 21:27  bonel  阅读(27)  评论(0编辑  收藏  举报