E - Domino Principle

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put ndominoes 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. The i-th domino has the coordinate xi and the height hi. 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 coordinate x and height h 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 follow n lines containing two integers xi and hi( - 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 the i-th domino to the right (including the domino itself).

Sample Input

Input
4
16 5
20 5
10 10
18 2
Output
3 1 4 1 
Input
4
0 10
1 5
9 10
15 10
Output
4 1 2 1 

很久没写博客了。这是一道dp题。
先排序,在从后往前更新,每次计算第i个卡米诺骨牌的能压倒的数量的时候先考虑是否能压倒下一个骨牌,如果能,加上这个骨牌能压倒的骨牌数,在考虑下一个骨牌的压不倒的第一个骨牌,看这个骨牌能否被要求的骨牌压倒,如果能,加上这个骨牌能压倒的骨牌数,在依次往后推。。。
//#include <iostream>
//#include<algorithm>
//using namespace std;
//
//struct dom
//{
// int x,h,num,id;
//}d[100010];
//
//int cmp1(const dom d1,const dom d2)
//{
// if(d1.x<d2.x)
// return 1;
// else
// return 0;
//}
//int cmp2(const dom d1,const dom d2)
//{
// if(d1.id<d2.id)
// return 1;
// else
// return 0;
//}
//int main()
//{
// int n,i;
// cin>>n;
// for(i=0;i<n;i++)
// {
// cin>>d[i].x>>d[i].h;
// d[i].id=i;
// d[i].num=1;
// }
// sort(d,d+n,cmp1);
// int cnt=0,bg=0;
// for(i=0;i<n-1;i++)
// {
// int tmp=d[i].h;
// for(int j=i+1;j<n;j++)
// {
// if(j>i+1)
// tmp=max(tmp-(d[j-1].x-d[j-2].x),d[j-1].h);
// if(tmp>d[j].x-d[j-1].x)
// {
// d[i].num++;
// }
// else
// {
// int t=d[i].num;
// for(int k=i+1;k<j;k++)
// {
// d[k].num=--t;
// }
// i=j-1;
// break;
// }
// }
// }
// sort(d,d+n,cmp2);
// for(i=0;i<n;i++)
// cout<<d[i].num<<' ';
// cout<<endl;
// return 0;
//} #include <iostream>
#include<algorithm>
using namespace std; struct dom
{
int x,h,num,id;
}d[];
int ans[]; int cmp1(const dom d1,const dom d2)
{
if(d1.x<d2.x)
return ;
else
return ;
} int main()
{
int n,i;
cin>>n;
for(i=;i<n;i++)
ans[i]=;
for(i=;i<n;i++)
{
cin>>d[i].x>>d[i].h;
d[i].id=i;
d[i].num=;
}
sort(d,d+n,cmp1);
for(i=n-;i>=;i--)
{
int j=i+;
while(j!=n&&d[j].x<d[i].x+d[i].h)
{
d[i].num+=d[j].num;
j=d[j].num+j;
}
ans[d[i].id]=d[i].num;
}
for(i=;i<n;i++)
cout<<ans[i]<<' ';
cout<<endl;
return ;
}

CodeForces 56E-Domino Principle的更多相关文章

  1. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

  2. codeforces A. Domino 解题报告

    题目链接:http://codeforces.com/problemset/problem/353/A 题目意思:通俗地说,就是当上下两半的数的总和不完全是偶数时,通过上下调换某些骨牌来使这两半的数和 ...

  3. codeforces 1269D. Domino for Young (二分图证明/结论题)

    链接:https://codeforces.com/contest/1269/problem/D 题意:给一个不规则的网格,在上面放置多米诺骨牌,多米诺骨牌长度要么是1x2,要么是2x1大小,问最多放 ...

  4. 【CF56E】Domino Principle(线性扫描,伪DP)

    每块多米诺骨牌所在的位置设为x,每块多米诺骨牌高度为h.如果将x位置上的多米诺骨牌向右翻到,它就可以影响[x+1, x+h-1]范围内的所有多米诺骨牌,让他们也翻到,同时这些被翻到的多米诺骨牌还能影响 ...

  5. Codeforces Good Bye 2015 C. New Year and Domino 前缀和

    C. New Year and Domino 题目连接: http://www.codeforces.com/contest/611/problem/C Description They say &q ...

  6. Codeforces 500 E. New Year Domino

    \(>Codeforces \space 500 E. New Year Domino<\) 题目大意 : 数轴上有序排列着 \(n\) 块多米诺骨牌, 第 \(i\) 块骨牌坐标为 \( ...

  7. Codeforces Round #609 (Div. 2) D. Domino for Young

    链接: https://codeforces.com/contest/1269/problem/D 题意: You are given a Young diagram. Given diagram i ...

  8. Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)

    链接: https://codeforces.com/contest/1230/problem/C 题意: Anadi has a set of dominoes. Every domino has ...

  9. Codeforces 238 div2 B. Domino Effect

    题目链接:http://codeforces.com/contest/405/problem/B 解题报告:一排n个的多米诺骨牌,规定,若从一边推的话多米诺骨牌会一直倒,但是如果从两个方向同时往中间推 ...

随机推荐

  1. IDE显示无法打开源文件时解决方案

      解决方法:加上具体地址信息将 #include <qwidgetresizehandler_p.h> 改为 #include <C:\Users\INnoVation\Deskt ...

  2. 联系 管理 Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(三)

    hibernate注解实体类示例 package cn.bdqn.smvc.entity; import java.io.Serializable; import javax.persistence. ...

  3. HDUOJ-------2493Timer(数学 2008北京现场赛H题)

    Timer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  4. URL链接中文参数乱码的若干处理方法

    JAVA 中URL链接中文参数乱码的若干处理方法,现在整理收录如下: 方法一: (1) JS中,在URL参数中确保用UTF-8编码,用js函数encodeURI()编码,例如 url:"xx ...

  5. 一份C++线程池的代码,非常实用

    #ifndef _ThreadPool_H_ #define _ThreadPool_H_ #pragma warning(disable: 4530) #pragma warning(disable ...

  6. struts2视频学习笔记 09-10(struts2处理流程,指定多个struts配置文件)

    课时9 Struts2的处理流程 StrutsPrepareAndExecuteFilter是Struts 2框架的核心控制器,它负责拦截由<url-pattern>/*</url- ...

  7. js——常见的小方法

    1.随机得到是六位数,可以当做“密码”来使用: Math.random().toString().substr(2, 6):

  8. WPF RichTextBox读取存储文本的方法和常用属性

    1. 取得已被选中的内容: (1)使用 RichTextBox.Document.Selection属性(2)访问RichTextBox.Document.Blocks属性的“blocks”中的Tex ...

  9. BZOJ4000 [TJOI2015]棋盘

    首先是状态压缩DP... 然后我们发现转移都是一样的...可以矩阵优化... 于是做完啦QAQQQ 题目读不懂?恩多读几遍就读懂了,诶诶诶!别打我呀! /*********************** ...

  10. 从客户端中检测到有潜在危险的Request.Form值的解决方法

    描述:从客户端中检测到有潜在危险的Request.Form值的解决方法asp.net 2.0 通常解决办法将.aspx文件中的page项添加ValidateRequest="false&qu ...