vijos p1883

时间:2023-03-09 03:46:14
vijos p1883

题意:

有些东西就如同月光的魔法一般.

Luke是爱着vijos的.
他想为自己心爱的东西画些什么.

就画N个圆吧.
把它们的圆心都固定在x轴上.

圆与圆.
为了爱,两两不能相交.
为了爱,它们可以互相贴在一起.
内切或外切,都是允许的.

vijos的美丽,在于人心.
vijos的孩子们,一定能告诉大家:Luke画的圆究竟把平面分割成了多少块?

月光恬美地洒在大地上.
Luke知道,如果什么都不画,平面就只有一块.多美呢!
Luke知道,只画一个圆,平面就分成了两块.也很美呢!
但Luke还是要多画一些的,因为他真的深爱着vijos呢.

找出 完全包含而又最大的圆
然后按左端点递增,左端点相同则右端点越远越优先排序
每个圆本来只能增加1个平面
会出现更多 是因为一些圆首尾相接把一个大圆割成了两部分
那我们只要找出每个圆的一级祖先就可以判断了
然后求每个圆的一级祖先可以用我在程序中的dfs来求出,正确性应该显然。

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
struct Node
{
int l,r,fa;
int sum;
}c[MAXN];
int now;
bool cmp(Node a,Node b)
{
if(a.l==b.l)
return a.r>b.r;
else return a.l<b.l;
}
void dfs(int R)
{
while(now<=n&&c[now].r<=c[R].r)
{
c[now].fa=R;
now++;
dfs(now-);
}
return;
}
int main()
{
int i,j,k;
while(~scanf("%d",&n))
{
int o,r;
for(i=;i<=n;i++)
{
scanf("%d%d",&o,&r);
c[i].l=o-r;
c[i].r=o+r;
c[i].sum=;
}
sort(c+,c+n+,cmp);
c[].r=;
now=;
dfs();
int ans=n+;
for(i=;i<=n;i++)
{
c[c[i].fa].sum+=c[i].r-c[i].l;
}
for(i=;i<=n;i++)
{
if(c[i].sum==c[i].r-c[i].l) ans++;
}
printf("%d\n",ans);
}
return ;
}