window.cnblogsConfig = { homeTopImg: [ "https://cdn.luogu.com.cn/upload/image_hosting/clcd8ydf.png", "https://cdn.luogu.com.cn/upload/image_hosting/clcd8ydf.png" ], }

对拍技巧

栗子:一个排序。

准备:

  • 一个写好的暴力(一定要保证正确)
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fir first
#define se second
#define ull unsigned long long
#define endl "\n"
using namespace std;
int n,a[100005];
int main(){
	cin >> n;
	for(int i =1;i <= n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1;i <= n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


名字为\(baoli.cpp\)


  • 一个写好待测的正解
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fir first
#define se second
#define ull unsigned long long
#define endl "\n"
using namespace std;
int n,a[100005];
void selection_sort(int l,int r){
	int length=r-l+1;
	for(int i=1;i<=length;i++){
		int aim=l+i-1;
		for(int j=l+i-1;j<=r;j++) if(a[j]<a[aim]) aim=j;
		swap(a[l+i-1],a[aim]);
	}
}
int main(){
	cin >> n;
	for(int i =1;i <= n;i++){
		scanf("%d",&a[i]);
	}
	selection_sort(1,n);
	for(int i = 1;i <= n;i++){
		printf("%d ",a[i]);
	}
	return 0;
}


名字为zhengji.cpp


  • 一个shuju
    然后问我们就要写shuju了
    我们通过 rand 函数 来造随机数据
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a,b,c;
int random(){//超级rand
	return ((rand()<<24)|0xff000000) & ((rand()<<12)|0x00fff000) &(rand()|0x00000fff); 
} 
signed main()
{
    srand(time(0));//随机种子
    n=random()%100000+1;
    cout<<n<<endl;
    while(n--){
		cout<<random()%1000000-500000<<" ";
	}
    return 0;
}


名字为:shuju.cpp


  • 一个checker

它起到类似评测机的作用

//评测运行
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read()
{
    ll ret=0;char ch=' ',c=getchar();
    while(!(c<='9'&&c>='0')) ch=c,c=getchar();
    while(c<='9'&&c>='0') ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
int main()
{
    for(int i=1;i<=10000;i++)
    {
        system("shuju.exe>stdsin.txt");//运行数据至stdin文件
        system("baoli.exe<stdsin.txt>baoli.txt");
        double st=clock();//时间
        system("zhengji.exe<stdsin.txt>zhengji.txt");
        double ed=clock();//时间
        if(system("fc baoli.txt zhengji.txt")) {printf("WA on #%d Time:%.3lfms  please open the 'stdsin.txt'\n",i,ed-st);break;}
        else printf("AC on #%d Time:%.3lfms\n",i,ed-st);
        cout<<"------------------\n\n";
    }
    return 0;
}

然后运行check就可以进行测试了

注意:每一次改完正解后都要编译

打包的zip,方便食用

posted @ 2023-11-24 19:39  gsczl71  阅读(63)  评论(0编辑  收藏  举报