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 ...
随机推荐
- Tomcat https自制证书和浏览器配置
Tomcat配置成https后,如过使用的是自己的证书,登陆首页时,总是提示证书安全问题,网上的很多资料有描述,但比较复杂,找了几个配置不成功,现在描述一个比较简单的方法. 生成证书的脚本 #!/bi ...
- iOS自动化编译
最近研究了一下iOS的自动化编译,目的是为了简化测试和开发的同学沟通协调的次数,实现测试同学可以随时从网页操作编译SVN最新源码并打包ipa进行测试. 具体思路是通过从配置文件读取需要编译的项目配置列 ...
- 两个Service之间相互监视的实现
在实际开发中可能需要用到两个Service相互监视的情况,本示例就是实现此功能以作参考. 服务A: public class ServiceA extends Service { private st ...
- Android程序意外Crash后自动重启
1.自定义UncaughtExceptionHandler public class UnCeHandler implements UncaughtExceptionHandler { private ...
- 【CoreData】 简单地使用
先介绍一下什么是CoreData —— 它是在iOS5之后出现的一个框架,提供了对象-关系映射(ORM)的功能,既能够将OC对象转化成数据,保存在SQLite数据库文件中,也能将保存在数据库中的数据还 ...
- UIWindow 实现遮盖导航条的蒙版
使用代码构建应用的主界面 我们先来介绍一下,如何使用代码来构建项目的主界面,以及主界面的一般架构方式 概述 刚创建的 iOS 项目默认是使用 Main.storeboard 作为项目的主界面的 若你不 ...
- VC对ScrollView的调整
VC对ScrollView的调整 automaticallyAdjustsScrollViewInsets automaticallyAdjustsScrollViewInsets是ViewContr ...
- CDC 2013 北京站手记
受搜狐畅游的邀请,这次能够有机会参与2013中国开发者大会北京站的活动. 本次大会的主题是“游戏”和“移动”,因此上午的峰会安排了5个主讲,分别就搜索.云存储服务器.游戏媒体.移动应用和游戏渠道等多方 ...
- Oracle global database name与db link的纠缠关系
ORACLE数据库中Global Database Name与DB LINKS的关系还真是有点纠缠不清,在说清楚这个关系前,我们先来了解一下Global Database Name的概念 Global ...
- eclipse出现的JRE运行环境错误
adt-bundle-linux eclipse启动运行错误,提示如下: A Java RunTime Environment (JRE) or Java Development Kit (JDK) ...
