UVA10167-birthday cake
2016-05-08 19:04
351 查看
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.![](http://uva.onlinejudge.org/external/101/p10167.gif)
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
#include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; struct point { double x,y; } p[105]; void solve(int n,int &a, int &b) { for(int i=-500; i<=500; i++) { for(int k=-500; k<=500; k++) { if( i == k && k == 0 ) continue; int cnt = 0; for(int j=0; j<n; j++) { if( i*p[j].x + k*p[j].y == 0 ) break; if( i*p[j].x + k*p[j].y > 0 ) cnt++; } if( cnt == n/2 ) { a = i; b = k; } } } } int main() { int n; while( ~scanf("%d", &n) && n ) { n *= 2; for(int i=0; i<n; i++) scanf("%lf%lf", &p[i].x, &p[i].y); int a,b; solve(n, a, b); printf("%d %d\n",a, b); } return 0; }
相关文章推荐
- eclipse.ini/myeclipse.ini文件中参数配置
- Ubuntu内存清理
- Area of Circle
- 后缀自动机SAM
- Navicat备份远程Oracle数据库到本地
- 简单操作只需10秒破解PDF加密文件
- 使用memadmin可视化监视我们的memcache
- 第一章:简介
- RBAC权限管理
- 轻量级应用开发之(10) UINavigationController导航控制器
- 初识Linux
- 5. sql*plus
- 4. Oracle PL/SQL语言及编程
- Android ListView的不同样式,getItemViewType,getViewTypeCount
- Codeforces 16E Fish (状压dp+概率)
- 小范围排序
- 3. SQL语言基础
- VI快捷键
- ORA-01291: missing logfile 事务闪回缺失日志
- 数列基础