Happy Birthday!
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4180 | Accepted: 1039 |
Description
There are three berries on a round birthday cake. You are required to divide the cake into three identical parts such that each part contains exactly one berry. To make it easy, it is assumed that the radius of the berries is 0 and each part of the cake is a sector with 120 degrees. Any line that divides the cake should not go through any berry.
Input
The first line contains a single integer t (1 <= t <= 20) that indicates the number of test cases. Then follow the t cases. Each case contains exactly 7 integers r, x1, y1, x2, y2, x3 and y3. r is the radius of the cake, (xi, yi) is the coordinates of i-th berry. The center of the cake is at (0, 0) and it's confirmed that all the berries will be on the cake.
Output
For each case, output 'Yes' if there is a valid solution, 'No' otherwise.
Sample Input
2 2 1 1 -1 1 0 -1 10 0 9 1 8 -1 8
Sample Output
Yes No 题目大意:给你一个圆心在原点,半径为R的圆,并给出三个果仁的坐标,问是否能够平均切三刀,让这三颗果仁恰好位于圆的三个部分。 思路:因为平均切三刀,那么每一部分的圆心角度数都为120°,那么如果有其中两颗果仁的夹角大于等于120°那我们就可以得到题目的要求将其均分成三块且每一块里面恰好 有一颗果仁,而如果任意两颗果仁的夹角都小于120°那么我们将无法均分三刀让每一部分都有一颗果仁,也就是说必然会有一个部分没有果仁的存在。具体可以画图用于理解。 因此做法很简单,枚举任意两颗果仁的夹角,求出夹角的最大值,看最大值是否大于等于120°即可。 一个坑:如果这三颗果仁任意一颗在原点。。那么你将永远不能将其使得每一部分都含有一颗果仁。。为此WA了一次。。。#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; const double pi=3.1415926; int main() { int t; cin>>t; while(t--) { double r; double x1,y1,x2,y2,x3,y3; cin>>r>>x1>>y1>>x2>>y2>>x3>>y3; double angl1; double angl2; double angl3; if((x1==0&&y1==0)||(x2==0&&y2==0)||(x3==0&&y3==0)) { cout<<"No"<<endl; } else { angl1=acos(((x1*x1+y1*y1)+(x2*x2+y2*y2)-((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)))/(2*sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2))); angl2=acos(((x1*x1+y1*y1)+(x3*x3+y3*y3)-((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)))/(2*sqrt(x1*x1+y1*y1)*sqrt(x3*x3+y3*y3))); angl3=acos(((x2*x2+y2*y2)+(x3*x3+y3*y3)-((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)))/(2*sqrt(x2*x2+y2*y2)*sqrt(x3*x3+y3*y3))); angl1=angl1*180/pi; angl2=angl2*180/pi; angl3=angl3*180/pi; double maxn; maxn=max(angl1,angl2); maxn=max(maxn,angl3); if(maxn<120) { cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } } } return 0; }