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 ...
随机推荐
- struct与 union的基本用法
结构体与联合体是C语言的常见数据类型,可对C的基本数据类型进行组合使之能表示复杂的数据结构,意义深远,是优异代码的必备工具.一. struct与 union的基本用法,在语法上union ...
- mysql创建 存储过程 并通过java程序调用该存储过程
create table users_ning(id primary key auto_increment,pwd int); insert into users_ning values(id,123 ...
- 网页Html代码优化及分析
- 一个简单的servlet
1.创建一个自己的servlet文件,继承HttpServlet MyServlet.java package com.jmu.ccjoin.controller; import java.io.IO ...
- HDU1964 Pipes —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1964 Pipes Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- POJ3376 Finding Palindromes —— 扩展KMP + Trie树
题目链接:https://vjudge.net/problem/POJ-3376 Finding Palindromes Time Limit: 10000MS Memory Limit: 262 ...
- 为什么越来越多公链项目将WASM拥入怀中?
最近越来越多的项目开始转向VNT使用的WASM,像EOS.Ontology,包括最初引入虚拟机EVM运行智能合约环境的以太坊,最近也开始转向使用WASM. 什么是WASM? WASM ,全称:WebA ...
- poj 1258 Agri-Net 解题报告
题目链接:http://poj.org/problem?id=1258 题目意思:给出 n 个 farm,每个farm 之间通过一定数量的fiber 相连,问使得所有farm 直接或间接连通的 最少 ...
- UVA-11082 Matrix Decompressing(有上下界的最大流)
题目链接: Matrix Decompressing 题意: 给一个矩阵的每行和每列的和,(给的是前i行或者列的和); 矩阵中每个元素的值在1到20之间,找出这样的一个矩阵: 思路: 把它转化成一个二 ...
- 前端CSS规范整理
一.文件规范 1.文件均归档至约定的目录中. 具体要求通过豆瓣的CSS规范进行讲解: 所有的CSS分为两大类:通用类和业务类.通用的CSS文件,放在如下目录中: 基本样式库 /css/core 通用U ...