UVA 511

#include<iostream>
#include<vector>
#include<string>
#include<type_traits>
#include<sstream>
#include<tuple>
#include<bitset>
#include<regex>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
using namespace std;

typedef struct{
	string name;
	double minX, minY;
	double maxX, maxY;
	double height, width;
	double area;
	double asp;
	double centerX, centerY;
	double lowRx, lowRy;
	double disCenter;
	double dislowR;
}Map;

typedef struct{
	string name;
	double x, y;
	vector<Map> info;
}location;

bool compare(Map a,Map b){
	if (a.area != b.area) return a.area > b.area;
	if (a.disCenter != b.disCenter) return a.disCenter > b.disCenter;
	if (a.asp != b.asp){
		double asp1 = fabs(a.asp-0.75);
		double asp2 = fabs(b.asp-0.75);
		return asp2 > asp1;
	}
	if (a.dislowR != b.dislowR){
		return a.dislowR < b.dislowR;
	}
	return a.minX > b.minX;
}

int main(){
	string s;
	cin >> s;
	vector<Map> map_info;
	while (cin >> s){
		if (s == "LOCATIONS") break;
		double x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		Map temp;
		temp.name = s;
		temp.minX = min(x1,x2);
		temp.maxX = max(x1,x2);
		temp.minY = min(y1,y2);
		temp.maxY = max(y1,y2);
		temp.height = temp.maxY-temp.minY;
		temp.width = temp.maxX - temp.minX;
		temp.area = temp.height*temp.width;
		temp.asp = temp.height / temp.width;
		temp.lowRx = temp.maxX;
		temp.lowRy = temp.minY;
		temp.centerX = (temp.minX + temp.maxX) / 2;
		temp.centerY = (temp.minY + temp.maxY) / 2;
		map_info.push_back(temp);
	}
	vector<location> Loc;
	map<string, int> name2pos;
	while (cin >> s){
		if (s == "REQUESTS") break;
		location temp;
		temp.name = s;
		cin >> temp.x >> temp.y;
		vector<Map> re;
		for (int i = 0; i < map_info.size(); i++){
			if (temp.x >= map_info[i].minX&&temp.x <= map_info[i].maxX
				&&temp.y >= map_info[i].minY&&temp.y <= map_info[i].maxY){
				map_info[i].disCenter = sqrt((temp.x - map_info[i].centerX)*(temp.x - map_info[i].centerX)
					+ (temp.y - map_info[i].centerY)*(temp.y - map_info[i].centerY));
				map_info[i].dislowR = sqrt((temp.x - map_info[i].lowRx)*(temp.x - map_info[i].lowRx)
					+ (temp.y - map_info[i].lowRy)*(temp.y - map_info[i].lowRy));
				re.push_back(map_info[i]);
			}
		}
		sort(re.begin(),re.end(),compare);
		int length = re.size()-1;
		if (length >= 0){
			temp.info.push_back(re[length]);
			double area = re[length].area;
			length--;
			while (length >= 0){
				if (re[length].area != area){
					temp.info.push_back(re[length]);
					area = re[length].area;
				}
				length--;
			}
		}
		reverse(temp.info.begin(),temp.info.end());
		Loc.push_back(temp);
		name2pos[s] = Loc.size() - 1;
	}
	while (cin >> s){
		if (s == "END") break;
		int pos;
		cin >> pos;
		if (name2pos.find(s) == name2pos.end()){
			cout << s << " at detail level " << pos 
				<< " unknown location" << endl;
			continue;
		}
		else{
			int index = name2pos[s];
			int length = Loc[index].info.size();
			if (length == 0){
				cout << s << " at detail level " << pos
					<< " no map contains that location" << endl;
			}
			else if (pos > length){
				cout << s << " at detail level " << pos << " no map at that detail level; "
					<< "using " << Loc[index].info.back().name << endl;
			}
			else{
				cout << s << " at detail level " << pos << " using "
					<< Loc[index].info[pos - 1].name << endl;
			}
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值