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 黑 ...
随机推荐
- jsp页面获取服务器时间
Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MON ...
- java集合之Map_keySet_entrySet
keySet()的使用:该方法返回的是一个key对象的Set<E>集合,通过该set集合的对象调用iterator方法返回一个迭代器,通过该迭代器可访问到set集合里面的key 再调用Ha ...
- jQuery对checkbox的各种操作
//注意: 操作checkbox的checked,disabled属性时jquery1.6以前版本用attr,1.6以上(包含)建议用prop //1.根据id获取checkbox $("# ...
- [Head First Python]6. 定制数据对象:打包代码与数据
相同功能,演进实现 数据文件 sarah2.txt sarah Sweeney,2002-6-17,2:58,2.58,2:39,2-25,2-55,2:54,2.18,2:55,2:55 1- 返回 ...
- 十进制二进制之间的转化 PHP算法
[ 十进制转二进制 ] function test($var){ $func = function($i){ if($i < 2){ return $i; } $return['int'] = ...
- iscsi模型相关点
1.iscsi即ip scsi,按架构分为控制器架构.链接桥系统架构.pc系统架构.这里主要说明一下pc系统架构. 所谓的pc系统架构,就是利用target软件存储端+initiator客户端+tcp ...
- Stars(BIT树状数组)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu just a hook(线段树,区间修改)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- android Unable to resolve target 'android-XX'错误和conversion to dalvik format failed with error 1错误
当用eclipse 导入一个已经存在的项目时,经常会遇见:Unable to resolve target 'android-XX' 类似的错误.这是因为导入的项目代码中project.propert ...
- 二分求解 三角形 stl的应用 涉及范围的二分查找可以先求上界再算下界,结果即上界减下界
二分 Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Description You ...