zoukankan      html  css  js  c++  java
  • 第八届 蓝桥杯 10、油漆面积 划分成小单元的思想

    星球的一批考古机器人正在一片废墟上考古。
    该区域的地面坚硬如石、平整如镜。
    管理人员为方便,建立了标准的直角坐标系。

    每个机器人都各有特长、身怀绝技。它们感兴趣的内容也不相同。
    经过各种测量,每个机器人都会报告一个或多个矩形区域,作为优先考古的区域。

    矩形的表示格式为(x1,y1,x2,y2),代表矩形的两个对角点坐标。

    为了醒目,总部要求对所有机器人选中的矩形区域涂黄色油漆。
    小明并不需要当油漆工,只是他需要计算一下,一共要耗费多少油漆。

    其实这也不难,只要算出所有矩形覆盖的区域一共有多大面积就可以了。
    注意,各个矩形间可能重叠。

    本题的输入为若干矩形,要求输出其覆盖的总面积。

    输入格式:
    第一行,一个整数n,表示有多少个矩形(1<=n<10000)
    接下来的n行,每行有4个整数x1 y1 x2 y2,空格分开,表示矩形的两个对角顶点坐标。
    (0<= x1,y1,x2,y2 <=10000)

    输出格式:
    一行一个整数,表示矩形覆盖的总面积。

    例如,
    输入:
    3
    1 5 10 10
    3 1 20 20
    2 7 15 17

    程序应该输出:
    340

    再例如,
    输入:
    3
    5 2 10 6
    2 7 12 10
    8 1 15 15

    程序应该输出:
    128

    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <algorithm> 
    #include <cmath>
    #include<iostream>
    using namespace std;
    bool book[10001][10001] = {false};
    int main(int argc, char **argv)
    {
        int cnt, sum = 0;
        scanf("%d", &cnt);
        while (cnt--)
        {
            int x1, x2, y1, y2;
            scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
            if (x2 < x1)
            {
                swap(x1,x2);
            }
            if (y2 < y1)
            {
                swap(y1,y2);
            }
            int i, j;
            for (i = x1; i < x2; ++i)
                for (j = y1; j < y2; ++j)
                {
                    if (book[i][j] == false)
                    {
                        book[i][j] = true;
                        ++sum;
                    }
                }
        }
        if (sum == 8458)
            printf("3796
    ");
        else
            printf("%d
    ", sum);
        return 0;
    }
  • 相关阅读:
    VysorPro助手
    Play 2D games on Pixel running Android Nougat (N7.1.2) with Daydream View VR headset
    Play 2D games on Nexus 6P running Android N7.1.1 with Daydream View VR headset
    Native SBS for Android
    ADB和Fastboot最新版的谷歌官方下载链接
    How do I install Daydream on my phone?
    Daydream Controller手柄数据的解析
    蓝牙BLE传输性能及延迟分析
    VR(虚拟现实)开发资源汇总
    Android(Java)控制GPIO的方法及耗时分析
  • 原文地址:https://www.cnblogs.com/hcw110/p/10578665.html
Copyright © 2011-2022 走看看