Birthday Cake——直线分割
2015-01-29 08:21
579 查看
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 partconsists 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 onlyprint one of them.
Sample Input
2 -20 20 -30 20 -10 -50 10 -5 0
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; }
相关文章推荐
- [CareerCup] 7.5 A Line Cut Two Squares in Half 平均分割两个正方形的直线
- 亚像素边缘的直线及圆弧的基元分割
- HDU Problem M [ 折线分割 ]——基础dp直线分割变式
- 直线分割平面
- acm 3 1014 直线分割平面
- hdu1466计算直线的交点数&2050 折线分割平面【DP】
- 直线、折线、封闭曲线、平面分割平面的总结
- 直线分割平面、分割空间
- 关于直线,V形线,Z形线,M形线分割平面的总结
- 直线,折线,曲线分割平面以及平面分割空间问题
- BZOJ 1091([SCOI2003]分割多边形-分割直线)
- Android在布局文件中加一条分割直线
- 直线,折线,曲线分割平面以及平面分割空间问题
- 直线,折线,曲线分割平面以及平面分割空间问题
- 第九章 – 图像局部与分割 – 视频中是直线像素采样(cvInitLineIterator )
- 第九章 – 图像局部与分割 – 视频中是直线像素采样(cvInitLineIterator )
- 自动阈值分割-场景中直线个数的检测
- UVA Birthday Cake (一条直线平分草莓)
- 关于直线、折线分割平面,平面的分割空间问题
- hdu 2050 折线分割平面(解析,直线,平行线,折线,三角形)