uva10167 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 mustn't in
[500;500]. Cherries are not allowed lying on the beeline. For each dataset there is at least one solution.
Input
The input le contains several scenarios. Each of them consists of 2 parts:
The rst 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 le
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
题目大意如下:平面直角坐标系中有一个以(0,0)为圆心,半径为100个单位长度的圆,圆内有一些点,求一条直线正好把所有点分成数量相等的两半,且没有点在直线上。
思路:枚举,外加一点初中知识。
来源:virtual judge
| 6714905 | 
 Accepted 
 | 
0 | 665 | 
 2016-08-02 17:26:10 
 | 
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int n,chy[101][2];
bool judge(int A,int B)
{
int cnt[2]={0,0};
for(int i=1;i<=(n<<1);i++){
int tmp=A*chy[i][0]+B*chy[i][1];
if(!tmp)
return false;
cnt[tmp<0]++;
}
return cnt[0]==n&&cnt[1]==n;//保证两边确实都有n个cherries,没有任何一个cherry在直线上;
}
void solve()
{
for(int i=-100;i<=100;i++)//圆的半径仅为100个单位长度;
for(int j=-100;j<=100;j++){
if(!j)continue;
if(judge(i,j)){
printf("%d %d\n",i,j);
return;
}
}
}
int main()
{
while(scanf("%d",&n)&&n){
for(int i=1;i<=(n<<1);i++)
scanf("%d%d",&chy[i][0],&chy[i][1]);
solve();
}
return 0;
}
/*
Sample input
2
-20 20
-30 20
-10 -50
10 -5
0
Sample output
0 1
*/
uva10167 Birthday Cake的更多相关文章
- 备战NOIP每周写题记录(一)···不间断更新
		
※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...
 - Windows 7上执行Cake 报错原因是Powershell 版本问题
		
在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...
 - 2015暑假多校联合---Cake(深搜)
		
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
 - Scalaz(15)- Monad:依赖注入-Reader besides Cake
		
我们可以用Monad Reader来实现依赖注入(dependency injection DI or IOC)功能.Scala界中比较常用的不附加任何Framework的依赖注入方式可以说是Cake ...
 - HDU  4762  Cut the Cake(公式)
		
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
 - Brute Force --- UVA 10167: Birthday Cake
		
Problem G. Birthday Cake Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudg ...
 - 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake
		
Description Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping ...
 - hdu acmsteps 2.1.3 Cake
		
Cake Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
 - ZOJ 3905 Cake ZOJ Monthly, October 2015 - C
		
Cake Time Limit: 4 Seconds Memory Limit: 65536 KB Alice and Bob like eating cake very much. One ...
 
随机推荐
- [outlook]打开以后就自动进入安全模式的解决方法。Outlook start in safe mode.
			
给客户写了一个Outlook的add-in, 用现在时髦的话应该叫outlook的app. 这个add-in的作用就是把outlook中的email,直接上传到SharePoint中.想要代码的联系我 ...
 - MySQL 安装 启动 基本语法概述
			
MySQL 安装 启动 基本语法概述 MySQL安装和配置 我是直接使用安装包:mysql-installer-community-5.6.10.1.msi 安装的时候其中有几点要注意: 1.记住端口 ...
 - ios开发人员北京,上海,深圳的工资待遇是多少?
			
ios开发人员北京,上海,深圳的工资待遇是多少? [1]首先看看平均工资 从图中来看,北京平均工资15570 居首,不愧是首都啊. 你过了平均线了吗?是不是感觉被平均了,如果感觉工资 ...
 - 高级SQL语句
			
改变数据 insert record 插入一行 insert into foods (name, type_id) values ('Cinnamon Bobka', 1); 如果在insert语句中 ...
 - Phonegap之ios对iPhone6和Plus的闪屏适配 -- xmTan
			
故事的发生起于,由于老板强烈要求app在iPhone6和5有一样的工具栏,然后前端妹子用@media为iPhone6和Plus做了样式适配.然后问题来了,竟然奇葩的发现@media样式只对iPhone ...
 - Android性能优化的浅谈
			
一.概要: 本文主要以Android的渲染机制.UI优化.多线程的处理.缓存处理.电量优化以及代码规范等几方面来简述Android的性能优化 二.渲染机制的优化: 大多数用户感知到的卡顿等性能问题的最 ...
 - socket编程中客户端常用函数 以及简单实现
			
1 常用函数 1.1 connect() int connect(int sockfd, const struct sockaddr *servaddr, socklen_taddrlen); 客 ...
 - IOS OC声明变量在@interface括号中与使用@property的区别
			
方式一:直接在@interface中的大括号中声明. @interface MyTest : NSObject{ NSString *mystr; } 方式二:在@interface中声明,然后再在@ ...
 - 解析ABP框架中的事务处理和工作单元,ABP事务处理
			
通用连接和事务管理方法连接和事务管理是使用数据库的应用程序最重要的概念之一.当你开启一个数据库连接,什么时候开始事务,如何释放连接...诸如此类的. 正如大家都知道的,.Net使用连接池(connec ...
 - HTML基础(一)——一般标签、常用标签和表格
			
第一部分 HTML <html> --开始标签 <head> 网页上的控制信息 <title>页面标题</title> </head> ...
 
			
		