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. ubuntu下安装基本配置

    安装ubuntu更新: sudo apt-get update sudo apt-get upgrade 安装Docky: sudo add-apt-repository ppa:ricotz/doc ...

  2. JAVA String作业——动手动脑以及课后实验性问题

    一:如何解释这样的输出结果?从中你能总结出什么?1.源码 //mao2015.10.20 //==的两个分辨 //对原始数据而言 //对引用类型变量 public class StringPool { ...

  3. 整理的一些模版LCS(连续和非连续)

    对于连续的最大串,我们称之为子串....非连续的称之为公共序列.. 代码: 非连续连续 int LCS(char a[],char b[],char sav[]){ int lena=strlen(a ...

  4. java多线程下如何调用一个共同的内存单元(调用同一个对象)

    /* * 关于线程下共享相同的内存单元(包括代码与数据) * ,并利用这些共享单元来实现数据交换,实时通信与必要的同步操作. * 对于Thread(Runnable target)构造方法创建的线程, ...

  5. 集成 AliPay - 支付宝

    作者感言 前面我已经写了一篇关于WeChat SDK的支付篇, 那我们继续研究接下来的支付SDK, 这次就是国民支付软件支付宝, 下面就让我们来看看怎么集成AliPay SDK.最后:如果你有更好的建 ...

  6. GPOR

    [tengzhenzhen15@lu01 gpor]$ for ((i=0; i<=19; i++)) do ./gpor -S 0.4 X4058_300_gpor/mytask_train. ...

  7. 教你如何做好SEO优化中的前端优化

    网站的速度是很多人都面临的问题,其实许多网站,都没有特意的去优化加载速度,对于一个网站来说,加速不但提高了用户体验(如果一个网站在几秒内没 有打开,大多数用户选择的是关闭而非等待),而且对于SEO的流 ...

  8. easyui 中重复加载两次url

    之前一直在使用easyui中,忽视了官网上的小细节,类似于datagrid.combobox 等组件在使用的时候,它的数据加载方式分为两种: 官网中: ①在html中,比如: <table id ...

  9. DOM系列---基础篇[转]

    DOM (Document Object Model) 即文档对象模型, 针对 HTML 和 XML 文档的 API (应用程序接口) .DOM 描绘了一个层次化的节点树,运行开发人员添加.移除和修改 ...

  10. mySql常用sql

    mysql sql语句大全1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server- ...