A + B forever!

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1295    Accepted Submission(s): 326

Problem Description
As always, A + B is the necessary problem of this warming-up contest. But the patterns and contents are different from the previous ones. Now I come up with a new “A + B” problem for you, the top coders of HDU.
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.
 

Input
There come a lot of cases. In each case, there is only a string in one line. There are four integers, such as “(x1,y1,x2,y2)”, describing the coordinates of the rectangle, with two brackets distinguishing other rectangle(s) from the string. There lies a plus symbol between every two rectangles. Blanks separating the integers and the interpunctions are added into the strings arbitrarily. The length of the string doesn’t exceed 500.
0<=x1,x2<=1000,0<=y1,y2<=1000.
 

Output
For each case, you just need to print the area for this “A+B” problem. The results will not exceed the limit of the 32-signed integer.
 

Sample Input

(1,1,2,2)+(3,3,4,4)
(1,1,3,3)+(2,2,4,4)+(5,5,6,6)
 

Sample Output

2
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!(面积并)题解的更多相关文章

  1. BZOJ2178:圆的面积并——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=2178 给出N个圆,求其面积并. simpson,将圆劈成两半,假设上面的叫上壳,下面的叫下壳,对这 ...

  2. codeforces CF475 ABC 题解

    Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...

  3. HDU 1542 Atlantis(线段树面积并)

     描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...

  4. poj 2079(旋转卡壳求解凸包内最大三角形面积)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9060   Accepted: 2698 Descript ...

  5. HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛 - 初赛(1)

    题目链接   题意:给出n个矩形,求能覆盖所有矩形的最小的矩形的面积. 题解:对所有点求凸包,然后旋转卡壳,对没一条边求该边的最左最右和最上的三个点. 利用叉积面积求高,利用点积的性质求最左右点和长度 ...

  6. Gym - 101208J 2013 ACM-ICPC World Finals J.Pollution Solution 圆与多边形面积交

    题面 题意:给你一个半圆,和另一个多边形(可凹可凸),求面积交 题解:直接上板子,因为其实这个多边形不会穿过这个半圆,所以他和圆的交也就是和半圆的交 打的时候队友说凹的不行,不是板题,后面想想,圆与多 ...

  7. L3-021 神坛 (叉积排序+向量积求面积)

    题目链接 https://pintia.cn/problem-sets/994805046380707840/problems/994805046577840128 题意:给定n个点求三角形最小面积: ...

  8. CodeForces 589J Cleaner Robot

    题目链接 题意:一个机器人打扫卫生,URDL代表初始时机器人面对的方向上右下左. ' . ' 代表可以打扫的, ' * ' 代表家具,如果机器人遇到家具就顺时针转90度,问机器人能打扫多少面积. 题解 ...

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

随机推荐

  1. elasticsearch的重启

    没有重启的操作,只有关闭了再启动的操作. ps -ef | grep elastic e表示全部的进程,f表示展示进程间的相关关系,如父子进程. 然后找到你启动es的那个账号,不是root,一般是新建 ...

  2. Unity3D中使用Profiler精确定位性能热点的优化技巧

    本文由博主(SunboyL)原创,转载请注明出处:http://www.cnblogs.com/xsln/p/BeginProfiler.html 简介 在使用Profiler定位代码的性能热点时,很 ...

  3. Linux替换字符串

    sed命令批量替换多个文件中的字符串: 命令:sed -i “s/原字符串/新字符串/g” `grep 原字符串 -rl 所在目录` 例如:我要把 xy 替换为 mn,执行命令: sed -i “s/ ...

  4. java.io.File实战

    There are many things that can go wrong: A class works in Unix but doesn't on Windows (or vice versa ...

  5. Dubbo简单环境搭建

    Dubbo服务的发展和作用: 首先,看下一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多之后的常规方案演进历程. 其次,当服务越来越多之后,我们需要做哪些服务治理? 最后,是d ...

  6. if判断代码 转变为 流程图

    转换规则如下: if 代表一个菱形+问号 if后面的条件代表菱形里的内容+↓yes(向下箭头和yes) if同级的else代表右拐向下箭头和no 执行语句块代表一个矩形. if 今天发工资: 先还信用 ...

  7. Linux 线程实现机制分析 Linux 线程模型的比较:LinuxThreads 和 NPTL

    Linux 线程实现机制分析 Linux 线程实现机制分析  Linux 线程模型的比较:LinuxThreads 和 NPTL http://www.ibm.com/developerworks/c ...

  8. 【剑指offer】旋转数组的最小数字

    一.题目: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个 ...

  9. Knight Moves(hdu1372 bfs模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1372 Knight Moves Time Limit: 2000/1000 MS (Java/Others)   ...

  10. turple list dict 互相转换

    1. 字典(dict) dict = {'name': 'Zara', 'age': 7, 'class': 'First'} 1.1 字典---字符串 print (type(str(dict)), ...