HDU 4533
一道好题。想了好久没想出来,只是觉得总要二分独立处理矩形。感觉自己在把问题转化为数学公式以及分解问题的方面的能力很不足。
http://blog.csdn.net/wh2124335/article/details/8739097
解题思路:



看过后敲代码不难。注意以后在涉及计算方面要把问题往数学公式方面靠近。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL __int64
using namespace std;
const int N= 20100; struct Point{
int x,y,qc;
Point (){}
Point (int x1,int y1){
x=x1,y=y1;
qc=max(x,y);
}
}a[N*2],b[N*2];
int n; LL aad[N*2],aam[N*2];
LL bad[N*2],bam[N*2]; bool cmp(Point a,Point b){
if(a.qc<b.qc ) return true;
return false;
} int bin(Point *s,int t){
int l=0,r=2*n-1;
int ans=-1;
while(l<=r){
int m=(l+r)>>1;
if(s[m].qc<=t){
ans=m;
l=m+1;
}
else r=m-1;
}
return ans;
} int main(){
int T,x1,y1,x2,y2,cnta,cntb,m,t;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
cnta=cntb=0;
for(int i=0;i<n;i++){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
a[cnta++]=Point(x1,y1);
a[cnta++]=Point(x2,y2);
b[cntb++]=Point(x1,y2);
b[cntb++]=Point(x2,y1);
}
sort(a,a+2*n,cmp);
sort(b,b+2*n,cmp);
aad[0]=a[0].x+a[0].y; aam[0]=a[0].x*a[0].y;
bad[0]=b[0].x+b[0].y; bam[0]=b[0].x*b[0].y;
for(int i=1;i<n*2;i++){
aad[i]=aad[i-1]+a[i].x+a[i].y;
aam[i]=aam[i-1]+(LL)a[i].x*(LL)a[i].y;
bad[i]=bad[i-1]+b[i].x+b[i].y;
bam[i]=bam[i-1]+(LL)b[i].x*(LL)b[i].y;
}
scanf("%d",&m);
LL ans;
while(m--){
scanf("%d",&t);
int a1=bin(a,t),b1=bin(b,t);
if(a1==-1)
puts("0");
else if(b1==-1){
ans=(LL)(a1+1)*(LL)t*(LL)t-aad[a1]*(LL)t+aam[a1];
printf("%I64d\n",ans);
}
else{
ans=(LL)(a1+1)*(LL)t*(LL)t-aad[a1]*(LL)t+aam[a1]-((LL)(b1+1)*(LL)t*(LL)t-bad[b1]*(LL)t+bam[b1]);
printf("%I64d\n",ans);
}
}
}
return 0;
}
HDU 4533的更多相关文章
- hdu 4533 线段树(问题转化+)
威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- HDU 4533 威威猫系列故事——晒被子
题目链接 扫描线可做,然后当时比赛后问虎哥,他说可以标记,然后拖了很久,今天从早上折腾到晚上,终于把两种情况写出来,分析太弱.改天扫描线,再来一次. 被子如果被y = x 穿过,可以分成两部分,上和下 ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- [Swift通天遁地]九、拔剑吧-(16)搭建卡片页面:Card Peek/Pop动态切换界面
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- SpringBoot集成Mybatis配置动态数据源
很多人在项目里边都会用到多个数据源,下面记录一次SpringBoot集成Mybatis配置多数据源的过程. pom.xml <?xml version="1.0" encod ...
- easyui datagrid 页面详细使用
//加载数据workflowName onloadmyCgxList: function (id) { if (id != null && id != "" ...
- ZOJ3714JavaBeans
#!/usr/bin/env python # encoding: utf-8 t = int(raw_input()) for i in range(t): n,k = [int(x) for x ...
- ACM_三角形蛇形矩阵
三角形蛇形矩阵 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小铠觉得各类题型是要温故而知新的,所以他叫小发出一道类似做过的题. ...
- android UI 操作 不要在子线程中操作UI
不管是android ,还是 ios ,请不要在子线程中操作UI,有时有些崩溃,从报错上看不出什么原因,就有可能是子线程操作了UI:切记,切记! 请放在主线程例: activity.runOnUiTh ...
- Bootstrap3模态框Modal垂直居中样式
1,Bootstrap 模态框插件Bootbox垂直居中样式: <!DOCTYPE html> <html lang="en"> <head> ...
- html5——DOM扩展
元素获取 1.document.getElementsByClassName ('class') 通过类名获取元素,以类数组形式存在. 2.document.querySelector(‘div’) ...
- ASP.NET MVC 二维码生成(ThoughtWorks.QRCode)
原文地址http://www.cnblogs.com/jys509/p/4592539.html
- JS监听事件错误:Uncaught TypeError: xx(函数名)is not a function at HTMLInputElement.onclick
事件监听一直出错,提示已定义的函数名不是一个函数,折腾了好久才想到,原来是函数名和JS内部关键字重名造成的. 以前也遇到过这种情况,但因为发生的概率比较小,就没太在意,但是这次感觉这方面确实需要注意, ...