Olddriver’s books
Olddriver 的书多的吓人,什么算法导论,组合数学英
文版(orz)。。。。。。他把 n 本书都放在身后的桌子上,
每本书有一定的面积,并且书可以覆盖,求 n 本书覆盖桌面
的面积
输入格式:
输入第一行为一个数 N,表示书的数量。下面 N 行,每行
四个整数,分别表示每个书的左下角和右上角的坐标。
输出格式:
输出只有一行,一个整数,表示图形的面积。
样例输入:
3
1 1 4 3
2 -1 3 2
4 0 5 2
样例输出:
10
数据范围:
对于 30%的数据:n<=100,坐标数值绝对值<=300
对于 100%的数据:n<=100,坐标数值绝对值<=10^8
【题解】
对于30%数据 打标记。
对于100%数据,注意到点最多有200个,对x,y坐标离散化,再打标记。
考试时没想到离散化(但数据范围是个很明显的暗示)。要试着接纳这道题的思维。
另外,离散化后要去重(然而我并不知道为什么)。
//这道题写什么扫描线
//离散化以后 直接暴力写不就好了么 O(n^3) 数据真是良心
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=510;
struct books
{
int x1,y1,x2,y2;
}c[MAX];
bool b[MAX][MAX];//某一区域上是否有书覆盖 注意是区域而不是点
int x[MAX],y[MAX];
int rx[MAX],ry[MAX],tx,ty;
int n,cnt;
long long ans;
int gi()
{
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=-1,ch=getchar();
while (ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*w;
}
//手写lower_bound
int pos_x(int x)
{
int l=1,r=tx;
while (l<r)
{
int mid=(l+r+1)>>1;
if (rx[mid]<=x) l=mid;
else r=mid-1;
}
return l;
}
//手写*2
int pos_y(int x)
{
int l=1,r=ty;
while (l<r)
{
int mid=(l+r+1)>>1;
if (ry[mid]<=x) l=mid;
else r=mid-1;
}
return l;
}
int main()
{
freopen("olddriver.in","r",stdin);
freopen("olddriver.out","w",stdout);
n=gi();
for (int i=1;i<=n;i++)
{
c[i].x1=gi();c[i].y1=gi();c[i].x2=gi();c[i].y2=gi();
x[++cnt]=c[i].x1;y[cnt]=c[i].y1;
x[++cnt]=c[i].x2;y[cnt]=c[i].y2;
}
sort(x+1,x+cnt+1);
sort(y+1,y+cnt+1);
for (int i=1;i<=cnt;i++)//去重
{
if (i==1||x[i]!=x[i-1]) rx[++tx]=x[i];
if (i==1||y[i]!=y[i-1]) ry[++ty]=y[i];
}
for (int i=1;i<=n;i++)//暴力枚举每一本书
{
int X1=pos_x(c[i].x1),X2=pos_x(c[i].x2);
int Y1=pos_y(c[i].y1),Y2=pos_y(c[i].y2);
for (int u=X1;u<X2;u++)
for (int v=Y1;v<Y2;v++)
b[u][v]=1;
}
for (int u=1;u<tx;u++)
for (int v=1;v<ty;v++)
if (b[u][v]) ans+=1ll*(rx[u+1]-rx[u])*(ry[v+1]-ry[v]);
printf("%lld",ans);
return 0;
}
Olddriver’s books的更多相关文章
- 7 Must Read Python Books
7 Must Read Python Books I started learning Python just two years ago. Coming from a C++ and Java ba ...
- TCP/IP BOOKS
TCP/IP Fundamentals for Microsoft Windows: Overview https://technet.microsoft.com/en-us/library/bb72 ...
- UVa 714 Copying Books(二分)
题目链接: 传送门 Copying Books Time Limit: 3000MS Memory Limit: 32768 KB Description Before the inventi ...
- LightOJ1283 Shelving Books(DP)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1283 Description You are a librarian ...
- 抄书 Copying Books UVa 714
Copying Books 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/B 题目: Descri ...
- [LintCode] Copy Books 复印书籍
Given an array A of integer with size of n( means n books and number of pages of each book) and k pe ...
- JSTL标签出错:<c:forEach var="book" items="${requestScope.books}" varStatus="status">
今天在运行书里的JSTL标签代码的时候出错,总结一下: 问题1.The JSP specification requires that an attribute name is preceded by ...
- A Year Of Books - 2016 Javaer书单
A Year Of Books - 2016 Javaer书单 (PS:欢迎留言推荐,很多来自白衣大哥的推荐) 1. OS & Networking <编码 : 隐匿在计算机软硬件背后的 ...
- A Personal Selection of Books on E lectromagnetics and Computational E lectromagnetics---David B. Davidson
链接. General Books on Electromagnetics When our department recently reviewed our junior-level text, w ...
随机推荐
- JavaScipt30(第五个案例)(主要知识点:flex布局)
承接上文,这是第5个案例:这节没什么讲的,随便记录下吧,主要是用了flex布局与transform translateY,js部分和案例1类似. 附上项目链接: https://github.com/ ...
- 使用lombok注解@Getter @Setter方法代码编译成功,但是没有生成get,set方法
现象描述: 在对应类对象中,添加lombok的@Getter或@Setter注解,编译没有问题,但是在使用类对象时,没有出现对应的get或set方法. 配置且编译ok,但是没有对应的get或set方法 ...
- BZOJ 2223: [Coci 2009]PATULJCI 主席树
Code: #include<bits/stdc++.h> #define maxn 300001 #define mid ((l+r)>>1) using namespace ...
- docker搭建日志收集系统EFK
EFK Elasticsearch是一个数据搜索引擎和分布式NoSQL数据库的组合,提过日志的存储和搜索功能. Fluentd是一个消息采集,转化,转发工具,目的是提供中心化的日志服务. Kibana ...
- 动态 SQL(2)
前面我们学习了使用动态 SQL 的 if.where.trim元素来处理一些简单查询操作,但对于一些 SQL 语句中含有 in 条件,需要迭代条件集合来生成的情况,我们就需要使用 foreach 标签 ...
- python面试题之如何在Python中创建自己的包
Python中创建包是比较方便的,只需要在当前目录建立一个文件夹, 文件夹中包含一个__init__.py文件和若干个模块文件, 其中__init__.py可以是一个空文件,但还是建议将包中所有需要导 ...
- python爬虫24 | 搞事情了,用 Appium 爬取你的微信朋友圈。
昨天小帅b看到一些事情不顺眼 有人偷换概念 忍不住就写了一篇反讽 996 的 看不下去了,我支持996,年轻人就该996! 没想到有些人看不懂 这就算了 还来骂我 早些时候关注我的小伙伴应该知道我第一 ...
- 关于python字典中文显示的处理办法
最近工作中遇到字典包含中文,显示\uxxxx的问题,怎么转换都无法输入正常的中文:{"gc": "\u4eba\u751f\u7f8e\u597d", &quo ...
- DemoKit编译过程错误
1.编译出错: 2.原因(将代码注释):
- UVA - 10825 Anagram and Multiplication
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34594 有一个m位n进制的数,它的特性是这个数依次乘以2,3... ...