首页 > ACM题库 > HDU-杭电 > HDU 1110 Equipment Box-计算几何-[解题报告] C++
2013
11-27

HDU 1110 Equipment Box-计算几何-[解题报告] C++

Equipment Box

问题描述 :

There is a large room in the Pyramid called Room-of-No-Return. Its floor is covered by rectangular tiles of equal size. The name of the room was chosen because of the very high number of traps and mechanisms in it. The ACM group has spent several years studying the secret plan of this room. It has made a clever plan to avoid all the traps. A specially trained mechanic was sent to deactivate the most feared trap called Shattered Bones. After deactivating the trap the mechanic had to escape from the room. It is very important to step on the center of the tiles only; he must not touch the edges. One wrong step and a large rock falls from the ceiling squashing the mechanic like a pancake. After deactivating the trap, he realized a horrible thing: the ACM plan did not take his equipment box into consideration. The box must be laid onto the ground because the mechanic must have both hands free to prevent contact with other traps. But when the box is laid on the ground, it could touch the line separating the tiles. And this is the main problem you are to solve.

输入:

The input consists of T test cases. The number of them (T) is given on the first line of the input. Each test case consists of a single line. The line contains exactly four integer numbers separated by spaces: A, B, X and Y. A and Bindicate the dimensions of the tiles, X and Y are the dimensions of the equipment box (1 <= A, B, X, Y <= 50000).

输出:

Your task is to determine whether it is possible to put the box on a single tile — that is, if the whole box fits on a single tile without touching its border. If so, you are to print one line with the sentence “Escape is possible.”. Otherwise print the sentence “Box cannot be dropped.”.

样例输入:

2
10 10 8 8
8 8 10 10

样例输出:

Escape is possible.
Box cannot be dropped.

卧槽!把大于号写成小于号在那里WA了半天我勒个去!!!!!

题意很明确,就是给定大盒子的边:A,B 以及小盒子的边X,Y,判断小盒子能否放入大盒子!显然,1. 当大盒子的面积小于小盒子时候,无法放进去2. 当大盒子没有小盒子宽的时候没法放进去(这里约定盒子边长中长的为长,短的为宽)3. 当大盒子的长宽都大于小盒子的时候,肯定能放进去4. 剩余的情况需要判断斜着放小盒子:

tt

判断小盒子斜放的最大长度(即坐上顶点右下顶点分别在大盒子的上下边,左下顶点在大盒子的左边上),当这个长度小于大盒子的长则能放下!

AC代码如下:

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

bool judge( double a, double b, double x, double y ){
	if( a > x && b > y ){
		return true;
	}
	if( a * b <= x * y ){
		return false;
	}
	if( y >= b ){
		return false;
	}

	double diagonal = sqrt( x * x + y * y );
	double angle = acos( y / diagonal ) - acos( b / diagonal );
//	double angle2 = asin( b / diagonal ) - asin( y / diagonal );
	double H = x * cos( angle ) + y * sin( angle );
	if( H > a ){
		return false;
	}else{
		return true;
	}
}

int main(){
	double a, b, x, y;
	int T;
	cin >> T;
	while( T-- ){
		cin >> a >> b >> x >> y;
		if( a < b ){
			swap( a, b );
		}
		if( x < y ){
			swap( x, y );
		}
		if( judge( a, b, x, y ) ){
			cout << "Escape is possible." << endl;
		}else{
			cout << "Box cannot be dropped." << endl;
		}
	}
	return 0;
}

  1. 代码是给出了,但是解析的也太不清晰了吧!如 13 abejkcfghid jkebfghicda
    第一步拆分为 三部分 (bejk, cfghi, d) * C(13,3),为什么要这样拆分,原则是什么?

  2. 嗯 分析得很到位,确实用模板编程能让面试官对你的印象更好。在设置辅助栈的时候可以这样:push时,比较要push的elem和辅助栈的栈顶,elem<=min.top(),则min.push(elem).否则只要push(elem)就好。在pop的时候,比较stack.top()与min.top(),if(stack.top()<=min.top()),则{stack.pop();min.pop();},否则{stack.pop();}.

  3. 博主您好,这是一个内容十分优秀的博客,而且界面也非常漂亮。但是为什么博客的响应速度这么慢,虽然博客的主机在国外,但是我开启VPN还是经常响应很久,再者打开某些页面经常会出现数据库连接出错的提示