3359: [Usaco2004 Jan]矩形
3359: [Usaco2004 Jan]矩形
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 8 Solved: 5
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
8 14
16 28
29 12
14 8
Sample Output
HINT
Source
题解:其实很明显有更好的办法的,但是我还是逗比的建立了一个拓扑图(A-->B表示A举行包含在B里面,为了方便,我还弄了个 \( -1 * -1 \) 的矩形作为源点),然后去用spfa求出从源点出发各个点的最长路径,然后求出最大值即可
type
point=^node;
node=record
g,w:longint;
next:point;
end;
var
i,j,k,l,m,n,f,r:longint;
p:point;
a:array[..,..] of longint;
b:array[..] of point;
c,g:array[..] of longint;
d:array[..] of longint;
procedure add(x,y,z:longint);inline;
var p:point;
begin
new(p);p^.g:=y;p^.w:=z;
p^.next:=b[x];b[x]:=p;
end;
procedure swap(var x,y:longint);inline;
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure sort(l,r:longint);inline;
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[(l+r) div ,];y:=a[(l+r) div ,];
repeat
while (a[i,]<x) or ((a[i,]=x) and (a[i,]<y)) do inc(i);
while (a[j,]>x) or ((a[j,]=x) and (a[j,]>y)) do dec(j);
if i<=j then
begin
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
begin
readln(n);
for i:= to n do
begin
readln(a[i,],a[i,]);
if a[i,]>a[i,] then swap(a[i,],a[i,]);
end;
a[n+,]:=-;a[n+,]:=-;n:=n+;
sort(,n);
for i:= to n do b[i]:=nil;
for i:= to n- do
for j:=i+ to n do
if (a[j,]>a[i,]) or ((a[j,]>=a[i,]) and (a[j,]>a[i,])) then
begin
add(i,j,);
end;
f:=;r:=;d[]:=;g[]:=;
fillchar(c,sizeof(c),);
while f<r do
begin
p:=b[d[f]];
while p<>nil do
begin
if (c[d[f]]+p^.w)>c[p^.g] then
begin
c[p^.g]:=p^.w+c[d[f]];
if g[p^.g]= then
begin
g[p^.g]:=;
d[r]:=p^.g;
inc(r);
end;
end;
p:=p^.next;
end;
g[d[f]]:=;
inc(f);
end;
l:=;
for i:= to n do if c[i]>l then l:=c[i];
writeln(l);
end.
3359: [Usaco2004 Jan]矩形的更多相关文章
- BZOJ 3359: [Usaco2004 Jan]矩形( dp )
数据范围这么小..怎么乱搞都可以吧... 先排序一遍然后O(n²) dp --------------------------------------------------------------- ...
- 3360: [Usaco2004 Jan]算二十四
3360: [Usaco2004 Jan]算二十四 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6 Solved: 6[Submit][Statu ...
- 3361: [Usaco2004 Jan]培根距离
3361: [Usaco2004 Jan]培根距离 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 16 Solved: 13[Submit][Sta ...
- BZOJ3356 : [Usaco2004 Jan]禁闭围栏
首先将坐标离散化,考虑从左往右扫描线 碰到插入操作则插入 碰到删除操作的: 当前包含i的矩形数=y1在[1,y2[i]]之间的矩形数-y2在[1,y1[i]-1]之间的矩形数 用两棵树状数组维护即可, ...
- BZOJ3355 : [Usaco2004 Jan]有序奶牛
对于一条边x->y,若去掉之后x不能到达y,那么它是必需的. 首先拓扑排序求出拓扑序,然后按照终点拓扑序为第一关键字,起点拓扑序为第二关键字从小到大加边. 对于每个点,维护一个bitset,表示 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ3355
3355: [Usaco2004 Jan]有序奶牛 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 37 Solved: 19[Submit][Sta ...
- BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘
题目 3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MB Description 农夫 ...
- 3385: [Usaco2004 Nov]Lake Counting 数池塘
3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 22 Solved: 21 ...
随机推荐
- Pomelo的Filter
在pomelo中,filter分为before filter和after filter.在一个请求到达Handler被处理之前,可以经过多个before Filter组成的filter链进行一些前置处 ...
- Spring @Transactional使用的示例
Spring @Transactional使用的示例: 参考: http://blog.csdn.net/seng3018/article/details/6690527 http://blog.si ...
- RocketMQ源码 — 三、 Consumer 接收消息过程
Consumer pull message 订阅 在Consumer启动之前先将自己放到一个本地的集合中,再以后获取消费者的时候会用到,同时会将自己订阅的信息告诉broker 接收消息 consume ...
- 微信扫码下载APP
前段时间开发过程中,要实现一个扫描二维码下载APP的功能,但是苹果系统中,微信不可以直接跳转苹果商店,需要先下载应用宝,显然太麻烦... 这样我们可以做个中间页,用中间页面生成二维码链接,在中间页代码 ...
- Python学习--13 文件I/O
Python内置了读写文件的函数,用法和C是兼容的. 读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘,所以,读写文件就是请求操作系 ...
- 蓝桥网试题 java 入门训练 Fibonacci数列
---------------------------------------------------------------------------------------------------- ...
- Codeforce 712A Memory and Crow
A. Memory and Crow time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- 《JavaScript DOM 编程艺术 》 笔记
一:这本书由几个案列带入知识点,通俗易懂.最大的收获莫过于作者多次提到的逐渐增强和平稳退化. "渐进增强"指的是给所用用户同等的基本使用体验,再根据用户终端的级别给予更高级的用户更 ...
- removeAll
问题:无法移除2个集合中相同元素 方法:移除所包含的其所有元素. 在执行removeAll方法时,会先对集合元素进行比较,如果元素相等才执行移除操作,说到这,相信很多人都已经明白是怎么回事了,因为不相 ...
- 转:微信开发获取地理位置实例(java,非常详细,附工程源码)
微信开发获取地理位置实例(java,非常详细,附工程源码) 在本篇博客之前,博主已经写了4篇关于微信相关文章,其中三篇是本文基础: 1.微信开发之入门教程,该文章详细讲解了企业号体验号免费申请与一 ...