CodeForces 56E-Find the Path(技巧)
来源:互联网 发布:萧山网络问政 高桥 编辑:程序博客网 时间:2024/06/10 20:41
Description
Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He putn dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. Thei-th domino has the coordinatexi and the heighthi. Now Vasya wants to learn for every domino, how many dominoes will fall if he pushes it to the right. Help him do that.
Consider that a domino falls if it is touched strictly above the base. In other words, the fall of the domino with the initial coordinatex and heighth leads to the fall of all dominoes on the segment[x + 1, x + h - 1].
Input
The first line contains integer n (1 ≤ n ≤ 105) which is the number of dominoes. Then follown lines containing two integers xi andhi ( - 108 ≤ xi ≤ 108, 2 ≤ hi ≤ 108) each, which are the coordinate and height of every domino. No two dominoes stand on one point.
Output
Print n space-separated numbers zi — the number of dominoes that will fall if Vasya pushes thei-th domino to the right (including the domino itself).
Sample Input
416 520 510 1018 2
3 1 4 1
40 101 59 1015 10
4 1 2 1
题意:给出多米诺骨牌所在的x 轴和高h,求出每一个多米诺骨牌向右倒下时能使多少的牌倒下。
思路:使用数组将每一个牌能够使右边的牌倒下的的数目记录下来,在操作的时候要使用一点小技巧才能不T,具体看代码
CODE:
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <string>#include <cstring>#include <queue>#include <stack>#include <vector>#include <set>#include <map>const int inf=0xfffffff;typedef long long ll;using namespace std;const int Max=100005;struct node{ int x,h,d; int sum; int id;}dom[Max];bool cmp(node a,node b){ return a.x<b.x;}bool idd(node a,node b){ return a.id<b.id;}int main(){ //freopen("in.in","r",stdin); int n; while(~scanf("%d",&n)){ for(int i=0;i<n;i++){ scanf("%d%d",&dom[i].x,&dom[i].h); dom[i].id=i; dom[i].d=dom[i].x+dom[i].h; } sort(dom,dom+n,cmp); dom[n-1].sum=1; for(int i=n-2;i>=0;i--){ int t=i+1; dom[i].sum=1; while(dom[i].d>dom[t].x && t<n){ dom[i].sum+=dom[t].sum; t+=dom[t].sum; //不T 的关键~ } } sort(dom,dom+n,idd); printf("%d",dom[0].sum); for(int i=1;i<n;i++) printf(" %d",dom[i].sum); printf("\n"); } return 0;}
- CodeForces 56E-Find the Path(技巧)
- POJ1426 Find The Multiple(E)
- 【Codeforces】Codeforces Round #299 (Div. 1) E. Tavas on the Path 【树链剖分+区间合并】
- Codeforces 416E. President's Path 图论 最短路 处理技巧
- hdu 2290 Find the Path(dij+heap)
- E - Find The Multiple POJ1426 (有点特殊的搜索)
- 暑期第一弹<搜索> E - Find The Multiple(DFS)
- CodeForces 416E President's Path
- Codeforces 416E President's Path
- CodeForces 59E Shortest Path 用边跑最短路
- codeforces 559E Gerald and Path
- codeforces 559E Gerald and Path
- PyCharm使用技巧:Find in Path(全局查找)、Find(当前文件查找)
- codeforces 3-A. Shortest path of the king(暴力)
- Codeforces Round #400 E. The Holmes Children (欧拉)
- codeforces 600 E. Lomsat gelral (dsu on the tree)
- codeforces 208 E. Blood Cousins (dsu on the tree)
- COdeforces 835E The penguin's game (二进制)
- 专为设计师而写的GitHub快速入门教程
- C指针系列之一 指针
- WebRadioGroup.Select
- 线程池、内存池、连接池、对象池
- 又一个被坑的题 读题太不细心了 hdu 1260 简单dp
- CodeForces 56E-Find the Path(技巧)
- 排序算法之堆排序
- 扩展KMP算法 Extend KMP
- Ubuntu Linux下为PHP5安装cURL
- 23-编码实现软件界面与通知
- 建站:域名注册,从国外注册干净的域名,用虚拟信用卡取得最优价格
- UVA - 10790 How Many Points of Intersection?
- sed高级用法
- [编程之美] PSet2.16 求数组中最长的递增子序列