1273. Tie
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
The subway constructors are not angels. The work under the ground and… Well, they are not angels. And where have you seen angels? It is all in a lifetime! Show me first somebody who has never… and then… all of us are people. And Vasya and me, too. May be we’ve overdrunked ourselves. But a little. And the ties lie crookedly… At that time they seemed to lie straight. No, we can’t say that it must be so — criss-cross, but not all of them criss-cross! Some of the ties lie almost properly… Crookedly you say? And I’d say normally… After the yesterday’s party? May be, may be… The ties that lie criss-cross we’ll take away and it’ll be OK, the train will pass on term, not by this New Year but by the next one. There’s not much to disjoint. We’ll pull out this tie and may be that one. Next to nothing! One, two, three…
Rails are two parallel straight lines that are for the users’ accommodation parallel to the Y axis and have the coordinates X=0 and X=1. The “pell-mell” ties are arbitrary segments with the vertices on the rails in the integer points of the coordinate scale. At the first elimination of defects step you are to remove several ties that would disappear all the crossings. And, of course, after the yesterday’s party the less you work the better, so you are to remove the minimal possible number of ties.
Input
The first line contains integer
K (0 ≤
K ≤ 100) — the number of laid ties. Then there are
Klines, each of them contains two integers
Y1 and
Y2 that describe the location of the next in turn tie — the tie described by the pair
Y1 and
Y2 connects the points (0,
Y1) и (1,
Y2). The absolute values of the numbers
Y1 and
Y2 don’t exceed 1000. There are no identical among the numbers
Y1 and among the numbers
Y2.
Output
the minimal number of ties that are to be removed in order to eliminate crossings.
Sample
input | output |
---|---|
3 0 1 3 0 1 2 | 1 |
Problem Author: Magaz Asanov (prepared Leonid Volkov)
Problem Source: Ural State University championship, October 25, 2003
Problem Source: Ural State University championship, October 25, 2003
Tags: none
hide tags for unsolved problems
Difficulty: 478
题意:两排点,两两连边,问最多多少不相交。
分析:比较裸Dp,或者最长上升子序列
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define For(i, s, t) for(int i = (s); i <= (t); i++) 21 #define Ford(i, s, t) for(int i = (s); i >= (t); i--) 22 #define Rep(i, t) for(int i = (0); i < (t); i++) 23 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--) 24 #define rep(i, x, t) for(int i = (x); i < (t); i++) 25 #define MIT (2147483647) 26 #define INF (1000000001) 27 #define MLL (1000000000000000001LL) 28 #define sz(x) ((int) (x).size()) 29 #define clr(x, y) memset(x, y, sizeof(x)) 30 #define puf push_front 31 #define pub push_back 32 #define pof pop_front 33 #define pob pop_back 34 #define ft first 35 #define sd second 36 #define mk make_pair 37 inline void SetIO(string Name) 38 { 39 string Input = Name+".in", 40 Output = Name+".out"; 41 freopen(Input.c_str(), "r", stdin), 42 freopen(Output.c_str(), "w", stdout); 43 } 44 45 46 inline int Getint() 47 { 48 int Ret = 0; 49 char Ch = ' '; 50 bool Flag = 0; 51 while(!(Ch >= '0' && Ch <= '9')) 52 { 53 if(Ch == '-') Flag ^= 1; 54 Ch = getchar(); 55 } 56 while(Ch >= '0' && Ch <= '9') 57 { 58 Ret = Ret * 10 + Ch - '0'; 59 Ch = getchar(); 60 } 61 return Flag ? -Ret : Ret; 62 } 63 64 const int N = 110; 65 typedef pair<int, int> II; 66 int n; 67 II Data[N]; 68 int Arr[N], Dp[N]; 69 70 inline void Input() 71 { 72 scanf("%d", &n); 73 For(i, 1, n) scanf("%d%d", &Data[i].ft, &Data[i].sd); 74 } 75 76 inline void Solve() 77 { 78 sort(Data + 1, Data + 1 + n); 79 For(i, 1, n) Arr[i] = Data[i].sd; 80 For(i, 1, n) 81 { 82 Dp[i] = 1; 83 For(j, 1, i - 1) 84 if(Arr[j] < Arr[i]) 85 Dp[i] = max(Dp[i], Dp[j] + 1); 86 } 87 88 int Ans = 0; 89 For(i, 1, n) Ans = max(Ans, Dp[i]); 90 printf("%d\n", n - Ans); 91 } 92 93 int main() 94 { 95 #ifndef ONLINE_JUDGE 96 SetIO("I"); 97 #endif 98 Input(); 99 Solve(); 100 return 0; 101 }