Adding New Machine ZOJ - 3540
https://vjudge.net/problem/ZOJ-3540
错误记录:
扫描线没有考虑到同一行的要删除在前,加入在后;由于用了特殊的方式所以想当然以为不需要考虑这个问题
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
struct Q
{
ll x1,y1,x2,y2;
}q[];
ll w,h,n,m;
struct Q2
{
ll x1,x2,y,type;
}qt[];
ll t1[];
bool operator<(const Q2 &a,const Q2 &b)
{
return a.y<b.y||(a.y==b.y&&a.type<b.type);
}
ll qn,ta,ans;
set<pi> s;
set<pi>::iterator it;
int main()
{
ll i,r,tx,ty;
while(scanf("%lld%lld%lld%lld",&w,&h,&n,&m)==)
{
ans=; for(i=;i<=n;i++) scanf("%lld%lld%lld%lld",&q[i].x1,&q[i].y1,&q[i].x2,&q[i].y2); qn=;
s.clear();s.insert(mp(-,));s.insert(mp(w+,w+));
for(i=;i<=n;i++)
{
++qn;qt[qn].x1=q[i].x1;qt[qn].x2=q[i].x2;qt[qn].y=q[i].y1;qt[qn].type=;
++qn;qt[qn].x1=q[i].x1;qt[qn].x2=q[i].x2;qt[qn].y=q[i].y2+;qt[qn].type=;
}
sort(qt+,qt+qn+);
for(i=;i<=qn;i++) t1[i]=qt[i].y;
t1[]=qn;
t1[++t1[]]=;
t1[++t1[]]=h+;
sort(t1+,t1+t1[]+);t1[]=unique(t1+,t1+t1[]+)-t1-;
r=;ta=max(w-m+,0ll);
for(i=;i<t1[];i++)
{
while(r+<=qn&&qt[r+].y<=t1[i])
{
r++;
if(qt[r].type==)
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=it->first;ty=(--it)->second;
ta-=max(tx-ty-m,0ll);
ta+=max(qt[r].x1-ty-m,0ll);
ta+=max(tx-qt[r].x2-m,0ll);
s.insert(mp(qt[r].x1,qt[r].x2));
}
else
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=(++it)->first;--it;ty=(--it)->second;
ta-=max(qt[r].x1-ty-m,0ll);
ta-=max(tx-qt[r].x2-m,0ll);
ta+=max(tx-ty-m,0ll);
s.erase(mp(qt[r].x1,qt[r].x2));
}
}
ans+=ta*(t1[i+]-t1[i]);
} qn=;
s.clear();s.insert(mp(-,));s.insert(mp(h+,h+));
for(i=;i<=n;i++)
{
++qn;qt[qn].x1=q[i].y1;qt[qn].x2=q[i].y2;qt[qn].y=q[i].x1;qt[qn].type=;
++qn;qt[qn].x1=q[i].y1;qt[qn].x2=q[i].y2;qt[qn].y=q[i].x2+;qt[qn].type=;
}
sort(qt+,qt+qn+);
for(i=;i<=qn;i++) t1[i]=qt[i].y;
t1[]=qn;
t1[++t1[]]=;
t1[++t1[]]=w+;
sort(t1+,t1+t1[]+);t1[]=unique(t1+,t1+t1[]+)-t1-;
r=;ta=max(h-m+,0ll);
for(i=;i<t1[];i++)
{
while(r+<=qn&&qt[r+].y<=t1[i])
{
r++;
if(qt[r].type==)
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=it->first;ty=(--it)->second;
ta-=max(tx-ty-m,0ll);
ta+=max(qt[r].x1-ty-m,0ll);
ta+=max(tx-qt[r].x2-m,0ll);
s.insert(mp(qt[r].x1,qt[r].x2));
}
else
{
it=s.lower_bound(mp(qt[r].x1,qt[r].x2));
tx=(++it)->first;--it;ty=(--it)->second;
ta-=max(qt[r].x1-ty-m,0ll);
ta-=max(tx-qt[r].x2-m,0ll);
ta+=max(tx-ty-m,0ll);
s.erase(mp(qt[r].x1,qt[r].x2));
}
}
ans+=ta*(t1[i+]-t1[i]);
} if(m==) ans/=;
printf("%lld\n",ans);
}
return ;
}
Adding New Machine ZOJ - 3540的更多相关文章
- HDU 4052 Adding New Machine(矩形面积并)
Adding New Machine Problem Description Incredible Crazily Progressing Company (ICPC) suffered a lot ...
- UVA1492 - Adding New Machine(扫描线)
UVA1492 - Adding New Machine(扫描线) option=com_onlinejudge&Itemid=8&page=show_problem&cate ...
- HDU 4052 Adding New Machine (线段树+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4052 初始给你w*h的矩阵,给你n个矩形(互不相交),按这些矩形尺寸把初始的矩形扣掉,形成一个新的'矩 ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- hdu 4052 线段树扫描线、奇特处理
Adding New Machine Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- QEMU, a Fast and Portable Dynamic Translator-Fabrice Bellard-翻译
Abstract We present the internals of QEMU, a fast machine emulator using an original portable dynami ...
- HZNU Training 4 for Zhejiang Provincial Collegiate Programming Contest 2019
今日这场比赛我们准备的题比较全面,二分+数论+最短路+计算几何+dp+思维+签到题等.有较难的防AK题,也有简单的签到题.为大家准备了一份题解和AC代码. A - Meeting with Alien ...
- zoj 3805 Machine
Machine Time Limit: 2 Seconds Memory Limit: 65536 KB In a typical assembly line, machines are c ...
随机推荐
- Hibernate quick start
Preface Working with both Object-Oriented software and Relational Databases can be cumbersome and ti ...
- 如何查看Java进程并获取进程ID?
1. 在 LINUX 命令平台输入 1-2 个字符后按 Tab 键会自动补全后面的部分(前提是要有这个东西,例如在装了 tomcat 的前提下, 输入 tomcat 的 to 按 tab).2. ps ...
- 使用Qt发送HTTPS请求
示例代码: #include "mainwindow.h" #include "ui_mainwindow.h" #include <QNetworkAc ...
- Uboot中start.S源码的指令级的详尽解析【转】
本文转载自:http://www.crifan.com/files/doc/docbook/uboot_starts_analysis/release/html/uboot_starts_analys ...
- Spring Boot2.0之 整合Redis集群
项目目录结构: pom: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// ...
- 多线程、死锁、线程安全、同步方法、代码块、休眠、守护线程、Thread、Runnable(二十三)
1.多线程的引入 * 1.什么是线程 * 线程是程序执行的一条路径, 一个进程中可以包含多条线程 * 多线程并发执行可以提高程序的效率, 可以同时完成多项工作* 2.多线程的应用场景 * 红蜘蛛同时共 ...
- SocketErrorCode:10022
在编写.net的网络服务器时,我使用了裸socket来实现.在windows上,或者在linux上通过.net core来跑时都没有什么问题,但是通过mono运行调用socket.Bind()时却总是 ...
- JS截取与分割字符串常用技巧总结
本文实例讲述了JS截取与分割字符串的常用方法.分享给大家供大家参考,具体如下: JS截取字符串可使用 substring()或者slice() 函数:substring() 定义:substring( ...
- [Selenium] 如何使用Chrome Options 定制测试Chrome 浏览器的特定属性 (类似FirefoxProfiles)
Chrome Options 类似于FirefoxProfiles,用于定制待测试的Chrome 浏览器的特定属性 1)如果希望测试某个浏览器插件,可通过addExtensions方式提前加载以.cr ...
- CocoaPods 安装相关问题
(1)pod install还是pod update都卡在Analyzing dependencies不动. 解决方法: 其实原因在于以上两个命令执行时会升级CocoaPods的spec仓库,加一个参 ...