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

这代码想不到什么 数据能WA 勒``` 大牛给点 数据?

Posted by __sunshine at 2009-06-09 20:43:36 on Problem 3687
#include <cstdlib>
#include <iostream>
#include <queue>
using namespace std;
int N,M,rest[201],k;
bool visa[201],visb[201];


struct inte {
       int x;
       friend bool operator <(inte a,inte b){
              return b.x<a.x;
       }
};
priority_queue <inte > map[201];

struct node {
       int a,b;
}res[201];

int cmp(const void *a1,const void *a2){
    node *p1=(node *)a1;
    node *p2=(node *)a2;
    return p1->b-p2->b;
}


bool findit(int a){
     //printf("a=%d\n",a);
     inte to;
     visa[a]=true;
     while(!map[a].empty()){
          to=map[a].top();
          map[a].pop();
          if(visb[to.x])continue;
          if(visa[to.x])return false;
          
          if(findit(to.x)==false)return false;
     }
     rest[k++]=a;
     visb[a]=true;
     return true;
}





int main(int argc, char *argv[])
{
    int T,a,b;
    cin>>T;
    while(T--){
        cin>>N>>M;
        bool ok=true;
        for(int i=0;i<=N;i++)while(!map[i].empty())map[i].pop();
        
        inte t;
        
        for(int i=0;i<M;i++){
                cin>>a>>b;
                t.x=a;
                map[b].push(t);
                if(a==b)ok=false;
        }
        
        if(!ok){
           printf("-1\n");
           continue;
        }
        //printf("ok=%d\n",i);
        memset(visb,false,sizeof(visb));
        k=0;
        for(int i=1;i<=N;i++){
                if(visb[i])continue;
                memset(visa,false,sizeof(visa));
                if(findit(i)==false){
                      ok=false;
                      break;
                }
        }
        if(!ok){
           printf("-1\n");
           continue;
        }
        for(int i=0;i<k;i++){
                res[i].a=i+1;
                res[i].b=rest[i];
        }
        qsort(res,k,sizeof(node),cmp);
        for(int i=0;i<k;i++){
                printf((i==0)?"%d":" %d",res[i].a);
        }
        printf("\n");
    }
        
        
        
                
    //system("PAUSE");
    return EXIT_SUCCESS;
}

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