UVa 10167 Birthday Cake (白皮书第七章 生日蛋糕)
来源:互联网 发布:域名生成二维码 编辑:程序博客网 时间:2024/04/30 13:52
// Birthday Cake (生日蛋糕)
;Ax+By=0;求出其中A,B的值,输出一组解即可。
暴力方法枚举的直线是否能将樱桃分成两个相等的两份了,也就是看点在直线的左侧还是右侧,
还是在直线上了(这里必须考虑其中两种,如果只判断在左侧的樱桃个数是否等于N的话可能会错误,因为有些樱桃可能会在直线上)。
判断点在直线左侧,右侧,直线上的方法。
点(x0,y0):
当x0 <a*y0+b的时候,点在直线左侧
x0> a*y0+b的时候,点在直线右侧
x0=a*y0+b的时候,点在直线上
*/
#include <iostream>
#include <cmath>
using namespace std;
#define MAXN 100
struct point
{
int x;
int y;
};
int main()
{
int N;
point cherries[MAXN + 10];
while (cin >> N, N)
{
for (int i = 1; i <= 2 * N; i++)
cin >> cherries[i].x >> cherries[i].y;
for (int i = -100; i <= 100; i++)
{
bool found = false;
for (int j = -100; j <= 100; j++)
{
int left_num= 0, down_num = 0;
bool online = false;
for (int k = 1; k <= 2 * N; k++)
{
if (i * cherries[k].x + j * cherries[k].y == 0)
{
online = true;
break;
}
else if (i * cherries[k].x + j * cherries[k].y > 0)
left_num++;
else
down_num++;
}
if (online == false && left_num == down_num)
{
cout << i << " " << j << endl;
found = true;
break;
}
}
if (found)
break;
}
}
return 0;
}
/*
题目地址 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1108
题意:一个蛋糕上有2*N个樱桃,将蛋糕切成相同大小的两部分,且经过中点(0,0),这条直线方程为:;Ax+By=0;求出其中A,B的值,输出一组解即可。
暴力方法枚举的直线是否能将樱桃分成两个相等的两份了,也就是看点在直线的左侧还是右侧,
还是在直线上了(这里必须考虑其中两种,如果只判断在左侧的樱桃个数是否等于N的话可能会错误,因为有些樱桃可能会在直线上)。
判断点在直线左侧,右侧,直线上的方法。
点(x0,y0):
当x0 <a*y0+b的时候,点在直线左侧
x0> a*y0+b的时候,点在直线右侧
x0=a*y0+b的时候,点在直线上
*/
#include <iostream>
#include <cmath>
using namespace std;
#define MAXN 100
struct point
{
int x;
int y;
};
int main()
{
int N;
point cherries[MAXN + 10];
while (cin >> N, N)
{
for (int i = 1; i <= 2 * N; i++)
cin >> cherries[i].x >> cherries[i].y;
for (int i = -100; i <= 100; i++)
{
bool found = false;
for (int j = -100; j <= 100; j++)
{
int left_num= 0, down_num = 0;
bool online = false;
for (int k = 1; k <= 2 * N; k++)
{
if (i * cherries[k].x + j * cherries[k].y == 0)
{
online = true;
break;
}
else if (i * cherries[k].x + j * cherries[k].y > 0)
left_num++;
else
down_num++;
}
if (online == false && left_num == down_num)
{
cout << i << " " << j << endl;
found = true;
break;
}
}
if (found)
break;
}
}
return 0;
}
0 0
- UVa 10167 Birthday Cake (白皮书第七章 生日蛋糕)
- UVa Problem 10167 Birthday Cake (生日蛋糕)
- UVA10167- Birthday Cake(生日蛋糕)
- UVa 10167 - Birthday Cake
- UVa:10167-birthday cake
- UVA 10167 Birthday Cake
- uva 10167 - Birthday Cake
- UVa 10167 Birthday Cake
- uva 10167 - Birthday Cake
- UVa 10167 Birthday Cake
- uva 10167 - Birthday Cake
- UVa 10167 - Birthday Cake
- uva-10167 - Birthday Cake
- UVA 10167 - Birthday Cake
- uva 10167 Birthday Cake
- UVa 10167Birthday Cake
- uva 10167 Birthday Cake
- uva 10167 Birthday Cake
- zoj1093题解 Monkey and Banana
- 还是优化 成熟游戏的优化
- C#语言各种集合介绍
- 序列化
- JAVA hdu 2013(蟠桃记)&&hdu 2035(人见人爱A^B)
- UVa 10167 Birthday Cake (白皮书第七章 生日蛋糕)
- 【设计模式基础】创建型模式 - 5 - 生成器(Builder)
- VS上测试运行时间
- Lua 学习笔记 一
- 4.1.4: jQuery事件之事件冒泡
- 4.1.5:jQuery事件之事件对象的属性
- 4.1.6: jQuery事件之移除事件
- 4.1.7: jQuery事件之模拟操作
- 4.1.8: jQuery事件之其他用法