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的更多相关文章

  1. 备战NOIP每周写题记录(一)···不间断更新

    ※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...

  2. Windows 7上执行Cake 报错原因是Powershell 版本问题

    在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...

  3. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  4. Scalaz(15)- Monad:依赖注入-Reader besides Cake

    我们可以用Monad Reader来实现依赖注入(dependency injection DI or IOC)功能.Scala界中比较常用的不附加任何Framework的依赖注入方式可以说是Cake ...

  5. HDU 4762 Cut the Cake(公式)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. Brute Force --- UVA 10167: Birthday Cake

     Problem G. Birthday Cake  Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudg ...

  7. 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 ...

  8. hdu acmsteps 2.1.3 Cake

    Cake Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  9. 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 ...

随机推荐

  1. iOS多线程中,队列和执行的排列组合结果分析

    本文是对以往学习的多线程中知识点的一个整理. 多线程中的队列有:串行队列,并发队列,全局队列,主队列. 执行的方法有:同步执行和异步执行.那么两两一组合会有哪些注意事项呢? 如果不是在董铂然博客园看到 ...

  2. 改变Android ProgressBar样式颜色

    地址: http://blog.csdn.net/lvxiangan/article/details/9110121

  3. tomcat WEB-INF中的结构

    tomcat中 WEB-INF中结构包含3个东西:web.xml,classes文件夹,lib文件夹 web.xml用来配置web中服务调用的uri和对应服务指定的是哪个class文件 classes ...

  4. 【代码笔记】iOS-多张图片合成一张

    代码: RootViewController.m #import "RootViewController.h" @interface RootViewController () @ ...

  5. net2.0对于递归变量的处理方式不同引发的递归问题

    同样的代码,用NET2.0执行产生的效果与其它框架使用的不同,导致报错. 认真查找原因后发现该程序的编写人员隐式的使用了一个公共变量,使之在递归过程中不断的被改写,使得1次递归后就破坏了原来的循环体, ...

  6. yii2超好用的日期组件和时间组件

    作者:白狼 出处:http://www.manks.top/yii2_datetimepicker.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 ...

  7. servlet 学习(一)

    一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...

  8. 如何分析解读systemstat dump产生的trc文件

    ORACLE数据库的systemstat dump生成trace文件虽然比较简单,但是怎么从trace文件中浩如烟海的信息中提炼有用信息,并作出分析诊断是一件技术活,下面收集.整理如何分析解读syst ...

  9. ADDM Reports bug:Significant virtual memory paging was detected on the host operating system

    查看ADDM(数据库版本为ORACLE 10.2.0.5.0)报告时,发现其中有个结论非常不靠谱:Significant virtual memory paging was detected on t ...

  10. Mongodb Manual阅读笔记:CH5 安全性

    5 安全性 Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mongodb Manual阅读 ...