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

谁能帮我看看那错了吗?又看了一遍,还是觉得没问题,从比赛一直郁闷到现在.

Posted by Tju_Rocket at 2006-08-08 09:28:56 on Problem 2938
#include <stdio.h>
#include <string.h>
char time[20];
char phone[20];
struct Call
{
   int m;
   int d;
   int h;
   int s;
   int sign;
}arr[1010];
int dp[1010];
int cmp(int i,int j)
{
   if(arr[i].m<arr[j].m) return -1;
   if(arr[i].m>arr[j].m) return 1;
   if(arr[i].d<arr[j].d) return -1;
   if(arr[i].d>arr[j].d) return 1;
   if(arr[i].h<arr[j].h) return -1;
   if(arr[i].h>arr[j].h) return 1;
   if(arr[i].s<arr[j].s) return -1;
   if(arr[i].s>arr[j].s) return 1;
   return 0;
}
int main()
{
   int n,t,p,f,i,j,k,min;
   char chr;
   while(scanf("%d",&n)&&n)
   {
      for(i=1;i<=n;i++)
      {
         scanf("%s %s %c",time,phone,&chr);
         sscanf(time,"%d:%d:%d:%d",&arr[i].m,&arr[i].d,&arr[i].h,&arr[i].s);
         if(chr=='+') arr[i].sign=1;
         else arr[i].sign=0; 
      }
      arr[0].m=arr[0].d=arr[0].m=arr[0].s=-1;
      arr[0].sign=0;
      memset(dp,-1,sizeof(dp));
      dp[0]=0;
      for(i=1;i<=n;i++)
      {
         f=0;
         for(j=i-1;j>=0;j--) 
         {
            t=cmp(j+1,j);
            if(t==0||t==-1) break;
            if(dp[i]==-1||dp[j]+1<dp[i]) dp[i]=dp[j]+1;
            if(arr[j].sign==1)
            {
               f=1;
               break;
            }
         }
         for(k=j;k>=0&&!f;k--)
         {
            t=cmp(i,k);
            p=cmp(k,k+1);
            if(t==1||(k!=j&&p!=-1)) break;
            if(dp[i]==-1||dp[k]+1<dp[i]) dp[i]=dp[k]+1;
            if(arr[k].sign==1) break;
         }
      }
      min=dp[n];
      for(i=n-1;i>=1&&arr[n].sign==0;i--)
      {
         t=cmp(i+1,i);
         if(t==0||t==-1) break;
         if(dp[i]<min) min=dp[i];
         if(arr[i].sign==1) break;
      }
      printf("%d\n",min);
   }
   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