首页 > 其他 > 详细

Gym 100820-G

时间:2020-07-13 12:42:16      阅读:58      评论:0      收藏:0      [点我收藏+]

题目:https://codeforces.com/gym/100820/problem/G

该题目可以通过十分巧妙的方法转换成nlogn求最长不下降子序列。

#include<iostream>
#include<algorithm>
using namespace std;
struct point {
    long long x , y ;
    bool operator < (point &a){
        return x < a.x ;
    }
}a[110000];
long long n , r , w , h , x , y , t ;
long long ans[110000] ; 
int main(){
    cin>>n>>r>>w>>h;
    for(int i = 1 ; i <= n ; i ++ ){
        cin>>x>>y;
        a[i].x = ( x * r + y ) ; 
        a[i].y = ( ( w - x ) * r + y ) ;
    }
    sort( a + 1 , a + n + 1 );
    for( int i = 1 ; i <= n ; i ++ ){
        if( a[i].y >= ans[t] ) ans[++t] = a[i].y ;
        else{
            int p = lower_bound( ans + 1 , ans + t + 1 , a[i].y ) - ans ;
            ans[p] = a[i].y ; 
        }
    }
    cout<<t<<endl;
    return 0 ;
}

这里将输入的x,y坐标转换了。技术分享图片

具体怎么做,这个题解讲的很好。我也是看了该题解才发现可以这么巧妙的转化。

 

Gym 100820-G

原文:https://www.cnblogs.com/xcsj/p/13292303.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!