pku3670 Eating Together
http://poj.org/problem?id=3670
DP,最长不降子序列,O(n*logn)解法
#include <stdio.h>
#define N 30030 int n, a[N], dp[N];
const int maxint = (<<)-; int bs(int l ,int r, int x)
{
int m;
while(l < r)
{
m = (l + r)>>;
if(dp[m] <= x)
{
l = m + ;
}
else
{
r = m;
}
}
return l;
} int LIS()
{
int i, j, maxn = ;
dp[] = ;
dp[] = maxint;
for(i=; i<=n; i++)
{
j = bs(, maxn+, a[i]);
dp[j] = a[i];
if(j > maxn)
{
maxn ++;
dp[maxn+] = maxint;
}
}
return maxn;
} int main()
{
int t, i, j;
int r1, r2;
while(~scanf("%d", &n))
{
for(i=; i<=n && scanf("%d", a+i); i++);
r1 = LIS();
for(i=; i<=n/; i++)
{
j = n-i+;
//printf("%d %d\n", i, j);
a[i] ^= a[j], a[j] ^= a[i], a[i] ^= a[j];
}
r2 = LIS();
printf("%d\n", n - (r1>r2? r1: r2));
}
return ;
}
pku3670 Eating Together的更多相关文章
- hdu------(4302)Holedox Eating(树状数组+二分)
Holedox Eating Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Bzoj 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 二分
1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1272 Solve ...
- BZOJ1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 938 Solved ...
- BZOJ 2016: [Usaco2010]Chocolate Eating
题目 2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec Memory Limit: 162 MB Description 贝西从大牛那里收到了 ...
- BZOJ 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐( LIS )
求LIS , 然后用 n 减去即为answer ---------------------------------------------------------------------------- ...
- BZOJ 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 Description 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按F ...
- BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )
因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...
- 2016: [Usaco2010]Chocolate Eating
2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 224 Solved: 87[Su ...
- 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
1609: [Usaco2008 Feb]Eating Together麻烦的聚餐 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1010 Solv ...
随机推荐
- apk反编译(4)Smali代码注入
转自 : http://blog.sina.com.cn/s/blog_5674d18801019i89.html 应用场景 Smali代码注入只能应对函数级别的移植,对于类级别的移植是无能为力的.具 ...
- 加密解密(9)Diffie-Hellman密钥交换协议
过程如下 : 1,小李把KeyX经过加密变化,生成MsgA传给老王. 2,老王得到MsgA,保存在本地. 3,老王把KeyY经过加密变化,生成MsgB传给小李, 4,小李得到MsgB保存在本地, 5, ...
- Android开发之获取系统管理权限,即DevicePolicyManager和DeviceAdminReceiver的使用
参考:http://www.cnblogs.com/androidez/archive/2013/02/17/2915020.html 1.创建AdminReceiver,继承DeviceAdminR ...
- 启动PL/SQL Developer 报字符编码不一致错误 Database character set (AL32UTF8) and Client character set (ZHS16GBK) are different. Character set conversion may cause unexpected results. Note: you can set the client
今天写hibernate时候遇到一些异常 代码: 出现异常情况: 出现以上原因是Session关闭 如果不是使用的SessionFactory.getSession()来获得Session. 而是使用 ...
- JPA中的@MappedSuperclass
说明地址:http://docs.oracle.com/javaee/5/api/javax/persistence/MappedSuperclass.html 用来申明一个超类,继承这个类的子类映射 ...
- 宏buf_pool_t
typedef struct buf_pool_struct buf_pool_t; struct buf_pool_struct{ /** @name General fields */ /* @{ ...
- acdream 1684 娜娜梦游仙境系列——莫名其妙的插曲 (gcd)
题意:一开始有一个集合,集合里有n个不同的数,然后Alice(娜娜)与Bob轮流进行操作,每人都可以任意选择两个数a,b,不妨设a>b,不过要求a-b不在集合中,把a-b放入集合(集合元素个数只 ...
- apache开源项目--Synapse
Apache Synapse一个易于使用.轻量级的XML与Web Services管理和集成中间件.可用于搭建SOA和ESB的基础平台.Apache Synapse支持多种标准包括:XML.XSLT. ...
- 数据库语言(二):SQL语法实例整理
连接表达式: select * from student join takes on student.ID = takes.ID; 通过on后面的谓词作为连接条件,相同的属性可以出现两次,也就是等价于 ...
- <一>面向对象分析之面向对象和面向过程
面向对象 ---->注重的是拆分,组装. ---->封装,继承,多态,复用(只是现象) ---->面向对象变成的目标从来就不是复用.相反,对 ...