zoukankan      html  css  js  c++  java
  • Rectangles

    You have n rectangles, each of which is described by three integers i, j and k. This indicates that the lower-left corner of the rectangle will be located at the point (i, 0) and the upper-right corner of the rectangle will be located at the point (j, k). For example, if you have a description of four rectangles like this: 0 2 3 0 3 1 1 2 2 2 4 4 The area occupied by these rectangles will be as follows:

    The total area in this case will be 14. You are given n and n triples (i, j, k), your task is to compute the total area occupied by the rectangles which are described by the n triples.

    Input

    The first line will contain a single integer T indicates the number of test cases. Each test case will consist of n + 1 lines, the first one will contain the number of rectangles n and the following n lines will be the description of the rectangles. Each description will be a triple (i, j, k) as mentioned above. The Constraints: 10 <= T <= 20 1 <= n <= 100 0 <= i < 100 1 <= j < 100 i != j 1 <= k <= 100

    Output

    For each test case, print a single integer in a separated line indicates the total area occupied by the rectangles.

    Examples

    input

    Copy

    1
    4
    0 2 3
    0 3 1
    1 2 2
    2 4 4
    

    output

    Copy

    14
    
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    using namespace std;
    int main()
    {
       int t,n,j,i,k,o,x,y,s,c[300][300];
       scanf("%d",&t);
       while(t--)
       {
           memset(c,0,sizeof(c));
           s=0;
           scanf("%d",&n);
           for(i=0;i<n;i++)
           {
               scanf("%d%d%d",&x,&y,&o);
               for(j=x;j<y;j++)
                   for(k=0;k<o;k++)
                       c[j][k]++;
            }
           for(j=0;j<110;j++)
           {
               for(k=0;k<110;k++)
               {
                   if(c[j][k]>0)
                       s++;
               }
           }
           printf("%d
    ",s);
       }
       return 0;
    }
  • 相关阅读:
    springcloud12-spring cloud stream
    Linux上安装gitbook并拉取git项目编译
    Python 之一条命令生成项目依赖包文件 requirements.txt
    python跨模块使用全局变量的实现方法
    微信朋友圈测试用例
    linux安装maven
    jenkins上集成sonar
    windows上安装sonar并使用其分析项目
    jquery 点击同级元素隐藏,再点击显示
    10进制转16进制自动补全8位 并高低位转换
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702821.html
Copyright © 2011-2022 走看看