bzoj 1628 && 1683: [Usaco2007 Demo]City skyline(模拟)
来源:互联网 发布:同济大学软件学院地址 编辑:程序博客网 时间:2024/06/04 20:07
1628: [Usaco2007 Demo]City skyline
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 558 Solved: 435
[Submit][Status][Discuss]
Description
Input
第一行给出N,W
第二行到第N+1行:每行给出二个整数x,y,输入的x严格递增,并且第一个x总是1
Output
输出一个整数,表示城市中最少包含的建筑物数量
Sample Input
10 26
1 1
2 2
5 1
6 3
8 1
11 0
15 2
17 3
20 2
22 1
Sample Output
6
x因为输入保证递增,所以毫无意义
这样维护一个优先队列(用栈更好),每输入一个y,就将>=y的全部弹出,每弹出一个ans++,然后y进队列
最后记得要多算一个y=0!
#include<stdio.h>#include<queue>using namespace std;priority_queue<int> q;int main(void){int n, w, i, x, ans = 0;scanf("%d%d", &n, &w);for(i=1;i<=n;i++){scanf("%*d%d", &x);while(q.empty()==0 && q.top()>x){ans++;q.pop();}if(q.empty() || q.top()<x)q.push(x);}while(q.empty()==0){if(q.top()!=0)ans++;q.pop();}printf("%d\n", ans);return 0;}
阅读全文
1 0
- bzoj 1628 && 1683: [Usaco2007 Demo]City skyline(模拟)
- BZOJ 1628: [Usaco2007 Demo]City skyline
- 贪心-BZOJ-1628-[Usaco2007 Demo]City skyline
- [bzoj] 1628: [Usaco2007 Demo]City skyline
- BZOJ 1628: [Usaco2007 Demo]City skyline
- 1628: [Usaco2007 Demo]City skyline
- 【BZOJ】1628 [Usaco2007 Demo]City skyline 单调栈
- bzoj 1628: [Usaco2007 Demo]City skyline 单调队列
- [单调栈] BZOJ 1113 [Poi2008]海报PLA & BZOJ 1628 [Usaco2007 Demo]City skyline
- bzoj1628 [Usaco2007 Demo]City skyline
- 【BZOJ1628】【USACO2007 Demo】City Skyline
- bzoj1628【Usaco2007 Demo】City skyline
- bzoj1628: [Usaco2007 Demo]City skyline(单调队列)
- [BZOJ1628]=[BZOJ1683][Usaco2007 Demo]City skyline
- bzoj 1683: [Usaco2005 Nov]City skyline 城市地平线
- City Skyline --(单调队列)
- City Skyline(单调队列)
- BZOJ 1683: [Usaco2005 Nov]City skyline 城市地平线 还是单调栈。。。
- JVM
- linode WordPress Permalink .htaccess 404 httpd.conf
- 链式队列
- 转移控制
- 查看JDK动态代理生成的类的内容
- bzoj 1628 && 1683: [Usaco2007 Demo]City skyline(模拟)
- linux学习笔记-定时器的设计与实现(shell)
- POJ-2255
- 数据库(一)
- c#中导入excel至sql server时出现“外部表不是预期格式”
- 【安全牛学习笔记】基本工具-NETCAT(传输文件/目录、流媒体服务、端口扫描、远程克隆硬盘)
- csdn如何转载别人的文章
- 关于sql查询/删除重复记录的事
- java对象序列化,RMI