程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> URAL - 1793 Tray 2(幾何題)

URAL - 1793 Tray 2(幾何題)

編輯:C++入門知識

URAL - 1793 Tray 2(幾何題)


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

Submit 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? Problem illustration

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
#include
#include
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;
	}
}


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved