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,1,2,2)+(3,3,4,4)
(1,1,3,3)+(2,2,4,4)+(5,5,6,6)
 

Sample Output
  1.  
2
8

思路:

一开始想到用一个二维数组当做坐标轴平面,然后一个一个方块去标记,最后数出来有多少方块。但是输入很坑,看着很麻烦。面积填涂也很坑,不能直接把x1,x2,y1,y2填上,因为数组中(x1,y1)是一个方块而坐标轴中(x1,y1)是一个点。

Code:

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #include<cctype>
  5. #include<queue>
  6. #include<math.h>
  7. #include<iostream>
  8. #include<algorithm>
  9. #define INF 0x3f3f3f3f
  10. #define N 1005
  11. using namespace std;
  12. int map[N][N];
  13. int num(char x){
  14. if(x>='0' && x<='9') return 1;
  15. return 0;
  16. }
  17. int main(){
  18. int len,x[4],count,sum;
  19. char s[510];
  20. while(gets(s)){
  21. memset(map,0,sizeof(map));
  22. len=strlen(s);
  23. count=0;
  24. sum=0;
  25. for(int i=0;i<len;i++){
  26. if(num(s[i])==1){
  27. x[count]=s[i]-'0';
  28. i++;
  29. while(num(s[i])==1){
  30. x[count]=x[count]*10+(s[i]-'0');
  31. i++;
  32. }
  33. count++;
  34. }
  35. if(count==4){
  36. int x1=min(x[0],x[2]);    //保证后面遍历大小不会错
  37. int x2=max(x[0],x[2]);
  38. int y1=min(x[1],x[3]);
  39. int y2=max(x[1],x[3]);
  40. for(int j=x1;j<x2;j++){    //这里要注意后面的<而不是<=,理由就是上面说到的
  41. for(int k=y1;k<y2;k++){
  42. map[j][k]=1;
  43. }
  44. }
  45. count=0;
  46. }
  47. }
  48. for(int i=0;i<N;i++){
  49. for(int j=0;j<N;j++){
  50. if(map[i][j]==1) sum++;
  51. }
  52. }
  53. printf("%d\n",sum);
  54. }
  55. return 0;
  56. }

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. 2018/03/28 每日一个Linux命令 之 mkdir/rmdir

    用于建立空文件夹和删除文件夹 -- 两命令重要参数 -p 递归建立/删除 -- 例如 mkdir -p demo1/demo2/demo3 建立demo3空文件夹,如果demo1/demo2没建立也建 ...

  2. 2018/03/25 每日一个Linux命令 之 df

    Linux df命令用于显示目前在Linux系统上的文件系统的磁盘使用情况统计. 就像在windows下打开我的电脑一样会统计各个磁盘一样的情况 主要用于查看磁盘空间占用情况 -- [@hong:~] ...

  3. Ubuntu14.04+eclipse下cocos2d-x3.0正式版环境的搭建

    环境: ubuntu14.04 adt-bundle-linux-x86_64 android-ndk-r9d-linux-x86_64 cocos2d-x-3.0正式版 apache-ant 1.9 ...

  4. 万恶之源 - Python文件操作

    文件操作 初始文件操作 使用Python来读写文件是非常简单的操作,我们使用open()函数来打开一个文件,获取到文件句柄,然后通过文件句柄就可以进行各种各样的操作了 根据打开方式的不同能够执行的操作 ...

  5. [py][mx]django get方法返回login页面

    get方法返回login.html users/views.py def login(request): if request.method == "POST": pass eli ...

  6. kvm日常管理

    创建虚拟机 快速启动虚拟机 [root@localhost ~]# yum install kvm libvirt python-virtinst qemu-kvm virt-viewer bridg ...

  7. [LeetCode] All questions numbers conclusion 所有题目题号

    Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...

  8. EXTJS 4.2.1.883 Summary 合计栏宽度bug

    EXTJS 4.2.1.883中改进了summary插件,使合计栏能够在grid最底部显示,但是列宽和表格对不上,解决方法: 找到以下样式 .x-docked-summary .x-grid-tabl ...

  9. OpenCV中对Mat里面depth,dims,channels,step,data,elemSize和数据地址计算的理解 (转)

    cv::Matdepth/dims/channels/step/data/elemSizeThe class Mat represents an n-dimensional dense numeric ...

  10. 剑指offer4

    中序遍历(LDR)是二叉树遍历的一种,也叫做中根遍历.中序周游.在二叉树中,先左后根再右.巧记:左根右. 现在有一个问题,已知二叉树的前序遍历和中序遍历:PreOrder:         GDAFE ...