题目链接:http://codeforces.com/gym/101020/problem/C

C. Rectangles
time limit per test

2.0 s

memory limit per test

64 MB

input

standard input

output

standard output

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

140 2 30 3 11 2 22 4 4

Output

Copy

14题意概括:你有n个矩形,每个矩形由三个整数i,j和k描述。这表示矩形的左下角将位于点(i,0),矩形的右上角将位于点(j,k)。例如,如果您有四个这样的矩形的描述:0 2 3 0 3 1 1 2 2 2 4 4这些矩形占用的区域如下:在这种情况下,总面积为14.您将获得n和n三元组(i,j,k),您的任务是计算由n个三元组描述的矩形占据的总面积。输入第一行将包含单个整数T表示测试用例的数量。每个测试用例由n + 1行组成,第一行包含矩形n的数量,后面的n行将是矩形的描述。如上所述,每个描述将是三(i,j,k)。约束:10 <= T <= 20 1 <= n <= 100 0 <= i <100 1 <= j <100 i!= j 1 <= k <= 100输出对于每个测试用例,在单独的行中打印单个整数表示矩形占用的总面积。解题思路:看似很复杂,会有很多重复的不只如何下手,其实我们只需要简单定义一个数组,记录每一竖的小矩形的面积,每次输入新的矩形时,只需要比较新的矩形在每个小矩形与原来的是否更高了,如果更高了,就该成新的高度,否则不变。具体详见代码:
#include<iostream>
#include<string.h>
typedef long long ll;
const int maxn=1e6+60;
int a[105];
using namespace std;
int main()
{int t;cin>>t;while(t--){int n;memset(a,0,sizeof(a));cin>>n;int sum=0;while(n--){int x,y,z;cin>>x>>y>>z;for(int i=x;i<y;i++){if(a[i]<z) a[i]=z; //如果横坐标为i的小矩形的高度小于新矩形的高度,则更新
            }    }for(int i=0;i<=100;i++)sum+=a[i];cout<<sum<<endl;}return 0;} 

转载于:https://www.cnblogs.com/zjl192628928/p/9280159.html

Codeforces-gym-101020 problem C. Rectangles相关推荐

  1. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  2. Codeforces Gym 100623I Problem I. Important Wires

    题目传送门:http://codeforces.com/gym/100623/attachments 题解:这道题...说了一大堆没用的....如果你看了题不会做再看代码...你会大喊我去.... C ...

  3. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  4. Codeforces Gym 100187M M. Heaviside Function two pointer

    M. Heaviside Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/ ...

  5. Codeforces Gym 100187D D. Holidays 排列组合

    D. Holidays Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/D ...

  6. Codeforces gym 100685 A. Ariel 暴力

    A. Ariel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Des ...

  7. Codeforces gym 100685 C. Cinderella 水题

    C. Cinderella Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/ ...

  8. codeforces Gym 100187B B. A Lot of Joy

    B. A Lot of Joy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/proble ...

  9. Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks

    Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...

最新文章

  1. 在Kubernetes v1.8中使用RBAC
  2. LeetCode 42. Trapping Rain Water--算法题--c++解法
  3. android开发获取应用本身耗电量_别找了,Android常用自动化工具全在这儿了!
  4. c语言后缀表达式构造二叉树,C ++程序为后缀表达式构造表达式树
  5. 一个好用的查看Angular应用ngrx状态的Chrome扩展:Redux devTools
  6. java小程序 2048_微信小程序之游戏2048
  7. 计划任务,机器码与注册码,Web服务
  8. 【附源码】计算机毕业设计SSM汽车租赁系统
  9. Django开发教程 第一节 HelloWorld
  10. 光学遥感和微波遥感异同点?影响微波散射的因素有哪些?
  11. 戴尔_从偶像派到实力派【我身边的戴尔企业级解决方案】
  12. linux与windows内核哪个难学,国产操作系统为何都基于Linux内核?又和Windows像?
  13. 整理了一波年终总结模版,速领!
  14. ECl@SS学习笔记(1)
  15. 重磅炸弹 诺基亚N71简体中文版全国抢先预览
  16. 面向协议与面向对象的区别
  17. LabVIEW学习笔记十三:窗格详解(调整窗格大小时缩放特定对象)
  18. Unity地面拼接实现无限路循环
  19. 贝叶斯方法(实例1)——概率分布
  20. 大数据 + VR 全景技术重塑“二手车买车场景”

热门文章

  1. 关于逆元的概念、用途和可行性的思考(附51nod 1013 和 51nod 1256)
  2. 防火墙(6)—— -d的用法
  3. 2019牛客暑期多校训练营(第十场)C - Gifted Composer (二分+哈希)
  4. POJ 2229 Sumsets
  5. java中ftp删除文件,Java 实现ftp 文件上传、下载和删除
  6. tail | grep引起的内存升高【对比三天数据】
  7. 重载和引用函数编程实验
  8. linux rm 不释放_linux删除文件空间不释放问题解决
  9. 一般纳米材料是指尺度为_纳米材料及纳米材料在高分子领域的应用
  10. 计算机的主存储器可以分为哪两类,2017年计算机应用基础模拟试题「答案」(2)...