Rectangles

原创 2018年04月15日 12:30:11

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\n",s);
   }
   return 0;
}



P - Rectangles

Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have t...
  • qq_30796379
  • qq_30796379
  • 2017-11-01 21:18:05
  • 125

D - Rectangles

Byteman has a collection of N squares with side 1. How many different rectangles can he form using t...
  • sdnuzsj
  • sdnuzsj
  • 2017-01-23 18:31:31
  • 153

750. Number Of Corner Rectangles

Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner rectan...
  • zjucor
  • zjucor
  • 2017-12-17 13:01:27
  • 403

PAT (Top Level) Practise 1011 Cut Rectangles (35)

1011. Cut Rectangles (35) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B ...
  • jtjy568805874
  • jtjy568805874
  • 2016-03-15 17:17:24
  • 737

杭电2056Rectangles

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot...
  • z2664836046
  • z2664836046
  • 2016-08-22 20:58:34
  • 168

杭电2056之Rectangles 杭电

Problem Description Given two rectangles and the coordinates of two points on the diagonals of each...
  • ESESZB
  • ESESZB
  • 2017-03-05 13:17:43
  • 191

USACO Packing Rectangles

Packing Rectangles IOI 95   The six basic layouts of four rectangles Four rectangles are given...
  • u012797220
  • u012797220
  • 2014-02-02 09:06:07
  • 1432

hdu1506 Largest Rectangle in a Histogram

Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3276...
  • qiqijianglu
  • qiqijianglu
  • 2013-01-30 16:42:07
  • 2493

HDU2056 Rectangles 【矩形面积交】

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...
  • u012846486
  • u012846486
  • 2015-01-19 10:26:30
  • 1363

HDU 2056 Rectangles(矩形面积交)

【题意】给你两个平行与X-Y坐标轴的矩形,求相交面积 【思路】直接判断,把坐标从小到大排序一遍,确定能够相交的情况下求出面积,X坐标之差*Y坐标之差即可 代码: #include using nam...
  • u013050857
  • u013050857
  • 2016-02-10 13:17:20
  • 557
收藏助手
不良信息举报
您举报文章:Rectangles
举报原因:
原因补充:

(最多只允许输入30个字)