前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDU 1866 A + B forever!

HDU 1866 A + B forever!

作者头像
ShenduCC
发布2018-04-26 16:05:22
5420
发布2018-04-26 16:05:22
举报
文章被收录于专栏:算法修养算法修养

A + B forever!

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

Total Submission(s): 1171    Accepted Submission(s): 268

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

代码语言:javascript
复制
(1,1,2,2)+(3,3,4,4)
(1,1,3,3)+(2,2,4,4)+(5,5,6,6)

Sample Output

代码语言:javascript
复制
2
8
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
int a[1005][1005];
char b[505];
int d[6];
int main()
{
    while(gets(b))
    {
    int len=strlen(b);
    memset(a,0,sizeof(a));
    int ans=0;
    for(int i=0;i<len;i++)
    {
        if(b[i]=='(')
        {
            int num=0;
            int cot=0;int p;int mark=0;
            for( p=i+1;cot<4;p++)
            {
                if(isdigit(b[p]))
                {
                    num=num*10+b[p]-'0';
                    mark=1;
                }
                else if(!mark)
                    continue;
                else
                {
                    d[++cot]=num;
                    num=0;
                    mark=0;
                }
            }
            i=p;
            int x1=min(d[1],d[3]);
            int x2=max(d[1],d[3]);
            int y1=min(d[2],d[4]);
            int y2=max(d[2],d[4]);
            for(int j=x1;j<x2;j++)
            {
                for(int k1=y1;k1<y2;k1++)
                {
                    if(!a[j][k1])
                    {
                        a[j][k1]=1;
                        ans++;
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
    }
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-04-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • A + B forever!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档