题解:由于解太多,随机抓 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. 19个非常有用的 jQuery 图片滑动插件和教程

    jQuery 是一个非常优秀的 Javascript 框架,使用简单灵活,同时还有许多成熟的插件可供选择.其中,最令人印象深刻的应用之一就是对图片的处理,它可以让帮助你在你的项目中加入精美的效果.今天 ...

  2. 插入排序(C语言)

    输入一个数,插入到已排序的队列中 第一:定义一个已经排好的整型数组 如: int arry[7]={2,3,5,11,15,17};  或输入一串整型的数组,再排序(冒泡.选择都可以) 下面我们用冒泡 ...

  3. IO定时器

    IoInitializeTimer 初始化定时器 IoStartTime 开启定时器 IoStopTimer 停止定时器 回调函数 VOID IoTimer( __in struct DEVICE_O ...

  4. oldboy第二天学习

    一.上课体验及感受 第二天上课了,从循环到队列,感觉都可以接受,但是当循环遇到队列之后感觉脑袋就有点不够用了.不知道是因为萌新的问题.每个人都这样,还是个人能力不行.总而言之加油努力吧!! 二.循环, ...

  5. C51的一些误区和注意事项

    1) C忌讳绝对定位.常看见初学者要求使用_at_,这是一种谬误,把C当作ASM看待了.在C中变量的定位是编译器的事情,初学者只要定义变量和变量的作用域,编译器就把一个固定地址给这个变量.怎么取得这个 ...

  6. 硝烟中的Scrum和XP-我们如何实施Scrum 4 (Part 1/2)

    4 制定Sprint计划 计划是Scrum中重要的一环; 是为了让团队获得足够信息, 不受打扰地工作, 增加团队的信心; Planning的成果: 1) Sprint目标 2) 团队成员名单(时间百分 ...

  7. c语言内存模型

    文章一.C语言的内存分配模型 1.程序代码区:存放函数体的二进制代码. 2.全局区数据区:全局数据区划分为三个区域.全局变量和静态变量的存储是放在一块的,初始化的全局变量和静态变量在一块区域,未初始化 ...

  8. Android中几种常用的话框

    1.普通对话框: Builder alert=new AlertDialog.Builder(MainActivity.this); alert.setTitle("提示"); a ...

  9. HDU_2051——十进制到二进制转换

    Problem Description Give you a number on base ten,you should output it on base two.(0 < n < 10 ...

  10. POJ 1979 深度优先搜索

    题意:有红色和黑色的格子,只能走黑色的,问从起始位置出发,最多能走到达多少块黑色格子. 分析:相当于走迷宫,黑色格子是路,红色格子是墙,每次到达一个未到达过的格子时计数,原点也算是一个.每次可以走上下 ...