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 file contains several scenarios. Each of them consists of 2 parts:
    The first 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 file 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

问题链接:UVA10167 Birthday Cake
问题简述
    给定2N 个点,求A和B为多少时,直线Ax+By=0 把点分成相等的两部分。
问题分析
    本题可以用暴力法来解决。把点带入直线方程Ax+By=0,那么大于0的是一边,小于0的是另外一边,枚举A和B,统计一下就可以。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++程序如下:

/* UVA10167 Birthday Cake */#include <iostream>using namespace std;const int LEFT = -500, RIGHT = 500;
const int N = 50;
int x[N * 2], y[N * 2];int main()
{int n;while(~scanf("%d", &n) && n) {n *= 2;for(int i = 0; i < n; i++)scanf("%d%d", &x[i], &y[i]);bool flag = true;for(int a = LEFT; a <= RIGHT && flag; a++)for(int b = LEFT; b <= RIGHT ; b++) {if(a==0 && b==0 ) continue;int i, cnt = 0;     // 统计满足AX+BY>0的点数目for(i = 0; i < n; i++) {if(a * x[i] + b * y[i] > 0) ++cnt;else if(a * x[i] + b * y[i] == 0) break;}if( i < n) continue;if(cnt == n / 2) {printf("%d %d\n", a, b);flag = false;break;}}}return 0;
}

UVA10167 Birthday Cake【暴力】相关推荐

  1. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  2. ICPC程序设计题解书籍系列之八:(美)斯基纳等:《挑战编程-程序设计竞赛训练手册》

    S书<挑战编程--程序设计竞赛训练手册>题目一览 1 Getting Started UVA100 POJ1207 HDU1032 The 3n + 1 problem[水题] - 海岛B ...

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

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

  4. 问题 J: Frosting on the Cake

    问题 J: Frosting on the Cake 时间限制: 1 Sec  内存限制: 128 MB 提交: 159  解决: 56 [提交][状态][讨论版][命题人:admin] 题目描述 I ...

  5. [Cake] 1. CI中的Cake

    在上一篇C#Make自动化构建-简介中,简单的介绍了下Cake的脚本如何编写以及通过Powershell或者Bash在本地运行Cake脚本.本篇在此基础上,介绍下如何在CI环境中使用Cake. 1. ...

  6. 喵哈哈村的魔法考试 Round #1 (Div.2) 题解源码(A.水+暴力,B.dp+栈)

    A.喵哈哈村的魔法石 发布时间: 2017年2月21日 20:05   最后更新: 2017年2月21日 20:06   时间限制: 1000ms   内存限制: 128M 描述 传说喵哈哈村有三种神 ...

  7. 哑谜,回文和暴力之美

    暴力搜索是一个有趣的东西.至少刘汝佳是这么认为的.编程之美的4.10节就是典型的暴力题.虽然作者将其难度定义为一颗星,但却不能因此认为这个类型的问题就是那么容易的,很多可能需要一些有创造力的想法. 不 ...

  8. Leetcode 15.三数之和 双指针 or 暴力哈希

    题目链接:传送门 题目:给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?请你找出所有和为 0 且不重复的三元组. 暴力+ ...

  9. HDU - 5875 2016 ACM/ICPC 大连网络赛 H题 暴力

    题目链接 题意:给你一个区间l,r一直将val[l]模上val[l+1],val[l+2]...val[r],因为一个模上比前一个数小数是没有意义的,所以需要将每一个点找到右边第一个小于他的点就行. ...

最新文章

  1. 5g通用模组是什么_广和通发布全新5G模组FG650,搭载展锐中国“芯”
  2. 为iOS Vision盒子架构建Core ML管道(五)
  3. TextView IME option
  4. 第08章-使用Spring Web Flow
  5. 推荐几个机器学习的干货公众号!
  6. 无盘服务器1410M,【说好的每周一贴】网维9系整套施工指南及常见问题与解决方法!!...
  7. RS485_PTZ_云台控制
  8. gis可达性分析步骤_干货来了!ArcGIS空间分析—空间聚类模式分析
  9. Ken Thompson 的经典 C 程序
  10. 【图像分割】基于区域的重叠椭圆拟合实现细胞分割附matlab代码
  11. Mybatis学习小结
  12. Java+coolq实现QQ机器人
  13. QMS-云质-质量管理-海克斯康为什么不断收购质量管理软件(QMS)?
  14. (十一)IPSec协议
  15. 川教版八年级计算机教学计划,川教版八年级下信息技术教学计划.doc
  16. IOS - rangeOfString、NSNotFound
  17. 计算机音乐谱巴啦啦小魔,天谕手游巴啦啦小魔仙乐谱代码是什么-天谕手游巴啦啦小魔仙乐谱代码分享_快吧手游...
  18. C++ 原创 小游戏 狼人杀1.0
  19. 去哪儿网java实习_【去哪儿网Java面试】Java实习(机票部门)-看准网
  20. 如何构建一个从创意出发的工作室

热门文章

  1. go tcp连接_在Go中构建并发TCP服务器样例
  2. 开源GIS(二)——openlayers加载Arcgis和geoserver在线离线切片
  3. Jquery实现子菜单散开动画
  4. Netty使用kryo序列化传输对象
  5. Android中Bitmap缓存池
  6. MFC 教程【13_MFC工具条和状态栏 】
  7. linux内核rop姿势详解,Linux内核ROP姿势详解(二)
  8. java 双击触发事件,用RxJava2的方式实现点击事件
  9. java 集合中对象的排序 和去重
  10. c语言程序设计个人作业,C语言程序设计-作业集.doc