UVA 511

xiaoxiao2021-02-28  138

#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; }
转载请注明原文地址: https://www.6miu.com/read-19751.html

最新回复(0)