题目链接: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
1
4
0 2 3
0 3 1
1 2 2
2 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+;
int a[];
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
memset(a,,sizeof(a));
cin>>n;
int sum=;
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=;i<=;i++)
sum+=a[i];
cout<<sum<<endl;
}
return ;
}

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 100342C Problem C. Painting Cottages 转化题意

    Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  3. Codeforces Gym 100342C Problem C. Painting Cottages 暴力

    Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...

  4. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  5. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  6. Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP

    Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10061 ...

  7. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

  8. Codeforces Gym 100610 Problem E. Explicit Formula 水题

    Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  9. Codeforces Gym 100002 Problem F "Folding" 区间DP

    Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...

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

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

随机推荐

  1. redis调优的实战经验

    本文根据redis的info命令查看redis的内存使用情况以及state状态,来观察redis的运行情况以及需要作出的相应优化. info 1.memory used_memory:13409011 ...

  2. EXPERT FOR SQL SERVER诊断系列--索引

    概述   索引设计是数据库设计中比较重要的一个环节,对数据库的性能起着至关重要的作用,但是索引的设计却又不是那么容易的事情,性能也不是那么轻易就获取到的,很多的技术人员因为不恰当的创建索引,最后使得其 ...

  3. Lustre文件系统部署和应用探索

    1. Lustre文件系统概述 2. Lustre文件系统部署 2.1 基本环境 本篇博客将在KVM虚拟机中部署Lustre文件系统. 操作系统版本为CentOS6.5_x86_64.Lustre软件 ...

  4. 基于HTML5 Canvas WebGL制作分离摩托车

    工业方面制作图表,制作模型方面运用到 3d 模型是非常多的,在一个大的环境中,构建无数个相同的或者不同的模型,构建起来对于程序员来说也是一件相当头疼的事情,我们利用 HT 帮大家解决了很大的难题,无数 ...

  5. Scrum与看板区别

    看板:在制品(work-in-progress, WIP)必须被限制 WIP上限和拉动式生产   1. Scrum与看板简述 Scrum:组织拆分,工作拆分,开发时间拆分,优化发布计划,过程优化 看板 ...

  6. ajax多级菜单栏

    1.jsp 首先ajax查询数据 <script type="text/javascript"> function targetlist() { $.ajax({ ur ...

  7. ChangeSort

    package com.home.test; import java.util.Arrays; public class ChangeSort { public String[] changeLoca ...

  8. C++高质量编程笔记

    /* * 函数介绍: * 输入参数: * 输出参数: * 返回值 : */ void Function(float x, float y, float z) { - } if (-) { - whil ...

  9. sqlalchemy orm 操作 MySQL

    一.ORM介绍 orm英文全称object relational mapping,是对象映射关系程序,简单来说类似python这种面向对象的程序来说一切皆对象,但是我们使用的数据库却都是关系型的,为了 ...

  10. 【Java集合的详细研究4】Java中如何遍历Map对象的4种方法

    方法一 通过Map.entrySet遍历key和value,在for-each循环中使用entries来遍历.推荐,尤其是容量大时 这是最常见的并且在大多数情况下也是最可取的遍历方式.在键值都需要时使 ...