1273. Tie

Time limit: 1.0 second
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
Difficulty: 478
 
题意:两排点,两两连边,问最多多少不相交。
分析:比较裸Dp,或者最长上升子序列
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
typedef pair<int, int> II;
int n;
II Data[N];
int Arr[N], Dp[N]; inline void Input()
{
scanf("%d", &n);
For(i, , n) scanf("%d%d", &Data[i].ft, &Data[i].sd);
} inline void Solve()
{
sort(Data + , Data + + n);
For(i, , n) Arr[i] = Data[i].sd;
For(i, , n)
{
Dp[i] = ;
For(j, , i - )
if(Arr[j] < Arr[i])
Dp[i] = max(Dp[i], Dp[j] + );
} int Ans = ;
For(i, , n) Ans = max(Ans, Dp[i]);
printf("%d\n", n - Ans);
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("I");
#endif
Input();
Solve();
return ;
}

ural 1273. Tie的更多相关文章

  1. Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)

    1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...

  2. URAL 1779 F - The Great Team 构造

    F - The Great TeamTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  3. URAL 1776 C - Anniversary Firework DP

    C - Anniversary FireworkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  4. URAL 1741 Communication Fiend

    URAL 1741 思路: dp 状态:dp[i][1]表示到第i个版本为正版的最少流量花费 dp[i][0]表示到第i个版本为盗版的最少流量花费 初始状态:dp[1][0]=dp[0][0]=0 目 ...

  5. URAL 1501 Sense of Beauty

    URAL 1501 思路: dp+记忆化搜索 状态:dp[i][j]表示选取第一堆前i个和第二堆前j的状态:0:0多1个              1:0和1相等                2:1 ...

  6. URAL 1029 Ministry

    URAL 1029 思路: dp+记录路径 状态:dp[i][j]表示到(i,j)这个位置为止的最少花费 初始状态:dp[1][i]=a[1][i](1<=i<=m) 状态转移:dp[i] ...

  7. URAL 1658 Sum of Digits

    URAL 1658 思路: dp+记录路径 状态:dp[i][j]表示s1为i,s2为j的最小位数 初始状态:dp[0][0]=0 状态转移:dp[i][j]=min(dp[i-k][j-k*k]+1 ...

  8. URAL 1303 Minimal Coverage

    URAL 1303 思路: dp+贪心,然后记录路径 mx[i]表示从i开始最大可以到的位置 sufmx[i]表从1-i的某个位置开始最大可以到达的位置 比普通的贪心效率要高很多 代码: #inclu ...

  9. URAL 1183 Brackets Sequence

    URAL 1183 思路:区间dp,打印路径,详见http://www.cnblogs.com/widsom/p/8321670.html 代码: #include<iostream> # ...

随机推荐

  1. unity3d web.config设置

    原地址:http://www.cnblogs.com/88999660/archive/2013/03/22/2976105.html <?xml version="1.0" ...

  2. lvs之ip-tun(ip隧道)技术的学习与实践

    1.配置测试环境 修改IP windows 200.168.10.4 lvs server  ip:200.168.10.1 因为IP隧道模式只需要一个网卡  所以就停掉其他网卡 web server ...

  3. SIFT+HOG+鲁棒统计+RANSAC

    今天的计算机视觉课老师讲了不少内容,不过都是大概讲了下,我先记录下,细讲等以后再补充. SIFT特征: 尺度不变性:用不同参数的高斯函数作用于图像(相当于对图像进行模糊,得到不同尺度的图像),用得到的 ...

  4. ROS2.9.27架设网吧软路由实战篇之端口映射与回流

    转载:http://blog.csdn.net/zm2714/article/details/7924280 上一篇:ROS2.9.27架设网吧软路由实战篇之连通网络,主要讲述了网吧架设软路由ROS2 ...

  5. Having与Where的区别

    where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,where条件中不能包含聚组函数,使用where条件过滤出特定的行. having 子句的作用是筛 ...

  6. Firefox上Web开发工具库一览

    Firefox的目标之一就是尽可能地使web开发者的生活更简单高效,并通过提供工具和具有很强扩展性的浏览器使人们创造出神奇的东西.使web开发者使用Firefox的时候,浏览器可以提供大量开发工具和选 ...

  7. DropDownList1

    循环绑定数据到DropDownList1 foreach (SPList ls in web.Lists) { LIColl.Add(ls.Title);//将数据保存list中 } dwlist.D ...

  8. Django之admin界面恢复及添加数据模型

    引自:http://fl0wjacky.github.io/jekyll_demo/2014/07/14/Django-admin.html Django之admin界面恢复及添加数据模型 Djang ...

  9. com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。

    org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro ...

  10. python下的MySQLdb使用

    下载安装MySQLdb <1>linux版本 http://sourceforge.net/projects/mysql-python/ 下载,在安装是要先安装setuptools,然后在 ...