Pages

Thursday 17 January 2013

UVA - 10167 - Birthday Cake

/*You don't have to brute force A from -500 to 500 and B from -500 to 500.
You can brute force A from 0 to 500 and B from -500 to 500  as if (-500,-500) is the same as (500,500) .
*/
#include<stdio.h>
#include<string.h>
#define MAX 101

int x[MAX],y[MAX];

int ans(int A,int B,int n){
    int i,pos=0,neg=0;
    for(i=0;i<2*n;i++){
        int temp=A*x[i]+B*y[i];
        if(temp>0){
            pos++;
        }
        else if(temp<0){
            neg++;
        }else{
            return 0;
        }
    }
    if(pos==neg)
        return 1;
    return 0;
}

int main()
{
    int i,j,n;
    while(1){
        scanf("%d",&n);
        if(n==0)
            break;
        for(i=0;i<2*n;i++){
            scanf("%d %d",&x[i],&y[i]);
        }
        int temp=-1,tempA=-1,tempB=-1;
        for(i=0;i<501;i++){
            for(j=-500;j<501;j++){
                temp=ans(i,j,n);
                if(temp==1){
                    tempA=i;
                    tempB=j;
                    break;
                }
            }
            if(temp==1){
                break;
            }
        }
        printf("%d %d\n",tempA,tempB);
    }
    return 0;
}

No comments:

Post a Comment