讨论 / 求助!!
rgb456rgb 2012-02-14 04:55:00
点我顶贴 收藏 删除

wa:80,求牛帮忙看下哪里错了(用预留写的)

#include<stdio.h>

#include<stdlib.h>

int n,i,j,k,l,m,a[5100],b[51000][4],c[91000],d[91000],f,r,fl,dl[720000],jh[5200][120],li[51000][3];

int t,t1,t2,t3,t4;

void cl(int t){

int i,j,k,t1,t2,t3,t4,f;

k=t-m;

while (c[t]>a[k]){

// printf("%d %d %d %d %d %d\n",t,c[t],jh[k][0],d[t],jh[k][1],a[k]);

// system("pause");

f=0;

for (i=1;i<=jh[k][0]&&c[t]>a[k];i++){

t1=jh[k][i];

if (d[t1]==d[t]-1){

f=1;

if (b[t1][1]==k) {t2=li[t1][1];t3=1;} else {t2=li[t1][2];t3=2;}

if (t2>c[t]-a[k]) t2=c[t]-a[k];

c[t]-=t2;

li[t1][t3]-=t2;

c[t1]+=t2;l++;dl[l]=t1;

t2=0;

if (li[t1][t3]==0) {

for (j=i;j<jh[k][0];j++)

jh[k][j]=jh[k][j+1];

jh[k][0]--;

}

}

}

if (f==0){

t4=99999999;

for (i=1;i<=jh[k][0];i++){

t1=jh[k][i];

if (d[t1]<t4) t4=d[t1];

}

d[t]=t4+1;

}

}

}

int main(){

scanf("%d%d",&n,&m);

for (i=1;i<=n;i++)

scanf("%d",&a[i]);

for (i=1;i<=m;i++)

scanf("%d%d%d",&b[i][1],&b[i][2],&b[i][3]);

for (i=1;i<=m;i++){

d[i]=2;c[i]=b[i][3];dl[i]=i;

}

for (i=m+1;i<=m+n;i++){

d[i]=1;

}

r=m;

f=1;

while (f<=r){

l=r;

for (i=f;i<=r;i++){

t=dl[i];t1=b[t][1]+m;t2=b[t][2]+m;

// printf("%d %d\n",t,c[t]);

while (c[t]>0&&(d[t]<40)){

fl=0;

t1=b[t][1]+m;

if (d[t]==d[t1]+1){

if (li[t][1]==0){li[t][1]=c[t];t3=t1-m;jh[t3][0]++;jh[t3][jh[t3][0]]=t;} else li[t][1]+=c[t];

c[t1]+=c[t];c[t]=0;

fl=1;cl(t1);

}

t2=b[t][2]+m;

if (d[t]==d[t2]+1){

if (li[t][2]==0){li[t][2]=c[t];t3=t2-m;jh[t3][0]++;jh[t3][jh[t3][0]]=t;} else li[t][2]+=c[t];

c[t2]+=c[t];c[t]=0;

fl=1;cl(t2);

}

if (fl==0){

if (d[t1]<d[t2]) d[t]=d[t1]+1; else d[t]=d[t2]+1;

}

//printf("%d\n",c[t]);

}

}

f=r+1;r=l;

// printf("%d %d\n",f,r);

}

t4=0;

for (i=1;i<=m;i++)

t4+=b[i][3];

for (i=m+1;i<=m+n;i++){

// printf("%d ",c[i]);

t4-=c[i];

}

printf("%d\n",t4);

//system("pause");

}

测试结果1: 通过本测试点|有效耗时46ms

测试结果2: 通过本测试点|有效耗时47ms

测试结果3: 通过本测试点|有效耗时47ms

测试结果4: 通过本测试点|有效耗时47ms

测试结果5: 通过本测试点|有效耗时47ms

测试结果6: 通过本测试点|有效耗时47ms

测试结果7: 通过本测试点|有效耗时47ms

测试结果8: 通过本测试点|有效耗时47ms

测试结果9: 测试结果错误.错误结果为:271

正确结果应为:32646

测试结果10: 测试结果错误.错误结果为:271

正确结果应为:29752

#1 liuxinyi_rqnoj@2012-02-13 04:53:00
回复 删除
文件格式

#include<stdio.h>

#include<stdlib.h>

main()

