暴力-Birthday Cake
来源:互联网 发布:三星clx3305清零软件 编辑:程序博客网 时间:2024/06/10 20:52
Birthday Cake
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
题意:有2n个樱桃在蛋糕上面,用一条直线把蛋糕从中心分成两半,使樱桃能平均分到两半,并且樱桃不能在直线上
方法:A,B的范围是[-500,500],所以枚举所有的AB,
for(i=-500;i<500;i++)
for(j=-500;j<500;j++)
判断Ax+By<0和Ax+By>0的个数,相等且和为2n则符合
#include<stdio.h>struct node{ int x,y;} s[105];int flag,n;void fun(int A,int B){ int i,cnt1=0,cnt2=0; for(i=0; i<2*n; i++) { if(A*s[i].x+B*s[i].y<0) { cnt1++; } else if(A*s[i].x+B*s[i].y>0) cnt2++; } if(cnt1+cnt2==2*n&&cnt1==cnt2) { flag=1; printf("%d %d\n",A,B); }}int main(){ int i,j; while(scanf("%d",&n)!=EOF&&n!=0) { flag=0; for(i=0; i<2*n; i++) { scanf("%d%d",&s[i].x,&s[i].y); } for(i=-500; i<=500; i++) { for(j=-500; j<=500; j++) { fun(i,j); if(flag==1) break; } if(flag==1) break; } } return 0;}
0 0
- 暴力-Birthday Cake
- UVA -birthday cake(暴力枚举)
- Birthday Cake (uva10167简单暴力枚举)
- Uva 10167 - Birthday Cake 暴力枚举
- uva 10167 Birthday Cake(暴力/枚举)
- uva 10167 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
- IOS7如何获取设备唯一标识
- 判断当前是手机还是平板
- poj 3661——Running
- 文件操作小结(C语言版)
- URIEncoding意义
- 暴力-Birthday Cake
- spring mvc 接收json、xml 数据格式,自动解析成对象
- Linux中文件查找方法大全
- getAttribute()方法与getParameter()区别
- Java常见错误列表
- HEVC 常用之 类TComDataCU分析
- Loadrunner参数化策略详解—适合初学者
- 【杂题】 codeforces 448C Painting Fence
- Linux下修改网卡的mac地址