Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
有什么要注意的,为什么我老是错? 程序有注解#include <iostream> #include <cmath> #include <vector> using namespace std; struct Planet { int id,x,y,z; }; int N; Planet d[1001]; int cnt[1001][1001]; //Êý¾Ý½á¹¹Òª¸ÃһϠint dis(int i, int j) { return pow(d[i].x-d[j].x,2) + pow(d[i].y-d[j].y,2)+pow(d[i].z-d[j].z,2); } void work() { if(N==1){ cout<<d[1].id<<endl; return; } if(N==2){ if(d[1].id<d[2].id) cout<<d[1].id<<" "<<d[2].id<<endl; else cout<<d[2].id<<" "<<d[1].id<<endl; return; } for(int j=1;j<=N;j++){ //init; cnt[j][j] = 0; } int i=2,p,tmp_dis,tmp_id; int max_num[1001]; int tmp; while(i<=N){ //×ö³öÁ¬½ÓÇé¿ö tmp_dis = 9000000; p=1; while(p<i){ //Ñ°ÕÒ×î½üµÄ save to tmp_id tmp = dis(i,p); if( tmp < tmp_dis){ //ÕÒ tmp_dis = tmp ; tmp_id = p; //ÕâÀï²»ÊÇÕæÕýµÄid ¶øÊÇÊý×éµÄϱê } p++; } cnt[i][tmp_id] = 1; cnt[tmp_id][i] = 1; //²é¿´pµ½1.¡£¡£¡£i-1µÄ¾àÀë int k=1; while(k<i){ if(k!=tmp_id){ cnt[i][k] = cnt[tmp_id][k]+1; //p==k? cnt[k][i] = cnt[i][k]; } k++; } i++; } for(i=1;i<=N;i++) //¸øÿһ¸ö½ÚµãÑ°ÕÒ×îÔ¶µÄcount { for(j=1;j<=N;j++) { if(cnt[i][j] > max_num[i]) max_num[i] = cnt[i][j]; } } int rst1, rst2,tmp_here1=1500; i=1; while(i<=N){ if(max_num[i]<tmp_here1) { rst1 = i; tmp_here1 = max_num[i]; } i++; } i=1; int tmp_here2=1500; while(i<=N) { if(i==rst1){ i++; continue; } if(max_num[i]<tmp_here2) { rst2 = i; tmp_here2 = max_num[i]; } i++; } if(tmp_here1!=tmp_here2) //Ñ°ÕÒµÄ×î´ó¾àÀë²»Ò»Ñù cout<<d[rst1].id<<endl; else //the same { if(d[rst1].id<d[rst2].id) cout<<d[rst1].id<<" "<<d[rst2].id<<endl; else cout<<d[rst2].id<<" "<<d[rst1].id<<endl; } } int main() { // freopen("C:\\ACMData.txt","r",stdin); int p; while(true){ scanf("%d", &N); if(N==0) return 0; p=1; while(p<=N){ scanf("%d%d%d%d",&d[p].id, &d[p].x,&d[p].y,&d[p].z); p++; } work(); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator