free diy tour

吗的,看错题目了

WA了几十次

挫代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int T,a,b,n,m,i,j,t,k;
    int cases=1;
    int num[1005];
    int ks[1005];
    int map[105][105];
    int sight[1005];
    scanf("%d",&T);
    int stack[100005];
    int len;
    while(T--)
    {
        len=1;
        stack[0]=1;
        int flag=1;
        memset(map,0,sizeof(map));
        scanf("%d",&n);
        for( i=1;i<=n;i++)
        scanf("%d",&num[i]);
        scanf("%d",&m);
        int maxn=(-1)*(0x7fffffff);
        memset(sight,0,sizeof(sight));
        num[n+1]=0;
        for( i=1;i<=m;i++)
        {
            scanf("%d%d",&a,&b);
            if(a>b)
            {
                t=a;
                a=b;
                b=t;
            }
            map[a][b]=1;
            if(a==1)
            {
                sight[b]=1;
            }
        }
        for( i=2;i<=n+1;i++)
        {
            int signmax=(-1)*(0x7fffffff);
            int signx,signy;
            for( j=1;j<i;j++)
            {
                if(map[j][i]==1)
                {
                    if(num[j]>signmax)
                    {
                    signmax=num[j];
                    signx=j;
                    }
                }
            }
                    if(signmax+num[i]>num[i]&&signmax>=0)
                    {
                        num[i]=signmax+num[i];
                        //printf("%d %d\n",i,j);
                        sight[i]=signx;
                    }
        }
        int sign=0;
        for( i=2;i<=n;i++)
        {
            if(maxn<num[i]&&map[i][n+1])
            {
                maxn=num[i];
                sign=i;
            }
        }
        //printf("sign==%d %d\n",sign,sight[sign]);
        for( i=sign;i!=1&&sight[i]!=0;i=sight[i])
        {
            //printf("%d %d %d\n",i,sight[2],sight[3]);
            stack[len++]=i;
        }
        if(maxn<0)
        maxn=0;
        printf("CASE %d#\n",cases++);
        printf("points : %d\n",maxn);
        printf("circuit : 1");
        for( i=len-1;i>=0;i--)
        printf("->%d",stack[i]);
        printf("\n");
        if(T!=0)
       printf("\n");
    }
}



你可能感兴趣的:(free diy tour)