码迷,mamicode.com
首页 > 其他好文 > 详细

URAL - 1793 Tray 2(几何题)

时间:2015-04-21 09:44:26      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

 Status

Description

One of the organizers of the Ural Regional School Programming Contest came to the university cafeteria to have lunch. He took a soup and a main course and tried to arrange them on a small rectangular tray, which was not so easy. “Oops, that‘s a problem,” he thought. “Oh, yes, that‘s a problem! A nice problem for the contest!”
The Ural State University‘s cafeteria has trays with a rectangular a × b bottom and vertical borders of height d. Plates have the shape of a truncated cone. All the plates in the cafeteria have the same height h. The organizer wants to put the plates on the tray so that their bottoms adjoin the bottom of the tray completely. Can he do it?
技术分享

Input

The first line contains the integers a, b, and d separated with a space. Each of the following lines describes one of the plates and contains two integers. The former integer is the radius of the plate‘s bottom and the latter integer is the radius of the circle formed by the edge of the plate. The second radius is greater than the first one. The last line contains the height h of the plates. All the input integers are positive and do not exceed 1000.

Output

Output “YES” if the plates can be arranged on the tray and “NO” otherwise.

Sample Input

input output
10 10 10
1 2
1 2
5
YES
8 4 1
1 2
1 3
1
NO


以前做过类似的题,只是把二维的问题搬到空间上来,处理出与托盘接触的平面中,碗的截面就好了,两个圆分别放在两个边角,判断距离与大半径的关系就好了。

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const double esp = 0.00001;
struct Point
{
	double x;
	double y;
	Point(double xx, double yy) :x(xx), y(yy){}
};
double dis(Point a, Point b)
{
	return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}

int main()
{
	double a, b, d;
	double r1, R1, r2, R2, h;
	double rr1, rr2;

	while (cin >> a >> b >> d)
	{
		cin >> r1 >> R1;
		cin >> r2 >> R2;
		cin >> h;
		rr1 = r1*(h - d) / h + R1*d / h;
		rr2 = r2*(h - d) / h + R2*d / h;
		if (h <= d)
		{
			rr1 = R1;
			rr2 = R2;
		}
		if (2 * rr1 > a || 2 * rr1 > b|| 2 * rr2 > a || 2 * rr2 > b)
		{
			cout << "NO" << endl;
			continue;
		}
		Point p1(rr1, rr1);
		Point p2(a - rr2, b - rr2);
		double dd = dis(p1, p2);
		if (dd >= R1 + R2)
		{
			cout << "YES" << endl;
		}
		else
			cout << "NO" << endl;
	}
}


URAL - 1793 Tray 2(几何题)

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45160063

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!