ACM技巧(对拍)

准备一个文件夹,创四个c++项目

1.data.cpp(随机生成输入数据)

//以Hdu 6709 为例
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(){
    srand(time(0));
    int t=rand()%10+1;
    cout<<t<<endl;
    while(t--){
        int n,k;
        n=rand()%5+1;
        k=rand()%10+1;
        cout<<n<<" "<<k<<endl;
        for(int i=0;i<n;i++){
            int x=rand()%10+1;
            cout<<x<<" ";
        }
        cout<<endl;
    }
    return 0;
}

2.ac.cpp(贴标程)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=1e5+7;
int a[N];
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		int n,k;
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		ll ans=k,ok=0;
		for(int i=1;i<=n;i++)
			ok+=a[i]/k;
		if(ok>=n-1) {
			for(int i=1;i<=n;i++)
				ans+=a[i];
			printf("%lld\n",ans);
		}
		else {
			for(int i=1;i<=n;i++)
				ans+=a[i],a[i]%=k;
			sort(a+1,a+1+n,greater<int>());
			for(int i=1;i<=n-1-ok;i++)
				ans+=k-a[i];
			printf("%lld\n",ans);
		}
	}
	return 0;
}

3.wa.cpp(贴你自己写的代码)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+10;
const ll inf=1e18;
int t,n;
ll k,x;
priority_queue<ll> pq;
int main()
{
    scanf("%d",&t);
    while(t--){
        scanf("%d%I64d",&n,&k);
        ll sum=0;
        for(int i=0;i<n;i++){
            scanf("%I64d",&x);
            pq.push(x);
            sum+=x;
        }
        ll ans=0;
        if(n==1){
            ans+=pq.top()+k;pq.pop();
        }
        else {
            if(pq.top()<=k){
                ans+=k;
                while(!pq.empty()){
                    if(pq.size()==1){
                        ans+=pq.top();pq.pop();
                    }
                    else {
                        ans+=k;pq.pop();
                    }
                }
            }
            else {
                ans+=k;
                int flag=0;
                ll s1=0,s2=0;
                while(!pq.empty()){
                    int now=pq.top();
                    if(now>=k){
                        s1+=k;
                        s2+=now;
                    }
                    else {
                        flag=1;
                        break;
                    }
                    pq.pop();
                }
                if(flag==0){
                    ans+=s2;
                }
                else {
                    int ff=0;
                    while(!pq.empty()){
                        if(s2>s1){
                            s1+=k;
                            s2+=pq.top();pq.pop();
                        }
                        else {
                            ff=1;
                            break;
                        }
                    }
                    if(ff==0){
                        ll nn=max(s1,s2);
                        ans+=nn;
                    }
                    else {
                        ans+=s1;
                        while(!pq.empty()){
                            if(pq.size()==1){
                                ans+=pq.top();pq.pop();
                            }
                            else {
                                ans+=k;pq.pop();
                            }
                        }
                    }
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

4.test.cpp(对拍)

//在test前要先把各个项目编译一下
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
    while(true){
        system("data.exe>data.in");
        system("ac.exe<data.in>ac.out");
        system("wa.exe<data.in>wa.out");
        if(system("fc ac.out wa.out")){
            system("pause");
        }
    }
    return 0;
}

5.查看没过的数据

去相应文件夹用记事本打开data.in即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值