Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:用G++一直WA,C++过的,不知道为什么

Posted by chinhape at 2011-07-31 11:27:03 on Problem 2349
In Reply To:Re:用G++一直WA,C++过的,不知道为什么 Posted by:chinhape at 2011-07-31 11:26:21
> 求代码
#include <iostream>
#include<cmath>
#include<cstdio>
#include<climits>
using namespace std;
struct node
{
    int x,y;
}a[500],dp[500];
void  Prim(int b[],int s,int p)
{
    int i,key[500],v=1;
    for(i=0;i<p;i++)
    {
        key[i]=1;
    }//标记分集合
    int t,m=0,f=0;
    key[0]=0;
    dp[0]=a[0];
    while(f<p-1)
    {
            for(i=0;i<=f;i++)//经过p-1次循环生成最小树
        {
            for(int j=0;j<p;j++)
            {
                t=(a[j].x-dp[i].x)*(a[j].x-dp[i].x)+(a[j].y-dp[i].y)*(a[j].y-dp[i].y);
            // cout<<t<<endl;
                if(t<b[m]&&key[j]==1)
                {
                    b[m]=t;
                    v=j;
                }//end if 判断
            }//end for
            //cout<<m<<endl;
            //cout<<b[m]<<endl;
        }//end for
            f++;dp[f]=a[v];
            key[v]=0;  m++;
    }

    int max=0;
    for(int j=0;j<s;j++)//判断第s个max
    {
        max=0;
        for(i=0;i<m-1;i++)
        {
            if(b[i]>max)
                {
                   // cout<<max<<endl;
                    max=b[i];
                    v=i; //cout<<max<<endl;
                }
        }
        b[v]=0;
       //cout<<max<<endl;
    }
   printf("%0.2f\n",sqrt((double)max));
}
int main()
{
    int N,s,p;
    cin>>N;int i;
    while(N--)
    {
        cin>>s>>p;
        for(i=0;i<p;i++)
            cin>>a[i].x>>a[i].y;
        int b[500];
        for(i=0;i<500;i++)
            b[i]=INT_MAX;
        Prim(b,s,p);
    }
   return 0;
}
为什么我测试数据过了还是错的啊~~~~

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator