题解:由于解太多,随机抓 A、B, 只要有符合就行了; (首先,Ax+By=0必须表示直线,即A、B不能同时为0;另外,要注意到直线不能过输入中的2N个点;检测点在直线的哪一侧,只需要简单的线性规划的知识)

  1. #include <cstdio>
  2. #include <cstdlib>
  3.  
  4. int x[], y[];
  5.  
  6. int test(int A, int B, int N)
  7. {
  8. static int i, pos, neg, tmp;
  9. pos = , neg = ;
  10. for (i = *N-; i >= ; i--)
  11. {
  12. tmp = A*x[i] + B*y[i];
  13. if (tmp > ) neg ++;
  14. else if(tmp < ) pos ++;
  15. else return ;
  16. }
  17. return pos == neg;
  18. }
  19.  
  20. void find(int N)
  21. {
  22. int A, B;
  23. while()
  24. {
  25. A = rand()% - ;
  26. B = rand()% - ;
  27. if(test(A, B, N))
  28. {
  29. printf("%d %d\n", A, B);
  30. break;
  31. }
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. int N, i;
  38. while(scanf("%d", &N) == && N)
  39. {
  40. for (i = *N-; i >= ; i--)
  41. scanf("%d %d", &x[i], &y[i]);
  42. find(N);
  43. }
  44. }

枚举:

  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. void bruteforce(int &A, int &B, vector<int> &x, vector<int> &y, int n){
  5. for (A = -; A <= ; A++){
  6. for (B = -; B <= ; B++){
  7. int d = , u = ;
  8. for (int i = ; i < * n; i++){
  9. if (A*x[i] + B*y[i] > ) u++;
  10. if (A*x[i] + B*y[i] < ) d++;
  11. }
  12. if (u == n&&d == n) return;
  13. }
  14. }
  15. }
  16. int main()
  17. {
  18. int n;
  19. while (cin >> n&&n != ){
  20. vector<int> x(*n, );
  21. vector<int> y(*n, );
  22. for (int i = ; i < *n; i++){
  23. cin >> x[i] >> y[i];
  24. }
  25. int A, B;
  26. bruteforce(A, B, x, y, n);
  27. cout << A << ' ' << B << endl;
  28. }
  29. return ;
  30. }

uva 10167 - Birthday Cake的更多相关文章

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

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

  2. Uva 10167 - Birthday Cake 暴力枚举 随机

      Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...

  3. UVA - 10167 - Birthday Cake (简单枚举)

    思路:简单枚举 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include &l ...

  4. UVa 1629 DP Cake slicing

    题意: 一块n×m的蛋糕上有若干个樱桃,要求切割若干次以后,每块蛋糕上有且仅有1个樱桃.求最小的切割长度. 分析: d(u, d, l, r)表示切割矩形(u, d, l, r)所需要的最小切割长度. ...

  5. 【Uva 1629】 Cake slicing

    [Link]: [Description] 给你一个n*m的格子; 然后里面零零散散地放着葡萄 让你把它切成若干个小矩形方格 使得每个小矩形方格都恰好包含有一个葡萄. 要求切的长度最短; 问最短的切割 ...

  6. uva10167 Birthday Cake

    Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them. Now we put t ...

  7. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  8. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  9. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

随机推荐

  1. 不能将值 NULL 插入列 'ID',表 'EupStoreDemoDB.dbo.OrderDiary';列不允许有 Null 值。INSERT 失败。

    MVC,使用EF构建实体.将数据存入数据库,执行到_db.SaveChange()时,会报如下错误:

  2. 转:Twitter.com在用哪些Javascript框架?

    原文来自于:http://blog.jobbole.com/63964/ 我一直在研究twitter.com使用的一些UI框架.下面是这些框架的清单(大部分是Javascript框架).如果你发现有些 ...

  3. Entity Framework with MySQL 学习笔记一(验证标签)

    直接上代码 [Table("single_table")] public class SingleTable { [Key] public Int32 id { get; set; ...

  4. 两段小PYTHON,作啥用的,行内人才懂~~~:(

    哎,作也不是,不作也不是.... 下次有更新文件时,直接刷新一次了. #coding: UTF-8 import sys reload(sys) sys.setdefaultencoding( &qu ...

  5. Linux企业级项目实践之网络爬虫(26)——线程池

    一旦有一个抓取请求开始,就创建一个新的线程,由该线程执行任务,任务执行完毕之后,线程就退出.这就是"即时创建,即时销毁"的策略.尽管与创建进程相比,创建线程的时间已经大大的缩短,但 ...

  6. class$1,class$2,class$innerclass中的$的含义

    class文件名中的$的含义如下:   $后面的类是$前面的类的内部类 内部类有以下两种情况: 1.普通的组合类形式,即在一个类内部定义一个普通的类  public class Outer { cla ...

  7. Java学习笔记(1)——基本数据类型

    一.进制转换 10^n被称为权  10称为基数   计算机中正数和负数的关系是取反加一, 如: ~3+1=-3 补码边界运算有溢出风险 32位二进制补码最多表示2^32个数, -2G~2G 1,计算机 ...

  8. SQL-MICK基础

    /*Select语句完整的执行顺序:1.from子句组装来自不同数据源的数据:2.where子句基于指定的条件对记录行进行筛选:3.group by子句将数据划分为多个分组:4.使用聚集函数进行计算: ...

  9. referer报头

    依据客户的到达方式定制页面 referer报头保存了用户是从哪个网站找到到这里来的信息的.如果用户直接输入了页面的地址,浏览器就不会发送referer信息. 5.6.1 创建一个可以根据链接过来的网站 ...

  10. google在线測试练习题1

    Problem You receive a credit C at a local store and would like to buy two items. You first walk thro ...