UVA 10167 Birthday Cake

开始一看,以为还是极角排序加扫描线呢。后来发现不好弄啊,如果有很多位置,那么我扫到一个cherries 但是正好在满足题意的边界上,我随便加个eps应该就行了吧?

后来再一看 = =。。。A B要求是整数,而且范围在-500到500,这个好办了。直接枚举每个 A  B ,然后判断是否满足题意即可。

注意处理cherries 在线上的状况。

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")

using namespace std;

const int MAX = 100;
struct point {double x,y;};
point p[MAX];

double t[MAX];

void solve(int n,int &a, int &b)
{
	for(int i=-500; i<=500; i++)
		for(int k=-500; k<=500; k++)
		{
			if( i == k && k == 0 ) continue;
			int cnt = 0;
			for(int j=0; j<n; j++)
			{
				if( i*p[j].x + k*p[j].y == 0 )
				{
					cnt = 0;
					break;
				}
				if( i*p[j].x + k*p[j].y > 0 )
					cnt++;
			}
			if( cnt == n/2 )
			{
				a = i;
				b = k;
				return ;
			}
		}
}

int main()
{
    int n;
    
    while( ~scanf("%d", &n) && n )
    {
        int sum = n;
        n *= 2;
        for(int i=0; i<n; i++)
			scanf("%lf%lf", &p[i].x, &p[i].y);
		int a,b;
		solve(n, a, b);
		printf("%d %d\n",a, b);
	}

return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值