UVA 10167 Birthday Cake
来源:互联网 发布:乳胶漆配色软件. 编辑:程序博客网 时间:2024/06/17 17:51
分析
对于一条直线
直接枚举所有可能的
思路
因为如果存在一颗樱桃在这个切割线上,那么一定不能如此切割,所以如果存在一点在该线上,那么可以跳过这组
代码
#include <cstdio>#define MAX_N 52int cherries[MAX_N<<1][2];int N;void solve(){ for (int A = -100; A <= 100; A++) for (int B = -100; B <= 100; B++) { int u = 0, d = 0; for (int i = 0; i < (N<<1); i++) if (A*cherries[i][0] + B*cherries[i][1] > 0) u++; else if (A*cherries[i][0] + B*cherries[i][1] < 0) d++; else break; if (u == N && d == N) { printf("%d %d\n", A, B); return; } }}int main(){ while (scanf("%d", &N), N) { for (int i = 0; i < (N<<1); i++) scanf("%d%d", &cherries[i][0], &cherries[i][1]); solve(); } return 0;}
题目
Description
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 2 N (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 mustn’t in [−500, 500]. Cherries are not allowed lying on the beeline. For each data set 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 2 N 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
- UVa 10167 - Birthday Cake
- UVa:10167-birthday cake
- UVA 10167 Birthday Cake
- uva 10167 - Birthday Cake
- UVa 10167 Birthday Cake
- uva 10167 - Birthday Cake
- UVa 10167 Birthday Cake
- uva 10167 - Birthday Cake
- UVa 10167 - Birthday Cake
- uva-10167 - Birthday Cake
- UVA 10167 - Birthday Cake
- uva 10167 Birthday Cake
- UVa 10167Birthday Cake
- uva 10167 Birthday Cake
- uva 10167 Birthday Cake
- UVA 10167 Birthday Cake
- uva 10167--birthday cake
- uva 10167 Birthday Cake
- 博弈论
- 【微信分享】李滔:搜狐基于Spark的新闻和广告推荐实战
- 关于获取textField的textFormat的使用总结
- 俄罗斯轮盘(Russian Roulette)
- DSP、CAN、USB、以太网系统
- UVA 10167 Birthday Cake
- cocos生成keystore及其项目配置的一些BUG
- xcode语法高亮插件
- lua中“类”的实现
- 倾情大奉送--Spark入门实战系列
- 大数据的机遇与挑战:清华、复旦、中科院、春雨移动及考拉征信专家的观点
- Android4.0 Launcher拖拽原理分析
- C++中的单例模式
- 不同环境间FSG报表组件的传输