Lis [swust OJ 585] inverted pyramid

Source: Internet
Author: User
Inverted pyramid (0585)Time limit (MS): 3000 memory limit (Kb): 65535 submission: 208 accepted: 48 descriptionswust a scientific expedition to the world-famous ancient egyptian pyramid.
The building of the pyramid has always been an unsolved mystery, and he is called the father of Western history. He believes that the building of the pyramid is human and livestock, it took 20 years to mine natural stones from the Sinai Peninsula and ship them to Egypt. Many people think that they are built by aliens. People found that the meridian lines of the HUF pyramid divide the earth into the east and west hemisphere, and their land area is equal. This "coincidence" is probably the intention of aliens to select the place to build the pyramid. The French chemist David dulis believes that the building of the pyramid is not natural, but artificial pouring.
The swust team members are preparing to study the hypothesis proposed by David dulis. To study this hypothesis, they need to use the inverted pyramid model ". The so-called inverted pyramid model, that is, the pyramid is built up by N-layer manually poured boulder, the length and width of a non-underlying boulder must be less than or equal to the length and width of a megacry.
Now, the team members plan to use only N boards in their hands to simulate this inverted pyramid model. Calculate the maximum height of the inverted pyramid model that the team members can build. The first row of input test data is a positive integer n (n <= 1st), indicating that the team members have a total of N boards.
In the next n rows, there are two numbers in each row: A, B (a, B <= 100000), indicating the length and width of a piece of wood. Output has only one positive integer, which is the height of the inverted pyramid that can be stacked at most. The thickness of all boards is 1. Sample input33 21 12 2 Sample output123 ah, I made a question and found that you have been writing something wrong as a template, what a sad thing,
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define N 100005struct Rect{    int x,y;    bool operator<(const Rect &t)const    {        if(x!=t.x) return x<t.x;        return y<t.y;    }}s[N];int n;int len;int dp[N];int up_bound(int k){    int l=1,r=len+1;    while(l<r)    {        int m=(l+r)/2;        if(dp[m]<=k) l=m+1;        else r=m;    };    return l;}void solve(){    len=1;    dp[1]=s[1].y;    for(int i=2;i<=n;i++)    {        if(s[i].y>=dp[len]) dp[++len]=s[i].y;        else        {            int pos=up_bound(s[i].y);            dp[pos]=s[i].y;        }    }}int main(){    while(scanf("%d",&n)!=EOF)    {        for(int i=1;i<=n;i++)        {            scanf("%d%d",&s[i].x,&s[i].y);        }        sort(s+1,s+n+1);        solve();        printf("%d\n",len);    }    return 0;}

 

Lis [swust OJ 585] inverted pyramid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.