[UVA] 10167 - Birthday Cake




 Problem
G. Birthday Cake 

Background


Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake
for them.Now we put the cake onto a Descartes coordinate. Its center is at
(0,0), and the cake‘s length of radius is 100.

There are 2N (N is a integer, 1<=N<=50) cherries on the cake. Mother
wants to cut the cake into two halves with a knife (of course a beeline). The
twins would like to be treated fairly, that means, the shape of the two halves
must be the same (that means the beeline must go through the center of the cake)
, and each half must have N cherrie(s). Can you help her?

Note: the coordinate of a cherry (x , y) are two integers. You must give the
line as form two integers A,B(stands for Ax+By=0), each number in the range
[-500,500]. Cherries are not allowed lying on the beeline. For each dataset
there is at least one solution.

Input

The input file contains several scenarios. Each of them consists of 2
parts: The first part consists of a line with a number N, the second part
consists of 2N lines, each line has two number, meaning (x,y) .There is only one
space between two border numbers. The input file is ended with N=0.

Output

For each scenario, print a line containing two numbers A and B. There
should be a space between them. If there are many solutions, you can only print
one of them.

Sample Input


2
-20 20
-30 20
-10 -50
10 -5
0

Sample Output

0 1

题解:暴力枚举+线性规划。A、B都是整数且范围为[-500,500],1<=N<=50,所以暴力枚举即可。统计一下直线一侧点的数目是否为N。注意有点在直线上的情况是不合法的。

代码:


 1 #include<stdio.h>
2 #include<string.h>
3 #include<stdbool.h>
4
5 int i,j,n,m,sum,
6 a[110],b[110];
7
8 int
9 init()
10 {
11 int i;
12 m=2*n;
13 for(i=1;i<=m;i++)
14 scanf("%d%d",&a[i],&b[i]);
15
16 return 0;
17 }
18
19 int
20 main()
21 {
22 int i,j,k,f;
23 while(true)
24 {
25 scanf("%d",&n);
26 if(n==0) break;
27 init();
28 f=0;
29 for(i=-500;i<=500;i++)
30 {
31 for(j=-500;j<=500;j++)
32 {
33 sum=0;
34 for(k=1;k<=m;k++)
35 {
36 if((i*a[k]+j*b[k])<0) sum++;
37 if((i*a[k]+j*b[k])==0) break;
38 }
39 if(sum==n)
40 {
41 f=1;
42 printf("%d %d\n",i,j);
43 break;
44 }
45 }
46 if(f==1) break;
47 }
48 }
49
50 return 0;
51 }
52

 

[UVA] 10167 - Birthday Cake,布布扣,bubuko.com

时间: 2024-12-23 05:38:25

[UVA] 10167 - Birthday Cake的相关文章

uva 10167 Birthday Cake(暴力/枚举)

uva 10167 Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100. There are 2N (N

Brute Force --- UVA 10167: Birthday Cake

 Problem G. Birthday Cake  Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=13&problem=1108&mosmsg=Submission+received+with+ID+14413715 Mean: http://luckycat.kshs.kh.edu.tw/

UVA - 10167 - Birthday Cake (简单枚举)

思路:简单枚举 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; int x[105], y[105]; int main() { int A, B, N; while(scanf("%d", &N), N) { for(int

uva 10167 Birthday Cake(暴力枚举)

....还不是完全自己独立做出来的题目,虽然很暴力,好像是范围为[-500,500],但是题上为什mustn't in呢,我还白痴的用点到直线的距离求个数,判断是在直线上还是下应该直接带入就ok了!!!看是大于0还是小于0,不过通过这个我又知道了点到直线距离公式,之前给忘了,d = abs(Ax+By+c)/sqrt(A*A+B*B) 贴代码了: #include<stdio.h> #include<string.h> #include<stdlib.h> #inclu

Birthday Cake UVA 10167

#include <stdio.h> #define MAXN 100+5 int main(){ int x[MAXN],y[MAXN]; int i,n; int A,B; int P,N,sign; //freopen("data","r",stdin); while(scanf("%d",&n)&&n){ for(i=0;i<2*n;i++) scanf("%d%d",&

UVa 10167 生日蛋糕

题意:有一个半径为100的圆形蛋糕,蛋糕上有一些樱桃.现在妈妈要把蛋糕分两半,因为要均分给两人,所以肯定是从原点切出来的.然后还需要两半蛋糕各含一半数目的樱桃,而且所切的地方不会切到樱桃.求所切下的这条直线的方程,Ax+By=0 中的 A 和 B 的值. cherry 樱桃:beeline 直线:coordinate 坐标 思路:可以看到大体的思路就是找到一条直线,使得所有樱桃的坐标满足 Ax+By>0 和 <0 的个数各一半,而且没有等于0的.而且很容易看到应该不止一条直线,甚至对同一条直线

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

计划,,留

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 一.<算法竞赛入门经典> 刘汝佳 (UVaOJ 351道题) 以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html "AOAPC I"

算法竞赛入门经典+挑战编程+USACO

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发.   一.UVaOJ http://uva.onlinejudge.org  西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ.   二.<算法竞赛入门经典> 刘汝佳  (UVaOJ  351道题)  以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html   "AO