hdu1866 A + B forever!(面积并)题解
A + B forever!
As we say, the addition defined between two rectangles is the sum of their area . And you just have to tell me the ultimate area if there are a few rectangles.
Isn’t it a piece of cake for you? Come on! Capture the bright “accepted” for yourself.
0<=x1,x2<=1000,0<=y1,y2<=1000.
(1,1,3,3)+(2,2,4,4)+(5,5,6,6)
8
思路:
一开始想到用一个二维数组当做坐标轴平面,然后一个一个方块去标记,最后数出来有多少方块。但是输入很坑,看着很麻烦。面积填涂也很坑,不能直接把x1,x2,y1,y2填上,因为数组中(x1,y1)是一个方块而坐标轴中(x1,y1)是一个点。
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<cctype>
#include<queue>
#include<math.h>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define N 1005
using namespace std;
int map[N][N];
int num(char x){
if(x>='0' && x<='9') return 1;
return 0;
}
int main(){
int len,x[4],count,sum;
char s[510];
while(gets(s)){
memset(map,0,sizeof(map));
len=strlen(s);
count=0;
sum=0;
for(int i=0;i<len;i++){
if(num(s[i])==1){
x[count]=s[i]-'0';
i++;
while(num(s[i])==1){
x[count]=x[count]*10+(s[i]-'0');
i++;
}
count++;
}
if(count==4){
int x1=min(x[0],x[2]); //保证后面遍历大小不会错
int x2=max(x[0],x[2]);
int y1=min(x[1],x[3]);
int y2=max(x[1],x[3]);
for(int j=x1;j<x2;j++){ //这里要注意后面的<而不是<=,理由就是上面说到的
for(int k=y1;k<y2;k++){
map[j][k]=1;
}
}
count=0;
}
}
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(map[i][j]==1) sum++;
}
}
printf("%d\n",sum);
}
return 0;
}
hdu1866 A + B forever!(面积并)题解的更多相关文章
- BZOJ2178:圆的面积并——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2178 给出N个圆,求其面积并. simpson,将圆劈成两半,假设上面的叫上壳,下面的叫下壳,对这 ...
- codeforces CF475 ABC 题解
Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...
- HDU 1542 Atlantis(线段树面积并)
描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...
- poj 2079(旋转卡壳求解凸包内最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9060 Accepted: 2698 Descript ...
- HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)
题目链接 题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积. 题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点. 利用叉积面积求高,利用点积的性质求最左右点和长度 ...
- Gym - 101208J 2013 ACM-ICPC World Finals J.Pollution Solution 圆与多边形面积交
题面 题意:给你一个半圆,和另一个多边形(可凹可凸),求面积交 题解:直接上板子,因为其实这个多边形不会穿过这个半圆,所以他和圆的交也就是和半圆的交 打的时候队友说凹的不行,不是板题,后面想想,圆与多 ...
- L3-021 神坛 (叉积排序+向量积求面积)
题目链接 https://pintia.cn/problem-sets/994805046380707840/problems/994805046577840128 题意:给定n个点求三角形最小面积: ...
- CodeForces 589J Cleaner Robot
题目链接 题意:一个机器人打扫卫生,URDL代表初始时机器人面对的方向上右下左. ' . ' 代表可以打扫的, ' * ' 代表家具,如果机器人遇到家具就顺时针转90度,问机器人能打扫多少面积. 题解 ...
- Codeforces Round #308 (Div. 2) A B C 水 数学
A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- FS Shell命令手册
1. FS Shell 1.1 简介 调用文件系统(FS)Shell命令应使用 bin/hadoop fs <args>的形式. 所有的的FS shell命令使用URI ...
- js_常见特效——点击切换_背景颜色_收起与展开
<script src="../js/jquery-1.8.3.min.js"></script><script type="text/ja ...
- [目标检测]SSD原理
1 SSD基础原理 1.1 SSD网络结构 SSD使用VGG-16-Atrous作为基础网络,其中黄色部分为在VGG-16基础网络上填加的特征提取层.SSD与yolo不同之处是除了在最终特征图上做目标 ...
- makefile 中wildcard
在Makefile规则中,通配符会被自动展开.但在变量的定义和函数引用时,通配符将失效.这种情况下如果需要通配符有效,就需要使用函数“wildcard”,它的用法是:$(wildcard PATTER ...
- 1025 PAT Ranking[排序][一般]
1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...
- Maven项目常见错误解决方法汇总
issue 1.Java compiler level does not match the version of the installed Java project facet. 或者 One o ...
- angular前端框架
总所周知,在前端开发中,大家用的比较多的框架就是angular,vue,react等,今天就为大家讲一下angular大家框架的原理及运用 1.本次所举的例子是以依赖require.js的, < ...
- 后台维护常用SQL
OU.库存组织与子库存 select hou.organization_id ou_org_id, --org_id hou.name ou_name, --ou名称 ood.organization ...
- VS2010中如何实现自定义MFC控件
本文简要讲解在VS2010中怎样实现自定义MFC控件的知识,以下是分步骤说明. 一.自定义一个空白控件 1.先创建一个MFC工程 NEW Project-->MFC-->MFC Appl ...
- Instruments(性能调优 12.3)
Instruments Instruments是Xcode套件中没有被充分利用的一个工具.很多iOS开发者从没用过Instruments,或者只是用Leaks工具检测循环引用.实际上有很多Instru ...