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 ...
随机推荐
- android HorizontalScrollView
第一个控件,借鉴网上的资料,自己稍加修改,横向滑动图片浏览功能,纪念下 布局文件 <?xml version="1.0" encoding="utf-8" ...
- Android中利用ViewHolder优化自定义Adapter的典型写法
利用ViewHolder优化自定义Adapter的典型写法 最近写Adapter写得多了,慢慢就熟悉了. 用ViewHolder,主要是进行一些性能优化,减少一些不必要的重复操作.(WXD同学教我的. ...
- mysql innodb 奔溃问题
ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ------------------------------------- ...
- spring.net (3)依赖注入基础
属性的注入: 在上篇例子中已经出现并解释过: <object id="dog" type="SpringDemo.Dog,SpringDemo" sing ...
- Android 应用程序的反编译
1.ApkTool工具 安装ApkTool工具,该工具可以解码得到资源文件,但不能得到Java源文件.安装环境:需要安装JRE1.61> 到http://code.google.com/p/an ...
- 数据持久化(一)--NSKeyedArchiver
数据持久化: 将内存中的数据按某种格式存进磁盘 数据的种类: 1,结构化的数据 2, 字节流数据 结构化的数据 字节流 内存中结构化的数据 -> 磁盘, 叫: 归档 字 ...
- iOS--通讯录(UITableViewController)
本文主要实现通讯录的部分功能(分组名.索引.分组的组名)等等功能: 废话不多说了,先上效果图: 在工程中需要导入一个plist文件,文件图如图: 工程目录文件如图: 工程程序如图所示: RootTab ...
- java中实现线程同步
为何要使用同步? java允许多线程并发控制,当多个线程同时操作一个可共享的资源变量时(如数据的增删改查), 将会导致数据不准确,相互之间产生冲突,因此加入同步锁以避免在该线程没有完成操作之前,被其他 ...
- AndroidStudio添加依赖库
以Gson为例 Step1:点击下图中的入口,进入ProjectStructure Step2: 在app项中选择Dependencies窗口,点击右侧的加号 Step3:在搜索框中输入gson,点击 ...
- [转]listview加载性能优化ViewHolder
当listview有大量的数据需要加载的时候,会占据大量内存,影响性能,这时候就需要按需填充并重新使用view来减少对象的创建. ListView加载数据都是在public View getView( ...
