问题 K: 小奇画画
时间限制: 1 Sec 内存限制: 128 MB提交: 46 解决: 21
[提交] [状态] [讨论版] [命题人:]
题目描述
红莲清泪两行欲吐半点却无
如初是你杳然若绯雾还在水榭畔画楼处
是谁衣白衫如初谁红裳如故
——《忆红莲》
小奇想画几朵红莲,可惜它刚开始学画画,只能从画圆开始。小奇画了n个圆,它们的圆心都在x轴上,且两两不相交(可以相切)。现在小奇想知道,它画的圆把画纸分割成了多少块?(假设画纸无限大)
如初是你杳然若绯雾还在水榭畔画楼处
是谁衣白衫如初谁红裳如故
——《忆红莲》
小奇想画几朵红莲,可惜它刚开始学画画,只能从画圆开始。小奇画了n个圆,它们的圆心都在x轴上,且两两不相交(可以相切)。现在小奇想知道,它画的圆把画纸分割成了多少块?(假设画纸无限大)
输入
第一行包括1个整数n。
接下来n行,每行两个整数x,r,表示小奇画了圆心在(x,0),半径为r的一个圆。
接下来n行,每行两个整数x,r,表示小奇画了圆心在(x,0),半径为r的一个圆。
输出
输出一个整数表示答案。
样例输入
4
7 5
-9 11 11 9
0 20
样例输出
6
提示
对于 100%数据,1<=n<=300000,-10^9<=x<=10^9,1<=r<=10^9。

#include <iostream> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <map> #define range(i,a,b) for(auto i=a;i<=b;++i) #define LL long long #define itrange(i,a,b) for(auto i=a;i!=b;++i) #define rerange(i,a,b) for(auto i=a;i>=b;--i) #define fill(arr,tmp) memset(arr,tmp,sizeof(arr)) using namespace std; int n,ans=1; map<LL,bool>alpha; struct cmp{ bool operator()(pair<LL,LL>a,pair<LL,LL>b){ return a.first<b.first; } }; priority_queue<pair<LL,LL>,vector<pair<LL,LL>>,cmp>que; void init(){ cin>>n; int x,r; range(i,1,n){ cin>>x>>r; que.push(make_pair(x,r)); } } void solve(){ while(!que.empty()){ pair<LL,LL>tmp=que.top(); que.pop(); if(alpha[tmp.first+tmp.second] and alpha[tmp.first-tmp.second])++ans; else alpha[tmp.first+tmp.second]=alpha[tmp.first-tmp.second]=true; ++ans; } cout<<ans<<endl; } int main() { init(); solve(); return 0; }