题解:由于解太多,随机抓 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. Python中else语句块(和if、while、for、try搭配使用)

    学过C/C++的都知道,else语句是和if语句搭配使用的, 但是在Python中,else语句更像是作为一个模块,不仅仅可以和if语句搭配,还可以和循环语句,异常处理语句搭配使用.下面逐个进行介绍: ...

  2. asp.net webapi参数绑定

    content={"content": [{"comb_id": "100323","comb_name": " ...

  3. WPF 自己动手来做安装卸载程序

    原文:WPF 自己动手来做安装卸载程序 前言 说起安装程序,这也许是大家比较遗忘的部分,那么做C/S是小伙伴们,难道你们的程序真的不需要一个炫酷的安装程序么? 声明在先 本文旨在教大家以自己的方式实现 ...

  4. How to make vcredist_x86 reinstall only if not yet installed

    Since you don't want to tell what minimal version of Visual C++ redistributable package you require, ...

  5. 源代码管理(Windows + VisualSVN Server + TortoiseSVN + VS2010)

    之前项目中使用过SVN管理源代码,但是都是链接别人搭建的服务器,现在感觉每周保留一个版本蛮麻烦的,就搭建一个,方便以后管理代码. 1.安装VisualSVN Server( VisualSVN Ser ...

  6. U8800安装软件显示无效的URI问题

    看到很多人遇到这个问题,其中包括我自己,最后找到可行的解决办法,现整理出来一个新帖,有同样问题的U友可以参考下. 手机先连接电脑,进入USB存储状态,然后在计算机上找到SD卡目录下的.android_ ...

  7. html基础知识总结2

    下拉列表,文本域,复选框 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  8. 2017年开年的第一次比较大的安全事件: MongoDB “赎金事件”,如何看待互联网安全问题

    今天上午(2017年1月7日),我的微信群中同时出现了两个MongoDB被黑掉要赎金的情况,于是在调查过程中,发现了这个事件.这个事件应该是2017年开年的第一次比较大的安全事件吧,发现国内居然没有什 ...

  9. cdh4.1.2 hadoop和oozie集成问题

    1.异常信息例如以下: Caused by: com.google.protobuf.ServiceException: java.net.ConnectException: Call From sl ...

  10. [Git] Automatically running tests before commits with ghooks

    Wouldn't it be nice if everyone ran the tests before committing code? With ghooks, you can automatic ...