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

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

Output

14

AC代码(二维数组记录就可以)

elect Code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int mp[110][110];
    int t, i, j, a, b, c, n;
    scanf("%d",&t);
    while(t--)
    {
        long long sm = 0;
        memset(mp, 0, sizeof(mp));
        scanf("%d",&n);
       while(n--)
       {
           scanf("%d %d %d",&a, &b, &c);
           for(i = a;i<b;i++)
           {
               for(j = 0;j<c;j++)
               {
                   mp[i][j] = 1;
               }
           }
       }
       for(i = 0;i<110;i++)
       {
           for(j = 0;j<110;j++)
           {
               if(mp[i][j])
                sm++;
           }
       }
       printf("%lld\n",sm);
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_41524782/article/details/81357745