UVA 10167 Birthday Cake

题目大意: 给你一个蛋糕(半径为100) 上面有2N个草莓

你的任务是找出一条直线(Ax+By=0)均分这个蛋糕,要求大小相等,草莓数各为N;

输出A B


1. ax+by>0 点在直线上方

     ax+by=0 点过直线

     ax+by<0 点在直线下方


2.-500<=A B<=500  枚举就好 注意不要超时

#include<algorithm>
#include<stdio.h>
#include<iostream>
using namespace std;
int con[50][50];
int n;
bool judge(int a, int b){
	int up = 0, down = 0;
	for (int i = 0; i < 2 * n; i++){
		int m = con[i][0] * a + con[i][1] * b;
		if (m == 0)
			return false;
		else if (m>0)
			up++;
		else
			down++;
	}
	if (up != down)
		return false;
	else
		return true;
}
void solve(){
	int a, b;
	for (a = -500; a <= 500; a++){
		for (b = -500; b <= 500; b++){
			if (!judge(a, b))
				continue;
			else {
				printf("%d %d\n", a, b);
				return ;
			}
		}
	}
}
int main(){
	
	while (scanf_s("%d", &n) ==1 && n){
		for (int i = 0; i < 2 * n; i++){
			scanf_s("%d%d", &con[i][0], &con[i][1]);
		}
		if (judge(0, 1)){
			cout << "0 1" << endl;
			continue;
		}
		solve();
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值