# 对拍程序

## 正题

### 标程（exe）

#include<cstdio>
#define maxn 100005
using namespace std;
typedef long long ll;
int n,a[maxn],c[maxn];
ll ans=0;
void msort(int L,int R){
int i,j,mid=L+R>>1;
if (L>=R) return;
msort(L,mid),msort(mid+1,R);
for (int k=L;k<=R;k++) c[k]=a[k];
i=L,j=mid+1;
for (int k=L;k<=R;k++){
if (i<=mid && (j>R || c[i]<=c[j])) a[k]=c[i++];
else a[k]=c[j++],ans+=mid-i+1;
}
}
int main(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",a+i);
msort(1,n);
printf("%lld\n",ans);
return 0;
}

### 暴力（exe）

#include<cstdio>
using namespace std;
typedef long long ll;
int n,a[100001];
ll ans;
int main(){
freopen("data.in","r",stdin);
freopen("data0.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",a+i);
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
if(a[j]<a[i]) ans++;
printf("%lld\n",ans);
return 0;
}

### 数据生成器（exe）

inline int brand(){ return (rand()<<16)+(rand()<<1)+(rand()&1); }

#include <cstdio>
#include <cstdlib>
#include <WINDOWS.h>

#define MAXN 1000
#define MAXX 1000000000

inline int brand(){ return (rand()<<16)+(rand()<<1)+(rand()&1); }

int n;

int main(){
freopen("data.in","w",stdout);
srand(GetTickCount());
n=brand()%MAXN+1;
printf("%d\n",n);
for (int i=1;i<=n;i++){
int x=brand()%MAXX+1;
printf("%d\n",x);
}
return 0;
}

#include <ctime>
#include <cstdio>
#include <cstdlib>

#define MAXN 1000
#define MAXX 1000000000

inline int brand(){ return (rand()<<16)+(rand()<<1)+(rand()&1); }

int n;

int main(){
freopen("data.in","w",stdout);
srand(time(0));
n=brand()%MAXN+1;
printf("%d\n",n);
for (int i=1;i<=n;i++){
int x=brand()%MAXX+1;
printf("%d\n",x);
}
return 0;
}

### 比较程序（bat）

@echo off
:loop
make_data.exe
std.exe
sb.exe
fc data.out data0.out
if errorlevel 1 pause
goto loop

@echo off
:loop
make_data.exe
std.exe < data.in > data.out
sb.exe < data.in > data0.out
fc data.out data0.out
if errorlevel 1 pause
goto loop

## 后记

posted @ 2018-06-01 16:44 xay5421 阅读(...) 评论(...) 编辑 收藏