• P1233-木棍加工


     1 #pragma GCC optimize("Ofast")
     2 #include <bits/stdc++.h>
     3 #define maxn 13003
     4 #define _for(i,a,b) for(int i = (a);i < b;i ++)
     5 typedef long long ll;
     6 using namespace std;
     7 
     8 inline ll read()
     9 {
    10     ll ans = 0;
    11     char ch = getchar(), last = ' ';
    12     while(!isdigit(ch)) last = ch, ch = getchar();
    13     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    14     if(last == '-') ans = -ans;
    15     return ans;
    16 }
    17 inline void write(ll x)
    18 {
    19     if(x < 0) x = -x, putchar('-');
    20     if(x >= 10) write(x / 10);
    21     putchar(x % 10 + '0');
    22 }
    23 struct wood
    24 {
    25     int W;
    26     int L;
    27 };
    28 int n;
    29 wood in[5003];
    30 int dp[5003];
    31 int dpend = 1;
    32 bool cmp(wood a,wood b)
    33 {
    34     if(a.L == b.L)
    35         return a.W > b.W;
    36     return a.L > b.L;
    37 }
    38 
    39 int main()
    40 {
    41     n = read();
    42     _for(i,1,n+1)
    43     {
    44         in[i].L = read();
    45         in[i].W = read();
    46     }
    47     sort(in+1,in+n+1,cmp);
    48 
    49     dp[dpend] = in[1].W;
    50     _for(i,2,n+1)
    51     {
    52         if(in[i].W > dp[dpend])
    53             dp[++dpend] = in[i].W;
    54         else
    55         {
    56             int t = lower_bound(dp+1,dp+dpend+1,in[i].W)-dp;
    57             dp[t] = in[i].W;
    58         }
    59     }
    60     write(dpend);
    61     return 0;
    62 }
  • 相关阅读:
    生活重心
    做自己才对,想多只会徒增烦恼
    列下计划,一个个实现吧
    公司搬迁
    限制文件的类型
    总结
    mvc mvp mvvm区别
    sessionStorage
    localStorage点击次数存储
    2016.09.01 html5兼容
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11357092.html
Copyright © 2020-2023  润新知