• BZOJ 3368 约翰看山(扫描)O(N)


    这题,简直丧心病狂了。

    大意是给你一个环上一些覆盖的区间,让你求总覆盖长度。

    非常坑的点是这个区间因为是个环,所以可能逆时针给你,也可能顺时针给你,你特别要注意。那么区分顺时针和逆时针的方法

    就是,题目中的一句关键:每个区间都小于180.根据这个判断就可以。还有一个要注意的地方就是,他可能在一个角度中的不能分度搞你。这题我是彻底服了。把我坑的底朝天。后来管理BZOJ要的数据才明白是怎么回事。。。。太弱弱了。。。。

    Code:

      1 #include <cstdio>
      2 #include <cstring>
      3 #include <cstdlib>
      4 #include <algorithm>
      5 #include <iostream>
      6 
      7 
      8 using namespace std;
      9 
     10 int N;
     11 int pos = 0,Ans = 0,tot = 0;
     12 
     13 struct data{
     14     int flag;
     15     int sum;
     16 }w[50000];
     17 
     18 int q[100000];
     19 int tail = 0;
     20 bool cmp(data a,data b);
     21 int main(){
     22     scanf("%d",&N);
     23     for(int i = 1;i <= N;++ i){
     24         int x1,y1,z1,x2,y2,z2;
     25         scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
     26         if(x1 > x2){//so silly..caocao
     27             if(x1 - x2 >= 180){
     28                 ++ tot;
     29                 w[tot].sum = x1*3600+y1*60+z1;
     30                 w[tot].flag = 1;
     31                 ++ tot;
     32                 w[tot].sum = 360*3600;
     33                 w[tot].flag = 2;
     34                 ++ tot;
     35                 w[tot].sum = 0;
     36                 w[tot].flag = 1;
     37                 ++ tot;
     38                 w[tot].sum = x2*3600+y2*60+z2;
     39                 w[tot].flag = 2;
     40             }
     41             else{
     42                 ++ tot;
     43                 w[tot].sum = x2*3600+y2*60+z2;
     44                 w[tot].flag = 1;
     45                 ++ tot;
     46                 w[tot].sum = x1*3600+y1*60+z1;
     47                 w[tot].flag = 2;
     48             }
     49         }
     50         else if(x2 > x1){
     51             if(x2 - x1 >= 180){
     52                 ++ tot;
     53                 w[tot].sum = x2*3600+y2*60+z2;
     54                 w[tot].flag = 1;
     55                 ++ tot;
     56                 w[tot].sum = 360*3600;
     57                 w[tot].flag = 2;
     58                 ++ tot;
     59                 w[tot].sum = 0;
     60                 w[tot].flag = 1;
     61                 ++ tot;
     62                 w[tot].sum = x1*3600+y1*60+z1;
     63                 w[tot].flag = 2;
     64             }
     65             else{
     66                 ++ tot;
     67                 w[tot].sum = x1*3600+y1*60+z1;
     68                 w[tot].flag = 1;
     69                 ++ tot;
     70                 w[tot].sum = x2*3600+y2*60+z2;
     71                 w[tot].flag = 2;
     72             }
     73         }
     74         else if(x2 == x1){
     75             if(y2 == y1){
     76                 if(z1 > z2){
     77                     ++ tot;
     78                     w[tot].sum = x1*3600+y2*60+z2;
     79                     w[tot].flag = 1;
     80                     ++ tot;
     81                     w[tot].sum = x1*3600+y2*60+z1;
     82                     w[tot].flag = 2;
     83                 }
     84                 else{
     85                     ++ tot;
     86                     w[tot].sum = x1*3600+y2*60+z1;
     87                     w[tot].flag = 1;
     88                     ++ tot;
     89                     w[tot].sum = x1*3600+y2*60+z2;
     90                     w[tot].flag = 2;
     91                 }
     92             }
     93             else{
     94                 if(y1 > y2){
     95                     ++ tot;
     96                     w[tot].sum = x1*3600+y2*60+z2;
     97                     w[tot].flag = 1;
     98                     ++ tot;
     99                     w[tot].sum = x2*3600+y1*60+z1;
    100                     w[tot].flag = 2;
    101                 }
    102                 else{
    103                     ++ tot;
    104                     w[tot].sum = x1*3600+y1*60+z1;
    105                     w[tot].flag = 1;
    106                     ++ tot;
    107                     w[tot].sum = x2*3600+y2*60+z2;
    108                     w[tot].flag = 2;
    109                 }
    110                 
    111             }
    112         }
    113     }
    114     sort(w+1,w+tot+1,cmp);
    115     
    116     while(true){
    117         ++ pos;
    118         if(pos > tot)
    119             break;
    120         if(w[pos].flag == 1){
    121             q[++ tail] = w[pos].sum;
    122         }
    123         else if(w[pos].flag == 2){
    124             if(tail == 1){
    125                 Ans += w[pos].sum - q[tail];
    126                 -- tail;
    127             }
    128             else
    129                 -- tail;
    130         }
    131     }
    132     printf("%d",Ans);
    133     return 0;
    134 }
    135 
    136 bool cmp(data a,data b){
    137     return a.sum < b.sum;
    138 }
    Have a Look
  • 相关阅读:
    企业如何推行白盒测试
    Java命名规范
    MobileVLC for iphoneos4.3
    用Android NDK编译FFmpeg
    Linux 下Android 开发环境搭建 ---CentOS
    为什么要做白盒测试
    vlc的第三方库contrib的修改之一:live库的修改
    VC命名规范
    POJ 1470 Closest Common Ancestors (LCA入门题)
    HDU 4407 Sum 第37届ACM/ICPC 金华赛区 第1008题 (容斥原理)
  • 原文地址:https://www.cnblogs.com/sxprovence/p/4850819.html
Copyright © 2020-2023  润新知