Codeforces-gym-101020 problem C. Rectangles
题目链接:http://codeforces.com/gym/101020/problem/C
2.0 s
64 MB
standard input
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.
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
For each test case, print a single integer in a separated line indicates the total area occupied by the rectangles.
1
4
0 2 3
0 3 1
1 2 2
2 4 4
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的更多相关文章
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342C Problem C. Painting Cottages 转化题意
Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100342C Problem C. Painting Cottages 暴力
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...
- Codeforces Gym 100500F Problem F. Door Lock 二分
Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...
- Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...
- 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 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100002 Problem F "Folding" 区间DP
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/ ...
- Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...
随机推荐
- SERDES关键技术总结
转自https://www.cnblogs.com/liujinggang/p/10125727.html 一.SERDES介绍 随着大数据的兴起以及信息技术的快速发展,数据传输对总线带宽的要求越来越 ...
- IOS 上架到App Store被拒的常见问题总结
Guideline 2.3.3 - Performance - Accurate Metadata 2017年11月16日 上午12:52 发件人 Apple 2. 3 Performance: Ac ...
- 干货,比较全面的c#.net公共帮助类(Common.Utility)
Common.Utility 初衷 网上有各式各样的帮助类,公共类,但是比较零碎,经常有人再群里或者各种社交账号上问我有没有这个helper,那个helper,于是萌生了收集全部helper的念头,以 ...
- Object-Oriented(一)创建对象
自用备忘笔记 前言 虽然可以使用 Object 和对象字面量创建对象,但是如果要创建大量相似的对象又显得麻烦.为解决这个问题,人们开始使用工厂模式的变种. 工厂模式 function person(n ...
- linux下core file size设置笔记
现象说明:突然发现一台测试机器的java程序莫名其妙地没了,但是没有core dump!这就需要打开服务器的core文件生成的功能了,(即core dump文件),方便程序调试.1)core文件简介c ...
- 【BUAA软件工程】第一次阅读作业
BUAA软件工程 第一次阅读作业 项目 内容 这个作业属于哪个课程? 北航软工 这个作业的要求在哪里? 第一次个人作业 我在这个课程的目标是? 学习高效严谨的软件工程开发过程,建立团队意识 这个作业在 ...
- 个人项目Individual Project:n皇后问题
源码的github链接: https://github.com/luhan420/test/tree/master 1.需求分析 在本次的课程设计中,用到的知识点主要有:类.函数.选择结构里的条件语 ...
- 软件工程项目之摄影App
摄影app 开发人员:Ives & Dyh 开发功能: 摄影师注册与认证,为年轻摄影师提供成长的空间,发挥一技之长的平台. 用户注册与验证,为有摄影需求的人提供选择摄影师进行个性化拍摄的平台. ...
- Windows 7 64位安装cURL
安装cURL. 1, 下载64位的SSL版cURL,网址: http://curl.download.nextag.com/download/curl-7.21.7-win64-ssl-sspi.zi ...
- ubuntu16.04下载安装navicate
1.下载试用版本地址: https://www.navicat.com.cn/download/navicat-premium 2.解压缩 tar -zxvf /home/rain/download ...