http://acm.hdu.edu.cn/showproblem.php?pid=1875
我只想问这样为什么一直 wrong ,求各路大神指教!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int c,k,cou;
double shortest;
struct P{
int x;
int y;
}point[110];
bool visit[110];
struct Graph{
int la,lb;
double jl;
}G[5050];
double hpy(P a,P b){
return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
int cmp(Graph a,Graph b){
return a.jl<b.jl;
}
void kruskal(){
sort(G,G+k,cmp);
int i;
memset(visit,0,sizeof(visit));
shortest=0; cou = 0;
for(i=0;i<k;++i){
int p,q;
p=G[i].la,q=G[i].lb;
if(!visit[p]||!visit[q]){
shortest+=G[i].jl;
visit[p]=1;
visit[q]=1;
cou++;
}
}
// printf(" %d %.1lf\n",cou,shortest);
}
int main(){
int t,i,j;
scanf("%d",&t);
while(t--){
scanf("%d",&c);
for(i=1;i<=c;++i)
scanf("%d%d",&point[i].x,&point[i].y);
k=0; double u;
for(i=1;i<c;++i){
for(j=i+1;j<=c;++j){
u=hpy(point[i],point[j]);
//printf("------%.2lf\n",u);
//if((u-10)>=1e-7&&(1000-u)>=1e-7)
if(u>=10.000000&&u<=1000.000001){
G[k].jl=hpy(point[i],point[j]);
G[k].la=i,G[k].lb=j;
k++;
//printf("%d,%d ,%.2lf\n",G[k].la,G[k].lb,G[k].jl);
}
}
}
kruskal();
if(cou!=(c-1))
printf("oh!\n");
else
printf("%.1lf\n",shortest*100);
}
return 0;
}
我只想问这样为什么一直 wrong ,求各路大神指教!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int c,k,cou;
double shortest;
struct P{
int x;
int y;
}point[110];
bool visit[110];
struct Graph{
int la,lb;
double jl;
}G[5050];
double hpy(P a,P b){
return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
int cmp(Graph a,Graph b){
return a.jl<b.jl;
}
void kruskal(){
sort(G,G+k,cmp);
int i;
memset(visit,0,sizeof(visit));
shortest=0; cou = 0;
for(i=0;i<k;++i){
int p,q;
p=G[i].la,q=G[i].lb;
if(!visit[p]||!visit[q]){
shortest+=G[i].jl;
visit[p]=1;
visit[q]=1;
cou++;
}
}
// printf(" %d %.1lf\n",cou,shortest);
}
int main(){
int t,i,j;
scanf("%d",&t);
while(t--){
scanf("%d",&c);
for(i=1;i<=c;++i)
scanf("%d%d",&point[i].x,&point[i].y);
k=0; double u;
for(i=1;i<c;++i){
for(j=i+1;j<=c;++j){
u=hpy(point[i],point[j]);
//printf("------%.2lf\n",u);
//if((u-10)>=1e-7&&(1000-u)>=1e-7)
if(u>=10.000000&&u<=1000.000001){
G[k].jl=hpy(point[i],point[j]);
G[k].la=i,G[k].lb=j;
k++;
//printf("%d,%d ,%.2lf\n",G[k].la,G[k].lb,G[k].jl);
}
}
}
kruskal();
if(cou!=(c-1))
printf("oh!\n");
else
printf("%.1lf\n",shortest*100);
}
return 0;
}