#296 -- D(转换思路)
来源:互联网 发布:window python开发工具 编辑:程序博客网 时间:2024/05/17 01:21
本题求特殊条件下最大完全图的节点个数。
转化成贪心问题。求不相交子区间的最大值。
#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <queue>#include <cmath>#include <set>using namespace std;typedef long long LL;const int maxn = 201000;int cmax(int& a,int b){if(a<b) a=b;}struct node{ LL x,y; bool operator <(const node& b)const{ return y<b.y; }}a[maxn];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ LL m,w; cin>>m>>w; node te; te.x=max((LL)0,m-w); te.y=m+w; a[i]=te; } sort(a,a+n); int b = -1,cnt=0; for(int i=0;i<n;i++){ if(a[i].x>=b){ b = a[i].y; cnt++; } } printf("%d\n",cnt); return 0;}
0 0
- #296 -- D(转换思路)
- 空间转换思路
- 进度更新&思路转换
- MySQL字符集转换思路
- 思路转换的失败
- CodeForces 589D(思路)
- 转换思路,售前思路大启发
- CSS3 2D转换&3D转换
- CSS3 2D转换 3D转换
- 2D手机Dota游戏设计思路
- HTML5实现3D校园地图思路
- codeforces round# 302(div 2 D)(思路)
- codeforces round#323(div2 D)(思路)
- codeforces 592D(树上的思路题)
- 2016深圳杯D题 思路
- atcoder regular contest D abs 思路
- bfs 思路 hrbust院赛初赛D
- A/D转换
- .net学习第十二天
- 2015-第3周项目2-三角形类2
- 旱冰场造价
- android-将.java文件转换为jar包(八)
- 第二周项目1-旱冰场造价
- #296 -- D(转换思路)
- MYSQL ERROR CODE 错误编号
- .net学习第十三天
- YTU-OJ-编程题AB-侦察员的密码
- extjs4 mvc 动态加载controller
- python-ConfigParser模块【读写配置文件】
- 第二周项目一旱冰场造价
- 设计模式-------代理模式(ProxyPattern)
- 第二周项目三时间类(2)