• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594

            PKU 3636 Nested Dolls---貪心

            Posted on 2009-09-09 21:34 Uriel 閱讀(620) 評論(0)  編輯 收藏 引用 所屬分類: POJ貪心
            搞了很久的一題。。。
            這題跟1065一樣,還是兩個月前做的,1065過了,3636一直TLE。。
            原來的方法很惡心的。。要遍歷很多遍知道所有的數(shù)都?xì)w類過,后來改了一下,還是TLE。。
            無奈上網(wǎng)搜解題報告。。http://hi.baidu.com/findthegateopen/blog/item/8d7694127d16b7d8f7039eb1.html
            感嘆下,二分的思想真是神奇啊。。

            貼下三個版本的代碼。。

            /*Problem: 3636  User: Gilhirith 
               Memory: N/A  Time: N/A 
               Language: C++  Result: Time Limit Exceeded
            */
             

            #include
            <stdio.h>
            #include
            <stdlib.h>
            #include
            <string.h>

            struct In{
                
            int L;
                
            int W;
            }
            S[20010];

            int i,x,sum,n,t,flag,y,z,r;

            int cmp(const void *a,const void *b)
            {
                
            struct In *= (In *)a;
                
            struct In *= (In *)b;
                
            if(c->!= d->L) return c->L-d->L;
                
            else return c->- d->W;
            }


            int main()
            {
                scanf(
            "%d",&t);
                
            while(t--)
                
            {
            //        memset(S,0x00,sizeof(S));
                    scanf("%d",&n);
                    x
            =n;
                    
            for(i=0;i<n;i++)
                    
            {
                        scanf(
            "%d %d",&S[i].L,&S[i].W);
                    }

                    sum
            =0;
                    qsort(S,n,
            sizeof(S[0]),cmp); 
                    
            while(x>0)
                    
            {
                        flag
            =0;
                        
            for(i=0;i<n;i++)
                        
            {
                            
            if(S[i].L==0)continue;
                            
            else
                            
            {
                                
            if(flag==0)
                                
            {
                                    sum
            ++;
                                    x
            --;
                                    S[i].L
            =0;
                                    r
            =S[i].W;
                                    z
            =S[i].L;
                                    flag
            =1;
                                    
            continue;
                                }

                                
            else if(flag==1 && r<S[i].W && z<S[i].L)
                                
            {
                                    x
            --;
                                    z
            =S[i].L;
                                    S[i].L
            =0;
                                    r
            =S[i].W;
                                }

                                
            else if(flag==1)
                                
            {
                                    
            continue;
                                }

                            }

                        }

                    }
                    
                    printf(
            "%d\n",sum); 
                }
                        
                
            return 0;
            }


            /*Problem: 3636  User: Gilhirith 
               Memory: N/A  Time: N/A 
               Language: C++  Result: Time Limit Exceeded
            */
             

            #include
            <stdio.h>
            #include
            <stdlib.h>
            #include
            <string.h>
            #include
            <algorithm>
            using namespace std;

            struct In{
                
            int L;
                
            int W;
            }
            S[20010];

            int t,i,j,n,sum,res[20010];

            bool cmp(In a,In b)
            {
                
            if(a.L != b.L) return a.L > b.L;
                
            else return b.W > a.W;
            }


            int main()
            {
                scanf(
            "%d",&t);
                
            while(t--)
                
            {
                    scanf(
            "%d",&n);
                    
            for(i=0;i<n;i++)
                    
            {
                        scanf(
            "%d %d",&S[i].L,&S[i].W);
                        res[i]
            =0;
                    }

                    sum
            =0;
                    sort(S,S
            +n,cmp);
                    
            for(i=1;i<n;i++)
                    
            {
                        
            for(j=0;j<i;j++)
                        
            {
                            
            if(S[i].L<=S[j].L && S[i].W>=S[j].W)
                            
            {
                                
            if(res[j]+1>res[i])res[i]=res[j]+1;
                            }

                        }

                        
            if(sum<res[i])sum=res[i];
                    }
                    
                    printf(
            "%d\n",sum+1); 
                }
                    
            //    system("PAUSE");    
                return 0;
            }




            /*Problem: 3636  User: Gilhirith 
               Memory: 496K  Time: 157MS 
               Language: C++  Result: Accepted
            */
             

            #include
            <stdio.h>
            #include
            <stdlib.h>
            #include
            <string.h>
            #include
            <algorithm>
            using namespace std;

            struct In{
                
            int L;
                
            int W;
            }
            S[20010];

            int t,i,j,n,sum,res[20010];

            bool cmp(In a,In b)
            {
                
            if(a.L != b.L) return a.L < b.L;
                
            else return b.W < a.W;
            }


            int Sov()
            {
                
            int T[20010],len=0,r,l,mid;
                memset(T,
            0,sizeof(T));
                
            for(int i=0;i<n;i++)
                
            {
                    l
            =0;
                    r
            =len;
                    
            while(l<r)
                    
            {
                        mid
            =(l+r)/2;
                        
            if(T[mid]>=S[i].W)l=mid+1;
                        
            else
                            r
            =mid;
                    }

                    
            if(len==l)len++;
                    T[l]
            =S[i].W;
                }

                
            return len;
            }


            int main()
            {
                scanf(
            "%d",&t);
                
            while(t--)
                
            {
                    scanf(
            "%d",&n);
                    
            for(i=0;i<n;i++)
                    
            {
                        scanf(
            "%d %d",&S[i].L,&S[i].W);
                        res[i]
            =0;
                    }

                    sort(S,S
            +n,cmp);
                    printf(
            "%d\n",Sov()); 
                }
                        
                
            return 0;
            }
            国产午夜精品久久久久免费视| 欧美亚洲国产精品久久| 国产精品18久久久久久vr| 色综合久久久久无码专区| 久久久精品免费国产四虎| 午夜精品久久久久久| 久久精品国产亚洲av麻豆小说 | 色妞色综合久久夜夜| 精品综合久久久久久97超人| 久久久久久青草大香综合精品| 色婷婷久久综合中文久久蜜桃av| 久久久久婷婷| 久久精品人人做人人爽电影| 思思久久99热只有频精品66| 国产成人无码精品久久久久免费 | 久久精品www人人爽人人| 人妻精品久久久久中文字幕 | 久久久久久久久久久| 国产亚州精品女人久久久久久| 久久精品中文闷骚内射| 亚洲国产精品一区二区三区久久| 97久久超碰成人精品网站| 99久久精品国产一区二区| 日本精品一区二区久久久| 一级做a爰片久久毛片人呢| 亚洲中文字幕无码久久综合网 | 精品无码久久久久久午夜| 亚洲国产视频久久| 人妻少妇精品久久| 久久精品免费大片国产大片| 亚洲国产精品久久久久久| 久久精品aⅴ无码中文字字幕不卡| 狠狠色综合网站久久久久久久高清| 久久精品国产亚洲欧美| 久久综合久久综合九色| 青青草原1769久久免费播放| 国产麻豆精品久久一二三| 久久精品国产亚洲AV无码娇色 | 久久亚洲精品国产精品| 久久综合亚洲色HEZYO社区| 久久综合久久综合亚洲|