{

FILE *fin,*fout;

fin=fopen("seat10.in","r");

fout=fopen("seat10.out","w");

int i,j,m,n,k,l,d,b1,b2,b3,b4,max=0,r=0,mm=0;

int hash1[2001]={0};

int hash2[2001]={0};

int s[2001]={0};

fscanf(fin,"%d%d%d%d%d",&m,&n,&k,&l,&d);

for(i=1;i<=d;i++)

{

fscanf(fin,"%d%d%d%d",&b1,&b2,&b3,&b4);

if(b2==b4)

{

if(b1>b3) hash1[b3]++;

else hash1[b1]++;

}

if(b1==b3)

{

if(b2>b4) hash2[b4]++;

else hash2[b2]++;

}

}

for(i=1;i<k;i++)

{

for(j=1;j<=n;j++)

{

if(hash1[j]>max)

{

max=hash1[j];

r=j;

}

}

s[r]++;

max=0;

hash1[r]=0;

}

for(i=1;i<=n;i++)

{

if(hash1[i]>max)

{

max=hash1[i];

r=i;

}

}

s[r]++;

for(i=1;i<=2000;i++)

if(s[i]!=0&&mm<(k-1))

{

fprintf(fout,"%d ",i);

mm++;

s[i]=0;

}

for(i=1;i<=2000;i++)

if(s[i]!=0)

fprintf(fout,"%d\n",i);

max=0;

for(i=1;i<=2000;i++)

s[i]=0;

for(i=1;i<l;i++)

{

for(j=1;j<=n;j++)

if(hash2[j]>max)

{

max=hash2[j];

r=j;

}

s[r]++;

max=0;

hash2[r]=0;

}

for(i=1;i<=n;i++)

{

if(hash2[i]>max)

{

max=hash2[i];

r=i;

}

}

s[r]++;

mm=0;

for(i=1;i<=2000;i++)

if(s[i]!=0&&mm<(l-1))

{

fprintf(fout,"%d ",i);

mm++;

s[i]=0;

}

for(i=1;i<=2000;i++)

if(s[i]!=0)

fprintf(fout,"%d",i);

fclose(fin); fclose(fout);

}

#2 jiajian199919@2012-02-13 21:38:00
回复 删除
#include<stdio.h>

#include<stdlib.h>

main()

{

FILE *fin,*fout;

fin=fopen("seat10.in","r");

fout=fopen("seat10.out","w");

int i,j,m,n,k,l,d,b1,b2,b3,b4,max=0,r=0,mm=0;

int hash1[2001]={0};

int hash2[2001]={0};

int s[2001]={0};

fscanf(fin,"%d%d%d%d%d",&m,&n,&k,&l,&d);

for(i=1;i<=d;i++)

{

fscanf(fin,"%d%d%d%d",&b1,&b2,&b3,&b4);

if(b2==b4)

{

if(b1>b3) hash1[b3]++;

else hash1[b1]++;

}

if(b1==b3)

{

if(b2>b4) hash2[b4]++;

else hash2[b2]++;

}

}

for(i=1;i<k;i++)

{

for(j=1;j<=n;j++)

{

if(hash1[j]>max)

{

max=hash1[j];

r=j;

}

}

s[r]++;

max=0;

hash1[r]=0;

}

for(i=1;i<=n;i++)

{

if(hash1[i]>max)

{

max=hash1[i];

r=i;

}

}

s[r]++;

for(i=1;i<=2000;i++)

if(s[i]!=0&&mm<(k-1))

{

fprintf(fout,"%d ",i);

mm++;

s[i]=0;

}

for(i=1;i<=2000;i++)

if(s[i]!=0)

fprintf(fout,"%d\n",i);

max=0;

for(i=1;i<=2000;i++)

s[i]=0;

for(i=1;i<l;i++)

{

for(j=1;j<=n;j++)

if(hash2[j]>max)

{

max=hash2[j];

r=j;

}

s[r]++;

max=0;

hash2[r]=0;

}

for(i=1;i<=n;i++)

{

if(hash2[i]>max)

{

max=hash2[i];

r=i;

}

}

s[r]++;

mm=0;

for(i=1;i<=2000;i++)

if(s[i]!=0&&mm<(l-1))

{

fprintf(fout,"%d ",i);

mm++;

s[i]=0;

}

for(i=1;i<=2000;i++)

if(s[i]!=0)

fprintf(fout,"%d",i);

fclose(fin); fclose(fout);

}

#3 LOVE.叛逆@2012-02-14 04:55:00
回复 删除
。。。

这也忒长了点吧。。。

查看更多回复
提交回复