zoukankan      html  css  js  c++  java
  • 天神下凡

    天神下凡

    时间限制: 3 Sec  内存限制: 256 MB

    题目描述

    Czy找到宝藏获得屠龙宝刀和神秘秘籍!现在他要去找经常ntr他的Jmars报仇……

    Czy学会了一招“堕天一击”,他对一个地点发动堕天一击,地面上就会留下一个很大的圆坑。圆坑的周围一圈能量太过庞大,因此无法通过。所以每次czy发动技能都会把地面分割。Jmars拥有好大好大的土地,几十眼都望不到头,所以可以假设土地的大小是无限大。现在czy对他发动了猛烈的攻击,他想知道在泽宇攻击之后他的土地被切成几份了?

    Czy毕竟很虚,因此圆心都在x坐标轴上。另外,保证所有圆两两之间不会相交。


    输入

    输入第一行为整数n,表示czy放了n次堕天一击。

    接下来n行,每行两个整数x[i],r[i]。表示在坐标(x[i] , 0)放了一次堕天一击,半径为r[i]。

    输出

    输出一行,表示地面被分割成几块。

    样例输入

    4
    7 5
    -9 11
    11 9
    0 20

    样例输出

    6

    这道题其实也是暴力搜索,但是在搜索的时候用到了路径压缩的思想,每找到一个圆就把其包含的所有圆递归的找完,这样每个圆就只被枚举了一次;

     1 #include<cmath>
     2 #include<ctime>
     3 #include<queue>
     4 #include<cstdio>
     5 #include<cstdlib>
     6 #include<cstring>
     7 #include<iostream>
     8 #include<algorithm>
     9 using namespace std;
    10 int n;
    11 struct node{
    12     int l,r,ans;
    13 };
    14 node g[300010],p[300010];
    15 bool cmp(const node a,const node b){
    16     if(a.l==b.l) return a.r > b.r;
    17     return a.l<b.l;
    18 }
    19 void find(int x){
    20     if(x==n || g[x+1].l != g[x].l){
    21         g[x].ans=1;
    22         return ;
    23     }
    24     bool ok=1,pd=0;
    25     int t=x+1;
    26     int l=g[x].l;
    27     int mx=g[t].r;
    28     while(t<=n && g[t].r<=g[x].r){
    29         //cout<<l<<"  "<<mx<<"  "<<g[t].r<<endl;
    30         if(g[t].l==l){
    31             if(g[t].ans==0)
    32             find(t);
    33             t++;
    34             continue;
    35         }
    36         else{
    37             if(g[t].l!=mx){
    38                 l=g[t].l;
    39                 //cout<<"t== "<<t<<"  "<<mx<<"  "<<g[t].l<<endl;
    40                 ok=0;
    41                 while(1);
    42             }
    43             else{
    44                 mx=g[t].r;
    45                 l=g[t].l;
    46                 if(mx==g[x].r){
    47                     pd=1;
    48                 }
    49             }
    50         }
    51     }
    52     if(ok && pd) g[x].ans=2;
    53     else g[x].ans=1;
    54 }
    55 int main(){
    56     //freopen("a.in","r",stdin);
    57     //freopen("a.out","w",stdout);
    58     scanf("%d",&n);
    59     int x,y;
    60     for(int i=1;i<=n;i++){
    61         scanf("%d%d",&x,&y);
    62         g[i].l=x-y; g[i].r=x+y; 
    63     }
    64     sort(g+1,g+n+1,cmp);
    65     for(int i=1;i<=n;i++){
    66         if(!g[i].ans){
    67             find(i);
    68         }
    69     }
    70     int sc=1;
    71     //cout<<"n== "<<n<<endl;
    72     for(int i=1;i<=n;i++){
    73         sc+=g[i].ans;
    74     }
    75     cout<<sc<<endl;
    76     return 0;
    77 }
    
    
    
     
  • 相关阅读:
    Windows 8/8.1/10 加载动画WPF实现
    WPF
    NAT类型判断
    Visual Studio插件: SlowCheetah
    EF6连接MySQL若干问题汇总
    javascript 继承
    docker安装宝塔
    协同推荐算法-php实现
    大文件传输解决方案:分片上传 / 下载限速
    WEB 防止CSRF攻击
  • 原文地址:https://www.cnblogs.com/FOXYY/p/7257646.html
Copyright © 2011-2022 走看看