uva 10167 - Birthday Cake
题解:由于解太多,随机抓 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的更多相关文章
- Brute Force --- UVA 10167: Birthday Cake
Problem G. Birthday Cake Problem's Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudg ...
- Uva 10167 - Birthday Cake 暴力枚举 随机
Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...
- UVA - 10167 - Birthday Cake (简单枚举)
思路:简单枚举 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include &l ...
- UVa 1629 DP Cake slicing
题意: 一块n×m的蛋糕上有若干个樱桃,要求切割若干次以后,每块蛋糕上有且仅有1个樱桃.求最小的切割长度. 分析: d(u, d, l, r)表示切割矩形(u, d, l, r)所需要的最小切割长度. ...
- 【Uva 1629】 Cake slicing
[Link]: [Description] 给你一个n*m的格子; 然后里面零零散散地放着葡萄 让你把它切成若干个小矩形方格 使得每个小矩形方格都恰好包含有一个葡萄. 要求切的长度最短; 问最短的切割 ...
- uva10167 Birthday Cake
Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them. Now we put t ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
随机推荐
- SQLite3简单入门及C++ API
转载请注明出处:http://www.cnblogs.com/StartoverX/p/4660487.html 项目用到SQLite3,简单记录一下. MySQL不同,SQLite3的数据库基于文件 ...
- PreparedStatement執行sql語句
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import org ...
- 转:为什么需要htons(), ntohl(), ntohs(),htons() 函数
为什么需要htons(), ntohl(), ntohs(),htons() 函数: 在C/C++写网络程序的时候,往往会遇到字节的网络顺序和主机顺序的问题.这是就可能用到htons(), ntohl ...
- jquery-qrcode在线生成二维码
通过bower进行获取: y@y:ydkt$ bower install jquery-qrcode --save bower not-cached git://github.com/gcusnieu ...
- 如何让多个Activity共用一个Menu
我们可以定义一个自己的CommActivity继承自Activity,然后让每个自定义Activity继承CommActivity,就可以做到. 例如: public class CommActivi ...
- 关于Adapter
ArrayAdapter------------>单一值 SimpleAdapter---------->HashMap<String,Object> 多值 BaseAdapt ...
- 为什么设计模式在C++社区没有Java社区流行?
我们发现设计模式在Java社区很流行,但是在C++社区却没有那么被关注,甚至有点被排斥,究竟是什么原因造成这个差异的呢? 昨天和同事讨论这个问题,最后得出几点原因: (1)C++内存需要 ...
- db file scattered read
SQL> set linesize 200 SQL> col name format a30 SQL> select SESSION_ID,NAME,P1,P2,P3,WAIT_TI ...
- c# 实现文件拖入和拖出(拖拽)
摘自:http://www.cnblogs.com/eaglet/archive/2009/01/06/1370149.html C# WinForm下一步一步实现文件的拖入和拖出 作者:Eaglet ...
- 将 Web 应用性能提高十倍的10条建议
提高 web 应用的性能从来没有比现在更重要过.网络经济的比重一直在增长:全球经济超过 5% 的价值是在因特网上产生的(数据参见下面的资料).这个时刻在线的超连接世界意味着用户对其的期望值也处于历史上 ...