【百炼oj】1675:Happy Birthday!

描述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.
输入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.输出For each case, output 'Yes' if there is a valid solution, 'No' otherwise.样例输入
2
2 1 1 -1 1 0 -1
10 0 9 1 8 -1 8
样例输出
Yes
No


#include<stdio.h>
#include<math.h>
int main(){
    int check(double a,double b,double c);
    int n,i,j;
    int test[7];
    double a,b,c,pi=atan(1)*4;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<7;j++)
        scanf("%d",&test[j]);
         if((test[1]==0&&test[2]==0)||(test[3]==0&&test[4]==0)||(test[5]==0&&test[6]==0))printf("No\n");
         else{
            a=atan2(test[1],test[2]);
            b=atan2(test[3],test[4]);
            c=atan2(test[5],test[6]);
            if(check(a,b,c))printf("No\n");
                else printf("Yes\n");
        }
    }

}

int check(double a,double b,double c){//判断是否可分
    double temp;
    double pi=atan(1)*4;
    double k[3];
    k[0]=a;
    k[1]=b;
    k[2]=c;
    int i,j;
    for(i=0;i<3;i++){
        for(j=i;j<3;j++){
            if(k[i]>k[j]){
                temp=k[i];
                k[i]=k[j];
                k[j]=temp;
            }
        }
    }
    if(a==b||a==c||b==c)return 1;
    else{
         if((k[2]-k[0])<=2*pi/3)return 1;
         if((2*pi-k[1]+k[0])<=2*pi/3)return 1;
         if((2*pi-k[2]+k[1])<=2*pi/3)return 1;
         return 0;
    }
}

阅读更多
个人分类: 代码
上一篇【百炼oj】2039:反反复复
下一篇【百炼oj】1001:Exponentiation
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