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

 #include <cstdio>
#include <cstdlib> int x[], y[]; int test(int A, int B, int N)
{
static int i, pos, neg, tmp;
pos = , neg = ;
for (i = *N-; i >= ; i--)
{
tmp = A*x[i] + B*y[i];
if (tmp > ) neg ++;
else if(tmp < ) pos ++;
else return ;
}
return pos == neg;
} void find(int N)
{
int A, B;
while()
{
A = rand()% - ;
B = rand()% - ;
if(test(A, B, N))
{
printf("%d %d\n", A, B);
break;
}
}
} int main()
{
int N, i;
while(scanf("%d", &N) == && N)
{
for (i = *N-; i >= ; i--)
scanf("%d %d", &x[i], &y[i]);
find(N);
}
}

枚举:

 #include<iostream>
#include<vector>
using namespace std;
void bruteforce(int &A, int &B, vector<int> &x, vector<int> &y, int n){
for (A = -; A <= ; A++){
for (B = -; B <= ; B++){
int d = , u = ;
for (int i = ; i < * n; i++){
if (A*x[i] + B*y[i] > ) u++;
if (A*x[i] + B*y[i] < ) d++;
}
if (u == n&&d == n) return;
}
}
}
int main()
{
int n;
while (cin >> n&&n != ){
vector<int> x(*n, );
vector<int> y(*n, );
for (int i = ; i < *n; i++){
cin >> x[i] >> y[i];
}
int A, B;
bruteforce(A, B, x, y, n);
cout << A << ' ' << B << endl;
}
return ;
}

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. 猜数字-js

    var n = Math.round(Math.random()*10); //随机数 // alert(n); while(true){ var Onum = prompt('请输入1-10之间的数 ...

  2. Css溢出隐藏

    display: -webkit-box;-webkit-line-clamp: 2;     /*多少行数之后显示为省略...*/word-wrap: break-word;word-break: ...

  3. 使用Jstl异常:The absolute uri: http://java.sun.com/jsp/jstl/core cannot&nbs

    错误提示是:        org.apache.jasper.JasperException: This absolute uri http://java.sun.com/jsp/jstl/core ...

  4. 【iOS问题】字典转模型,属性个数不匹配问题

    一.字典转模型的键值对与模型属性不匹配问题 1. 字典的键个数 < 模型的属性个数 (key 能与模型的属性匹配) 1> .KVO 方式: - setValuesForKeysWithDi ...

  5. windows 下安装使用ipython

    转自:https://my.oschina.net/u/1431433/blog/189337 1. 下载安装Python 下载: python-3.3.3.amd64.msi (救在Python.o ...

  6. 深入理解querySelector(All)

          querySelector和querySelectorAll同属于Selectors API Level 1规范,该规范早在2006年就已经开始发展,并在2007年10月形成querySe ...

  7. ASP超级网店V2.5一注入漏洞

    Title:ASP超级网店V2.5一注入漏洞  --2011-10-30 17:59 ASP超级网店V2.5 这个系统,有很多地方可以注入 http://www.xxxxxx.com/admin/pi ...

  8. 【HDOJ】1057 A New Growth Industry

    纯粹的模拟题目. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 20 # ...

  9. COJ 0358 xjr考考你数据结构(根号3)线段树区间修改

    xjr考考你数据结构(根号3) 难度级别:C: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 请你编写一个数据结构,完成以下功能: 1)求出第 ...

  10. head命令

    head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 1.命令格式: hea ...