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 diaorun at 2012-04-18 11:49:45 on Problem 3636
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn=20050;
int dp[maxn],n;
struct tnode
{
    int h,w;
}node[maxn];
bool cmp(tnode a,tnode b)
{
    if(a.h==b.h) return a.w<b.w;
    else
    return a.h>b.h;
}
int search(int l,int r,int v)
{
   while(l<r)
   {
     int mid=(l+r)>>1;
     if(dp[mid]<v)l=mid+1;
     else r=mid;
   }
   return l;
}

int  main()
{
  // freopen("in.txt","r",stdin);
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,0,sizeof(dp));
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        scanf("%d%d",&node[i].h,&node[i].w);
        sort(node,node+n,cmp);
        int count=0;
        dp[0]=node[0].w;
         for(int i=1;i<n;i++)
         {
             if(dp[count]<=node[i].w)
             dp[++count]=node[i].w;
             else
             {
                  int tem=search(0,count,node[i].w);
                  dp[tem]=node[i].w;
             }
         }
         cout<<count+1<<endl;

    }
}

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