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

为什么我的第5个数据和第7个数据错了?

Posted by xijunlee93 at 2012-12-03 19:44:36 on Problem 1062
对了下别人的数据,发现7组数据对了5组,其中两组错了。
分别是
0 5
10000 3 4
2 3000
3 2000
4 2000
5 9000
8000 2 3
3 5000
4 2000
5 7000
5000 4 0
2000 3 1
5 1900
50 2 0
ans:3950
而我的是4000
另外一组答案是105
而我的是104

我用的算法就是DFS,很简单的搜索啊,为什么会有两组数据是错的?
附上源代码:
#include<fstream>
using namespace std;
int m,n,owner[101],t[101][50],v[101][50],ans=21400000;
int abs(int a,int b)
{
    if (a>b)
    return a-b;
    else
    return b-a;
}
int min(int a,int b)
{
    if (a<b)
    return a;
    else return b;
}
int dfs(int num)
{
    int i,temp=2140000;
    for (i=1;i<=t[num][0];i++)
       if (abs(owner[num],owner[t[num][i]])<=m)
       temp=min(temp,dfs(t[num][i])+v[num][i]);
    temp=min(temp,v[num][0]);
    return temp;
}
int main()
{
     ifstream infile;
     ofstream outfile;
     infile.open("data.in",ios::in);
     outfile.open("data.out",ios::out);
     int p,l,x,i,j,temp;
     infile>>m>>n;
     for (i=1;i<=n;i++)
     {
        infile>>p>>l>>x;
        v[i][0]=p;owner[i]=l;
        t[i][0]=x;
        for (j=1;j<=x;j++)
        infile>>t[i][j]>>v[i][j];
     }
     temp=dfs(1);
     ans=min(ans,temp);
     outfile<<ans;
     infile.close();
     outfile.close();
     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