• 2016"百度之星"


    拍照

    思路:先静态,离线树状数组,分别统计每个点向左向右能看到的船的数量。再枚举整个区间求最大值。

    应为人和船都是动态的,假设船往左走,处理每个点看到向左最大船的数量,满足动态条件。就是向左的船一开始在最右边,向右的船一开始在最左边,则两船肯定相向运动到某个地方最佳。

     1 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <iostream>
     6 #include <queue>
     7 #include <stack>
     8 #include <cmath>
     9 #include <set>
    10 #include <utility>
    11 #include <algorithm>
    12 #include <vector>
    13 #include <map>
    14 // #include<malloc.h>
    15 using namespace std;
    16 #define clc(a,b) memset(a,b,sizeof(a))
    17 #define LL long long
    18 void fre() { freopen("in.txt","r",stdin);}
    19 const int inf = 0x3f3f3f3f;
    20 const double eps = 1e-5;
    21 const double pi = acos(-1);
    22 const LL MOD = 1e9+7;
    23 // const LL p = 1e9+7;
    24 // inline int r(){
    25 //     int x=0,f=1;char ch=getchar();
    26 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
    27 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    28 //     return x*f;
    29 // }
    30 
    31 const int N = 100100;
    32 struct  node{
    33    int x,y,z,d;
    34 }a[N];
    35 
    36 
    37 int sum1[N],sum2[N];
    38 int summ[N];
    39 int p[N<<1];
    40 
    41 int main(){
    42     // fre();
    43     int t,n,X,Y,Z,D;
    44     scanf("%d",&t);
    45     int cas;
    46     cas=0;
    47     while(t--){
    48         clc(sum1,0);
    49         clc(sum2,0);
    50         clc(summ,0);
    51        scanf("%d",&n);
    52        int k;
    53        k=0;
    54        for(int i=0;i<n;i++){
    55           scanf("%d%d%d%d",&X,&Y,&Z,&D);
    56           if(X+Z>=Y-Z){
    57              p[++k]=X+Z;
    58              p[++k]=Y-Z;
    59           }
    60           a[i].d=D;
    61           a[i].x=X;
    62           a[i].y=Y;
    63           a[i].z=Z;
    64        }
    65        sort(p+1,p+k+1);
    66        k=unique(p+1,p+k+1)-p-1;
    67        for(int i=0;i<n;i++){
    68           if(a[i].d==-1&&a[i].y-a[i].z<=a[i].x+a[i].z){
    69              sum1[lower_bound(p+1,p+k+1,a[i].y-a[i].z)-p]++;
    70              sum1[lower_bound(p+1,p+k+1,a[i].x+a[i].z)-p+1]--;
    71           }
    72           else if(a[i].d==1&&a[i].y-a[i].z<=a[i].x+a[i].z){
    73              sum2[lower_bound(p+1,p+k+1,a[i].y-a[i].z)-p]++;
    74              sum2[lower_bound(p+1,p+k+1,a[i].x+a[i].z)-p+1]--;
    75           }
    76        }
    77        for(int i=1;i<=k;i++){
    78           sum1[i]+=sum1[i-1];
    79           sum2[i]+=sum2[i-1];
    80        }
    81        for(int i=k;i>=1;i--){
    82           summ[i]=max(summ[i+1],sum1[i]);
    83        }
    84        int ans=0;
    85        for(int i=1;i<=k;i++){
    86           ans=max(ans,sum2[i]+summ[i]);
    87        }
    88        printf("Case #%d:
    %d
    ",++cas,ans);
    89     }
    90     return 0;
    91 }
  • 相关阅读:
    八、springboot 简单优雅的通过docker-compose 构建
    【并发编程】ThreadLocal其实很简单
    计算机网络
    相似度
    不同激活函数的区别
    快速排序+归并排序
    xgboost
    c++面试
    PCA算法和SVD
    各种排序算法的时间复杂度和空间复杂度
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5544130.html
Copyright © 2020-2023  润新知