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 ...
随机推荐
- IOS安全测试
1.本地存储安全 配置文件 缓存 数据库 测试数据 证书数据 2.网络通信安全 http明文通信 https证书认证 敏感参数弱加密 加签/验签策略 外接第三方SDK 外发不明数据 3.源代码安全 日 ...
- Swift设置自动行高
// 设置行高自适应 tableView.rowHeight = UITableViewAutomaticDimension // 设置预估行高 tableView.estimatedRowHeigh ...
- iOS 单例模式 浅叙
单例模式作用 可以保证在程序运行过程中,一个类只有一个实例,而且该实例易于供外界使用 从而方便地控制了实例个数,并节约系统资源 单例模式使用场合 在整个引用程序中,共享一份资源(这份资源只需要创建初始 ...
- iOS不同IDS说明
1.Vindor标识符 identifierForVendor 一个英文字符串,对于相同的产品商(这里指com.zhang.*,也就是前缀一样),其唯一的标识设备. * 这个值对于相同的产品商在相同 ...
- 【代码笔记】iOS-旋转的图片
一,效果图. 二,工程图. 三,代码. AppDelegate.h #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder ...
- Java 引用
Java 对象的引用方式有如下四种,这四种方式主要是为了给垃圾回收提供更灵活的操作: 1.强引用,最常见的引用方式,当一个对象被一个或一个以上的引用变量引用时,它处于可达状态,这时不会被垃圾回收器回收 ...
- 【转】Android开发之如何保证Service不被杀掉(broadcast+system/app)
Service简介 1.Service 每个Service必须在manifest中 通过<service>来声明. 可以通过contect.startservice和contect.bin ...
- VBA 操作数字
第8章 操作数字 加.减.乘.除.平方与指数(^2 或者^n).平方根Sqr.正弦Sin.余弦Cos.正切Tan.反正切Atn.绝对值Abs 转换为整型数.长整型数.双精度型数和值 Cint当双精度型 ...
- 布局 position
position : 设置定位方式 跟『定位』相关的有一些属性,最重要的一个是『position』,它主要是设置『定位方式』. 而定位方式最重要的是设置『参照物』. 配合 position 使用的有这 ...
- Java基础知识学习(六)
多线程 先了解线程的概念 多线程需要注意的地方 优先级.线程同步.消息传递.数据共享.死锁等 Java线程类 Thread,实现接口 Runnable Thread常用方法 getName 获得线程名 ...
