[INFOR] 18 人口問題
題目連結:https://oj.infor.org/problems/18
h由小到大w由大到小排序,然後對w最LIS,就可以保證得到的是h1<h2、w1<w2了。
h由小到大w由大到小排序,然後對w最LIS,就可以保證得到的是h1<h2、w1<w2了。
#include<bits/stdc++.h> #define F first #define S second #define pi pair<int,int> #define endl '\n' using namespace std; int n; bool ok[10009]; pair<int,int> people[10009]; int main() { cin >> n; cin >> people[0].F >> people[0].S; cout << 1 << endl; int ans = 1; fill(ok,ok+10009,true); for(int i = 1; i < n; i++) { cin >> people[i].F >> people[i].S; for(int j = 0; j < i; j++) { if( (people[i].F > people[j].F && people[i].S >= people[j].S) || (people[i].F >= people[j].F && people[i].S >people[j].S) ) ok[i] = false; if(ok[j]) if( (people[j].F > people[i].F && people[j].S >= people[i].S) || (people[j].F >= people[i].F && people[j].S >people[i].S) ) { ok[j] = false; ans--; } } if(ok[i] == 1) { ans++; } cout << ans << endl; } }
留言
張貼留言