NOIP2010三国游戏
sanguo.rar
(541.49 KB)
http://www. 测试了一下得了90分,搞到了测试数据,前9个都能快速过,最后一个数据就是过不了,调试的时候程序总是报错。程序代码:
#include <stdio.h> #include <stdlib.h> FILE *fin,*fout; void print(long general[500][500],long n) { int i,j; printf("\n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) printf("%2ld ",general[i][j]); printf("\n"); } } void Qsort(long general[500],long startPos,long endPos) { int i,j,temp; temp=general[startPos]; i=startPos,j=endPos; while(i<j) { while(temp>=general[j]&&i<j)j--; general[i]=general[j]; while(temp<=general[i]&&i<j)i++; general[j]=general[i]; } general[i]=temp; if(i-1>startPos)Qsort(general,startPos,i-1); if(endPos>i+1)Qsort(general,i+1,endPos); } int main() { long general[500][500]={},n,i,j,ans; fin=fopen("sanguo.in","r"); fout=fopen("sanguo.out","w"); fscanf(fin,"%ld",&n);//输入行 for(i=1;i<=n;i++) for(j=i+1;j<=n;j++)//输入元素 { fscanf(fin,"%ld",&general[i][j]); general[j][i]=general[i][j];// 复制对称部分 } for(i=1;i<=n;i++) { Qsort(general[i],1,n);//对每行排序 if(general[i][2]>ans) ans=general[i][2]; } fprintf(fout,"1\n"); fprintf(fout,"%ld",ans); system("pause"); return 0; }
最后一个测试数据放在压缩包里了