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

自己测ac,在这里re。。。。poj的c++真不地道

Posted by sideman at 2010-03-28 01:13:12 on Problem 3662 and last updated at 2010-03-28 10:32:07
直接上代码
#include<cstdio>
int N,P,K;
struct edges
{
   struct edges *next;
   int nextvex;
   long l;
   int temp;
   edges(){next=NULL;nextvex=-1;}
   
};
struct vexs
{
   struct edges *next;
   int data;
   vexs(){next=NULL;}
}vex[2000];
int findmin(int used[],int opt[])
{
    int minn,min;
    int i,j;
    min=32767;
    for(i=1;i<=N;i++)
    {
       if((opt[i]<min)&&(used[i]==0)) {minn=i; min=opt[i];}
    }
    return minn;
}
int dij(struct vexs ve[])
{
    int used[2000]={0};
    int i,j,min;
    struct edges *t;
    int opt[1001];
    ////////////init
    for(i=1;i<=N;i++)   opt[i]=32767; opt[1]=0;
    t=ve[1].next;
    while(t!=NULL) {opt[t ->nextvex]=t ->temp; t=t->next;}
    ///////////////////init done!
    for(i=1;i<=N;i++)
    {
       if(used[N]==1) break;
       min=findmin(used,opt);
       used[min]=1;
       t =ve[min].next;
       while(t !=NULL){     if((t ->temp+opt[min])<opt[t ->nextvex])
       {
          opt[t->nextvex]=t->temp+opt[min];
       }t=t->next;
       }
    }
    return opt[N];
}
long erfen(int fir,int las)
{
    int i,j,min=2000000;
    int k;
    struct edges *t;
    while(fir<las)
    {  j=(fir+las)/2;
       for(i=1;i<=N;i++)
       {
          t=vex[i].next;
          while(t!=NULL)
          {
             t->temp=((t->l)>j)?1:0;
             t =t ->next;
          }
       }
       k=dij(vex);
       if(k<=K)
       {
          if(j<min) min=j;
          las=j;
       }
       else
       {
           fir=j+1;
       }
    }
    if(min>=200000) return -1;
    return min;
}
void insert(int s,int e,int l)
{
   struct edges *temp1,*temp2;
   temp1=new edges; temp2=new edges;
   temp1->nextvex=e;
   temp1->l=l;
   temp1->next=vex[s].next;
   vex[s].next=temp1;
   ///
   temp2->nextvex=s;
   temp2->l=l;
   temp2->next=vex[e].next;
   vex[e].next=temp2;
}
int main()
{
    int i,j;
    int s,e,l;
    int maxl,minl;
    ////////// 
    scanf("%d%d%d",&N,&P,&K);
    maxl=0; minl=32767;
    for(i=1;i<=P;i++)
    {
       scanf("%d%d%d",&s,&e,&l);
       insert(s,e,l);
       if(l>maxl) maxl=l;
       if(l<minl) minl=l;
    }
    printf("%ld",erfen(minl-1,maxl+1));
    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