Sicily 1741. Jaunt around the Zhuhai Campus
来源:互联网 发布:linux打开telnet服务 编辑:程序博客网 时间:2024/06/03 23:58
Time Limit: 1 secs, Memory Limit: 32 MB
Description
The 1st Annual Guangdong Collegiate Programming Contest (GDCPC) was held in Zhuhai Campus of Zhongshan(SunYat-Sen) University last year. And now we gather again for the 2nd GDCPC in the same wonderful place. After the contest, most of the participants will probably have a jaunt around the beautiful Campus.
As you have seen, the main attraction of this place is the green hills surrounding. And a problem comes up now. What is the area of cross section of the hills?
This range of hills contains peaks and valleys. So before calculating the area, we have to firstly scale and write down the coordinates of the turning points. In the following graph, 7 turning points of a hill are marked.
Input
The first line of the input is a positive integer T.T is the number of the test cases followed.
The first line of each test cases contains only one positive integer N(1< N<=1000) which represents the number of the turning points. Then N lines follow and the ith line contains two nonnegative integers Xi(0<=Xi<=10000),Yi(0<=Yi<=10000) which represent the coordinate of the ith turning point. It is assumed that the given turning points is in X-coordinate increasing order, i.e. Xi< Xj when i< j.
Output
The output of the program should consist of one line of output for each test case. The output of each test case only contains one real number which represents the area of the cross section of the hills. The real numbers are rounded to one decimal digit. No redundant spaces are needed.
Sample Input
2
2
1 4
3 4
2
2 7
3 9
Sample Output
8.0
8.0
(^∀^●)ノシ 题目比较长,不过大意还是比较好理解的。即输入一些在平面直角坐标系中的顶点坐标计算面积——转化为计算一个一个相邻梯形面积即可。get?
#include <iostream>#include <iomanip>#include <vector>using namespace std;typedef pair<double, double> point;inline double getArea(point& p1, point& p2){ return (p1.second + p2.second) * (p2.first - p1.first) / 2;}int main(){ int T, N; double S, x, y; vector<point> pro; cin >> T; while (T--) { S = 0; cin >> N; pro.clear(); while (N--) { cin >> x >> y; pro.push_back(make_pair(x, y)); } for (int i = 0; i < pro.size() - 1; i++) S += getArea(pro[i], pro[i + 1]); cout << fixed << setprecision(1) << S << endl; } return 0;}
- Sicily 1741. Jaunt around the Zhuhai Campus
- 1741.Jaunt around the Zhuhai Campus
- 1741. Jaunt around the Zhuhai Campus (梯形面积)
- Sicily 1031. Campus
- Sicily 1031. Campus
- [sicily online]1031. Campus
- Sicily 1031 Campus
- sicily 1031. Campus
- Sicily 1031. Campus
- Sicily 1031. Campus
- sicily 1031.Campus
- Sicily 1031 Campus
- sicily 1031. Campus
- sicily 1006. Campus
- #sicily#1003.campus
- Sicily: Campus(Floyd-Warshall算法)
- life on the campus
- 10397 - Connect the Campus
- 文章标题
- 简单总结2015股市
- @property 的基本认识
- 安卓相对布局的基本属性
- 2015年度引进版技术书TOP10
- Sicily 1741. Jaunt around the Zhuhai Campus
- android之旅23 多媒体处理2: 画画板
- Ajax异步验证用户名是否已经存在
- Linux基本的命令与快捷建(在centos版本下)
- TableView Segues
- 【南理oj】6 - 喷水装置(一)(贪心)
- 如何制作gif图片?如何制作你项目的动态效果图到你的csdn?
- binder驱动-接收缓存区管理
- 委托