日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces-gym-101020 problem C. Rectangles

發布時間:2024/4/17 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces-gym-101020 problem C. Rectangles 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接: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+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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。