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的更多相关文章

  1. 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 ...

  2. TCP/IP BOOKS

    TCP/IP Fundamentals for Microsoft Windows: Overview https://technet.microsoft.com/en-us/library/bb72 ...

  3. UVa 714 Copying Books(二分)

    题目链接: 传送门 Copying Books Time Limit: 3000MS     Memory Limit: 32768 KB Description Before the inventi ...

  4. LightOJ1283 Shelving Books(DP)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1283 Description You are a librarian ...

  5. 抄书 Copying Books UVa 714

    Copying  Books 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/B 题目: Descri ...

  6. [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 ...

  7. JSTL标签出错:<c:forEach var="book" items="${requestScope.books}" varStatus="status">

    今天在运行书里的JSTL标签代码的时候出错,总结一下: 问题1.The JSP specification requires that an attribute name is preceded by ...

  8. A Year Of Books - 2016 Javaer书单

    A Year Of Books - 2016 Javaer书单 (PS:欢迎留言推荐,很多来自白衣大哥的推荐) 1. OS & Networking <编码 : 隐匿在计算机软硬件背后的 ...

  9. 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 ...

随机推荐

  1. RabbitMQ系列(五)--高级特性

    在上一篇文章讲解MQ消息可靠性投递和幂等性中有提到confirm机制的重要性,现在更相信的说明一下 一.Confirm机制 Confirm就是消息确认,当Producer发送消息,如果Broker收到 ...

  2. ThinkPHP---rbac权限管理

    [一]概论 (1)简介 rbac(role based access controal),全称基于用户组/角色的权限控制. (2)概况 目前来说,一般项目有两种权限管理方式①传统方式:②rbac方式. ...

  3. vue-quill-editor + element-ui upload实现富文本图片上传

    代码贴上 <template> <div class="quill-editor-example"> <div class="box&quo ...

  4. BigDecimal运算

    BigDecimal由任意精度整数未缩放值和32位整数级别组成 . 如果为零或正数,则刻度是小数点右侧的位数. 如果是负数,则数字的非标定值乘以10,以达到等级的否定的幂. 因此,BigDecimal ...

  5. POJ2454——Jersey Politics

    POJ2454——Jersey Politics 题目大意: 在泽西奶牛和荷斯坦奶牛的最新普查中,威斯康星奶牛在谷仓中获得了三个档位. 泽西奶牛目前控制着国家重新分配委员会. 他们想将国家分为三个相当 ...

  6. UVA12118 Inspector's Dilemma(欧拉路径)

    题目: 某个国家有V(V≤1000)个城市,每两个城市之间都有一条双向道路直接相连,长度为T(每条边的长度都是T).你的任务是找一条最短的道路(起点和终点任意), 使得该道路经过E条指定的边.输出这条 ...

  7. 【转】精选十二款餐饮、快递、票务行业微信小程序源码demo推荐

    微信小程序的初衷是为了线下实体业服务的,必须有实体相结合才能显示小程序的魅力.个人认为微信小程序对于餐饮业和快递业这样业务比较单一的行业比较有市场,故整理推荐12款餐饮业和快递业微信小程序源码demo ...

  8. springcloud(十):熔断监控Hystrix Dashboard

             申明: 这里比较坑爹,大家写的时候要小心,这里和springboot的版本有关系哈,我使用的是2.0 版本,要么调频为1.5 版本,要么使用其他方式 解决错误,我选择了还是用2.0  ...

  9. Calculate S(n)

    Problem Description Calculate S(n). S(n)=13+23 +33 +......+n3 .   Input Each line will contain one i ...

  10. 给nginx生成自签名证书

    https://blog.csdn.net/qq_26819733/article/details/53431662 https://www.liaoxuefeng.com/article/00141 ...