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 |
为什么WA了呢??帮忙看一下,谢谢!!#include <iostream> #include <fstream> using namespace std; #define INF 1000000 struct point{ int group; int x,y; void print(){ cout<<"point=("<<x<<" "<<y<<" "<<group<<") "; } }; point p[1010]; double dis[1010][1010]; int pn; double getdis(int a,int b){ double distance; if(p[a].group!=p[b].group||p[a].group==p[b].group&&p[a].group==0){ distance=(double)(abs(p[a].x-p[b].x)+abs(p[a].y-p[b].y)); }else{ int tmp=abs(p[a].x-p[b].x)+abs(p[a].y-p[b].y); distance=(double)tmp/4; } // p[a].print();p[b].print(); // cout<<"dis="<<distance; // cout<<endl; return distance; } void main(){ ifstream cin("data.txt"); pn=0; cin>>p[0].x>>p[0].y>>p[1].x>>p[1].y; p[0].group=0;p[1].group=0; pn=2; int x,y,i,j,k; int group=1; while(cin>>x>>y){ if(x==-1&&y==-1){ group++; continue; } p[pn].x=x;p[pn].y=y; p[pn].group=group; pn++; } for(i=0;i<pn;i++){ for(j=0;j<pn;j++){ if(i==j)dis[i][j]=0; else dis[i][j]=INF; } } for(i=0;i<pn;i++){ for(j=i+1;j<pn;j++){ int gap=getdis(i,j); dis[i][j]=gap; dis[j][i]=gap; } } for(k=0;k<pn;k++){ for(i=0;i<pn;i++){ for(j=0;j<pn;j++){ if(dis[i][j]>dis[i][k]+dis[k][j])dis[i][j]=dis[i][k]+dis[k][j]; } } } double time=(double)dis[0][1]/1000*6; int tmpn=(int)time; if(time-tmpn>0.5)cout<<tmpn+1<<endl; else cout<<tmpn<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator