湖南大學第十四屆ACM程式設計新生杯 Dandan's lunch
Dandan's lunch
Description:
As everyone knows, there are now n people participating in the competition. It was finally lunch time after 3 hours of the competition. Everyone brought a triangular bread. When they were going to eat bread, some people found that they solved more problems than others, but their bread was smaller than others. They thought it was very unfair. In this case, they will forcibly exchange bread with the other party (may be exchanged many times, someone can still exchange with others after being exchanged if the above conditions are satisfied, the other party can not refuse).
The description of the bread is given by the coordinates of the three vertices of the triangle. The size of the bread is twice the size of the triangle area, ensuring that there are no two breads of the same size, and the number of problems each person makes is different.
Dandan is also one of the contestants. Now he knows the number of problems solved by each person and the description of the bread they bring. Now he wants to know that after all the exchanges are over (That is, there can be no more exchanges between any two people), The size of the bread he can get.
Input:
The first line gives an integer n, which indicates the number of people who participated in the competition.
Lines 2~n+1, each line gives 7 integers separated by spaces such as:
num x1 y1 x2 y2 x3 y3
num represents the number of the ith personal problem solving. (x1, y1) (x2, y2) (x3, y3) represents the coordinates of the three points of the bread of the triangle with the i-th person. ensure that three points are not in the same line.
Notice that the second line (the first person) represents Dandan's information.
Data guarantee: 0<n<=1e5,0<=num<1e9, -1e8<x1, x2, x3, y1, y2, y3<1e8.
Output:
Outputs an integer representing the size of the bread that DanDan eventually gets.
Sample Input:
1 100000000 0 0 10000 0 0 1000
Sample Output:
10000000
題意:
給出n個三角形的三個頂點座標,求第x大的三角形面積的2倍是多少。(詳見Description)
題解:
就是叉乘求平行四邊形面積,注意下絕對值。後面排個序找一下就好了。
程式碼如下:
#include <cstdio> #include <cstring> #include<algorithm> #include <iostream> #include <queue> #include <cmath> using namespace std; typedef long long ll; const int N = 1e5+5; int n; int a[N]; int main(){ cin>>n; vector <ll> vec; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); int x1,x2,x3,y1,y2,y3; scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); ll vecx1 = x2-x1,vecx2 = x3-x1; ll vecy1 = y2-y1,vecy2 = y3-y1; vec.push_back(vecx1*vecy2-vecy1*vecx2); } sort(vec.begin(),vec.end()); int tmp=a[1]; sort(a+1,a+n+1); for(int i=1;i<=n;i++){ if(a[i]==tmp){ cout<<vec[i-1]; return 0; } } return 0; }