Birthday Cake——直线分割
来源:互联网 发布:关于淘宝店 编辑:程序博客网 时间:2024/06/09 18:15
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 -5010 -50
Sample Output
0 1
题意:一个蛋糕,放了2*N个樱桃,过圆心将这块蛋糕一刀切开,使得每一块都有N个樱桃,
切开的线方程为:Ax+By = 0,已知A,B的范围在【-500,500】求A,B的一个可能值
解析:所求值的范围已给出,可以进行暴力求解,带进去A,B的一个值,如果能将樱桃平均分成两份,直接输出值就可。
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>struct po{ int i,j;};po point[1000];int main(){ int n,x,y,z,a,b,bj = 1,num1,num2; while(~scanf("%d",&n),n) { for(x = 0; x < 2*n; x++) { scanf("%d%d",&point[x].i,&point[x].j); } bj = 1; for(a = -500; a <= 500; a++) { if(a == 0) continue; for(b = -500; b <= 500; b++) { num1 = 0; num2 = 0; for(x = 0; x < 2*n; x++) { if(a*point[x].i + b*point[x].j > 0) num1++; else if(a*point[x].i + b*point[x].j < 0) num2++; else if(a*point[x].i + b*point[x].j == 0) { break; } } if(num1 == num2 && num1 == n) { printf("%d %d\n",a,b); bj = 0; break; } } if(bj == 0) break; } } return 0;}
- Birthday Cake——直线分割
- 10167—Birthday Cake
- UVA 10167 Birthday Cake(判断点在直线的哪边)
- UVA Birthday Cake (一条直线平分草莓)
- Birthday Cake
- Birthday Cake
- Birthday Cake
- Birthday Cake
- Birthday Cake
- UVa 10167 - Birthday Cake
- 10167--Birthday Cake
- UVa:10167-birthday cake
- poj 2515 Birthday Cake
- UVA 10167 Birthday Cake
- uva 10167 - Birthday Cake
- 10167 - Birthday Cake
- UVa 10167 Birthday Cake
- UVaOJ 10167 - Birthday Cake
- C. Anya and Ghosts( Codeforces Round #288 (Div. 2))
- Android Reverse Engineering: Basics -- Tools Usage and Proguard
- SQLSERVER 事务日志查看LogExplore 使用方法
- SQL2005中查看事务日志方法-MS-SQLServer
- 4.2.4 init_post函数
- Birthday Cake——直线分割
- 作为一个程序员,我想,是该有自己的一个博客的时候了
- ACM题集以及各种总结大全!
- Struts 1之DispatchAction
- 拾遗语句
- 实现输入框右侧圆形X图标删除输入框内容,以及获取焦点消除hint
- socket 超时
- 2014一个屌丝程序猿的一天
- Triangle - Leetcode