POJ 2437 贪心+priority_queue
2024-08-31 17:28:46
题意:
思路:
贪心 能不覆盖的就不盖
写得很乱 左闭右开的 temp
//By SiriusRen
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,l,temp,ans;
struct Node{int from,to;}node[10050];
priority_queue<Node>pq;
bool operator < (Node a,Node b){
return a.from>b.from;
}
int main(){
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++){
scanf("%d%d",&node[i].from,&node[i].to),node[i].to--;
pq.push(node[i]);
}
while(!pq.empty()){
Node t=pq.top();pq.pop();
if(temp<=t.from){
int rec=(t.to-t.from+1)/l;
ans+=rec;
temp=t.from+l*rec;
if(temp<=t.to)ans++,temp+=l;
}
else if(temp>t.to)
{
continue;
}
else{
int rec=(t.to-temp+1)/l;
ans+=rec;temp+=l*rec;
if(temp<=t.to)ans++,temp+=l;
}
}
printf("%d\n",ans);
}
最新文章
- iOS--知识综合应用成就时髦小功能点
- 关于refs/for/ 和refs/heads/
- JS文件加载:比较async和DOM Script
- 14---Net基础加强
- ERROR 1442 (HY000):because it is already used by statement which invoked this stored function/tr
- Servlet &; JSP - Form-based Authentication
- Linux中_ALIGN宏背后的原理——内存对齐
- Python 学习开发笔记之IO操作
- PullToRefreshListView调用onRefreshComplete方法 无法取消刷新的bug
- 安卓handler.post问题
- idea maven 无法加载已经安装的模块
- android解决内存溢出的问题(没有从根本上解决)
- &#39;nmake&#39; 不是内部或外部命令,VCVARS32.BAT路径问题
- 《Python编程从入门到实践》_第五章_if语句
- C++ Primer 笔记——函数
- ResourceBundle与Properties读取配置文件
- 如何优雅地等待所有的goroutine退出
- python-opencv boundingRect使用注意
- 【转载】浅谈JavaScript,let和var定义变量的区别
- UOJ 347(洛谷4220) 【WC2018】通道——随机化
热门文章
- [HNOI2008]水平可见直线 单调栈
- 洛谷P2197 nim游戏模板
- 【Git 四】一款不错的 Git 客户端
- vue 退出动画无效解决方法
- iostat---监视磁盘CPU相关信息
- HDFS 断点续传,写文件功能
- WEB前端,混合排版,有的宽有的窄,滚动会出现空白处,怎么办。
- IOS &;#39;NSInternalInconsistencyException&;#39;
- Iocomp控件之数字显示【图文】
- Android Design Support Library(一)用TabLayout实现类似网易选项卡动态滑动效果