BZOJ 3368 约翰看山(扫描)O(N)
这题,简直丧心病狂了。
大意是给你一个环上一些覆盖的区间,让你求总覆盖长度。
非常坑的点是这个区间因为是个环,所以可能逆时针给你,也可能顺时针给你,你特别要注意。那么区分顺时针和逆时针的方法
就是,题目中的一句关键:每个区间都小于180.根据这个判断就可以。还有一个要注意的地方就是,他可能在一个角度中的不能分度搞你。这题我是彻底服了。把我坑的底朝天。后来管理BZOJ要的数据才明白是怎么回事。。。。太弱弱了。。。。
Code:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream> using namespace std; int N;
int pos = ,Ans = ,tot = ; struct data{
int flag;
int sum;
}w[]; int q[];
int tail = ;
bool cmp(data a,data b);
int main(){
scanf("%d",&N);
for(int i = ;i <= N;++ i){
int x1,y1,z1,x2,y2,z2;
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
if(x1 > x2){//so silly..caocao
if(x1 - x2 >= ){
++ tot;
w[tot].sum = x1*+y1*+z1;
w[tot].flag = ;
++ tot;
w[tot].sum = *;
w[tot].flag = ;
++ tot;
w[tot].sum = ;
w[tot].flag = ;
++ tot;
w[tot].sum = x2*+y2*+z2;
w[tot].flag = ;
}
else{
++ tot;
w[tot].sum = x2*+y2*+z2;
w[tot].flag = ;
++ tot;
w[tot].sum = x1*+y1*+z1;
w[tot].flag = ;
}
}
else if(x2 > x1){
if(x2 - x1 >= ){
++ tot;
w[tot].sum = x2*+y2*+z2;
w[tot].flag = ;
++ tot;
w[tot].sum = *;
w[tot].flag = ;
++ tot;
w[tot].sum = ;
w[tot].flag = ;
++ tot;
w[tot].sum = x1*+y1*+z1;
w[tot].flag = ;
}
else{
++ tot;
w[tot].sum = x1*+y1*+z1;
w[tot].flag = ;
++ tot;
w[tot].sum = x2*+y2*+z2;
w[tot].flag = ;
}
}
else if(x2 == x1){
if(y2 == y1){
if(z1 > z2){
++ tot;
w[tot].sum = x1*+y2*+z2;
w[tot].flag = ;
++ tot;
w[tot].sum = x1*+y2*+z1;
w[tot].flag = ;
}
else{
++ tot;
w[tot].sum = x1*+y2*+z1;
w[tot].flag = ;
++ tot;
w[tot].sum = x1*+y2*+z2;
w[tot].flag = ;
}
}
else{
if(y1 > y2){
++ tot;
w[tot].sum = x1*+y2*+z2;
w[tot].flag = ;
++ tot;
w[tot].sum = x2*+y1*+z1;
w[tot].flag = ;
}
else{
++ tot;
w[tot].sum = x1*+y1*+z1;
w[tot].flag = ;
++ tot;
w[tot].sum = x2*+y2*+z2;
w[tot].flag = ;
} }
}
}
sort(w+,w+tot+,cmp); while(true){
++ pos;
if(pos > tot)
break;
if(w[pos].flag == ){
q[++ tail] = w[pos].sum;
}
else if(w[pos].flag == ){
if(tail == ){
Ans += w[pos].sum - q[tail];
-- tail;
}
else
-- tail;
}
}
printf("%d",Ans);
return ;
} bool cmp(data a,data b){
return a.sum < b.sum;
}
Have a Look
BZOJ 3368 约翰看山(扫描)O(N)的更多相关文章
- TTTTTTTTTTTTTTTTTT Gym 100851L 看山填木块
题意:这题是给你w列方格,然后给你n个方块,让你加进去,使得这个图变得最高,加的要求是,如果这块的下面,以及左下右下都有,才能放 #include <cstdio> #include &l ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 自定义ZXing二维码扫描界面并解决取景框拉伸等问题
先看效果 扫描内容是下面这张,二维码是用zxing库生成的 由于改了好几个类,还是去年的事都忘得差不多了,所以只能上这个类的代码了,主要就是改了这个CaptureActivity.java packa ...
- BZOJ.5319.[JSOI2018]军训列队(主席树)
LOJ BZOJ 洛谷 看错了,果然不是\(ZJOI\)..\(jry\)给\(JSOI\)出这么水的题做T3么= = 感觉说的有点乱,不要看我写的惹=-= 对于询问\(l,r,k\),设\(t=r- ...
- spring启动component-scan类扫描加载过程(转)
文章转自 http://www.it165.net/pro/html/201406/15205.html 有朋友最近问到了 spring 加载类的过程,尤其是基于 annotation 注解的加载过程 ...
- 【Spring源码分析系列】启动component-scan类扫描加载过程
原文地址:http://blog.csdn.net/xieyuooo/article/details/9089441/ 在spring 3.0以上大家都一般会配置一个Servelet,如下所示: &l ...
- 冰雪奇缘,白色世界:四个IT人的四姑娘山双桥沟游记
去年9月初去了川西的稻城亚丁,体会了金色世界秋日童话,还写了一篇游记<从你的全世界路过-一群程序员的稻城亚丁游记>,也是得到了很多朋友和童鞋的点赞.今年11月初趁着周末的两天时间和朋友去了 ...
- BZOJ 3238 差异
BZOJ 3238 差异 看这个式子其实就是求任意两个后缀的 $ LCP $ 长度和.前面的 $ len(T_i)+len(T_j) $ 求和其实就是 $ n(n-1)(n+1)/2 $ ,这个是很好 ...
- 3000本IT书籍下载地址
http://www.shouce.ren/post/d/id/112300 黑客攻防实战入门与提高.pdfhttp://www.shouce.ren/post/d/id/112299 黑 ...
随机推荐
- vs中动态DLL与静态LIB工程中加入版本信息的方法
说明:本文仅针对刚接触VS不久的新手们(包括ME),提供的一点小Tips,同时也是小生的首篇Blog文章,请大伙多多担待O(∩_∩)O哈! 步骤1 - 在工程中右键添加新建项 步骤2 - 选择创建RC ...
- PHP学习笔记十八【构造函数】
<?php class Person{ public $name; public $age; //定义构造函数 function 空格__construct 构造方法没有返回值,对象自动调用 p ...
- android listview Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
android listview 适配器在多种类型viewType报错: Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; ...
- linux bugfree 安装
前段时间用了下bugzilla,请参考:linux bugzilla nginx 安装配置 详解,感觉不是很好用.下面说一下,bugfree的安装 bugfree3.0.1是用php的yii框架开发的 ...
- Stall Reservations(POJ 3190 贪心+优先队列)
Stall Reservations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4434 Accepted: 158 ...
- Frogger(最短路)
Frogger(poj2253) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31854 Accepted: 1026 ...
- C++----练习
1.完成一个C++实现的加法程序: #include<iostream> int main() { std::cout<<"可以输入两个加数,本程序完成加法...&q ...
- SQL查询 addScalar()或addEntity()
Hibernate除了支持HQL查询外,还支持原生SQL查询. 对原生SQL查询执行的控制是通过SQLQuery接口进行的,通过执行Session.createSQLQuery()获取这个接口.该 ...
- js加载优化-二
http://www.cnblogs.com/radom/archive/2011/04/26/2028886.html ontrolJS 主要为了是解决网页加载中Js文件的性能问题,ControlJ ...
- Keil C51 中指针的使用
指针是C语言中比较难的一个内容,Keil C51在指针方面有和标准C不一样的地方,今天看了一些资料学习了一下Keil C51 中指针的使用. keil51的指针,包含两种指针:普通指针,兼容标准C:内 ...