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 shllhsno1 at 2012-11-08 16:30:02 on Problem 1230
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int t,n,k;
struct walls{
       int s,t,num;
}wall[105];
int cnt[105];
bool cmp(walls a,walls b)
{
     if(a.s == b.s)
         return a.t<b.t;
     return a.s<b.s;
}
int main()
{
    int i,j,sun,ans,a,b;
    bool flag;
    scanf("%d",&t);
    while(t--)
    {
        sun = 0;
        memset(cnt,0,sizeof(cnt));
        scanf("%d%d",&n,&k);
        for(i = 1;i<=n;i++)
        {
           scanf("%d%d%d%d",&a,&wall[i].num,&b,&wall[i].num);
           wall[i].s = a<b?a:b;
           wall[i].t = a>b?a:b;
        }
        sort(wall+1,wall+n+1,cmp);
        for(i = 1;i<=n;i++)
        {

              for(j = wall[i].s;j<=wall[i].t;j++)
                       cnt[j]++;
              flag = false;
              for(j = wall[i].s;j<=wall[i].t;j++)
              {
                    if(cnt[j]>k)
                    {
                        flag = true;
                        break;
                    }
              }
              if(flag)
              {
                      int max = 0;
                      for(int k = 1;k<=i;k++)
                           if(wall[k].s<=j&&wall[k].t>=j)
                           {
                               if(wall[k].t-j>max)
                               {
                                    max = wall[k].t-j;
                                    ans = k;
                               }
                           }
                      for(int k = wall[ans].s;k<=wall[ans].t;k++)
                                cnt[k]--;
                      sun++;
              }
        }
        printf("%d\n",sun);
    }
    system("pause");
    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