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年半年时间完成 ...
随机推荐
- 不能将值 NULL 插入列 'ID',表 'EupStoreDemoDB.dbo.OrderDiary';列不允许有 Null 值。INSERT 失败。
MVC,使用EF构建实体.将数据存入数据库,执行到_db.SaveChange()时,会报如下错误:
- 转:Twitter.com在用哪些Javascript框架?
原文来自于:http://blog.jobbole.com/63964/ 我一直在研究twitter.com使用的一些UI框架.下面是这些框架的清单(大部分是Javascript框架).如果你发现有些 ...
- Entity Framework with MySQL 学习笔记一(验证标签)
直接上代码 [Table("single_table")] public class SingleTable { [Key] public Int32 id { get; set; ...
- 两段小PYTHON,作啥用的,行内人才懂~~~:(
哎,作也不是,不作也不是.... 下次有更新文件时,直接刷新一次了. #coding: UTF-8 import sys reload(sys) sys.setdefaultencoding( &qu ...
- Linux企业级项目实践之网络爬虫(26)——线程池
一旦有一个抓取请求开始,就创建一个新的线程,由该线程执行任务,任务执行完毕之后,线程就退出.这就是"即时创建,即时销毁"的策略.尽管与创建进程相比,创建线程的时间已经大大的缩短,但 ...
- class$1,class$2,class$innerclass中的$的含义
class文件名中的$的含义如下: $后面的类是$前面的类的内部类 内部类有以下两种情况: 1.普通的组合类形式,即在一个类内部定义一个普通的类 public class Outer { cla ...
- Java学习笔记(1)——基本数据类型
一.进制转换 10^n被称为权 10称为基数 计算机中正数和负数的关系是取反加一, 如: ~3+1=-3 补码边界运算有溢出风险 32位二进制补码最多表示2^32个数, -2G~2G 1,计算机 ...
- SQL-MICK基础
/*Select语句完整的执行顺序:1.from子句组装来自不同数据源的数据:2.where子句基于指定的条件对记录行进行筛选:3.group by子句将数据划分为多个分组:4.使用聚集函数进行计算: ...
- referer报头
依据客户的到达方式定制页面 referer报头保存了用户是从哪个网站找到到这里来的信息的.如果用户直接输入了页面的地址,浏览器就不会发送referer信息. 5.6.1 创建一个可以根据链接过来的网站 ...
- google在线測试练习题1
Problem You receive a credit C at a local store and would like to buy two items. You first walk thro ...