题目链接:https://vjudge.net/problem/UVA-511

题目翻译摘自《算法禁赛入门经典》

题目大意

  有 n 张地图(已知名称和两个对角线端点的坐标)和 m 个地名(已知名称和坐标), 还有 q 个查询。每张地图都是边平行于坐标轴的矩形,比例定义为高度除以宽度的值。每个查询包含一个地名和详细等级 i。面积相同的地图总是属于同一个详细等级。假定包含此地名的地图中一共有 k 种不同的面积,则合法的详细等级为 1~k(其中 1 最不详细,k 最详细, 面积越小越详细)。如果详细等级 i 的地图不止一张,则输出地图中心和查询地名最接近的一张;如果还有并列的,地图长宽比应尽量接近 0.75(这是Web浏览器的比例);如果还有并列,查询地名和地图右下角的坐标应最远(对应最少的滚动条移动);如果还有并列,则输出x坐标最小的一个。如果查询的地名不存在或者没有地图包含它,应报告查询非法。如果包含它的地图最高详细等级小于 i,应报告查询非法(并输出包含它的最详细地图名称,如果存在)。

分析

  对于每个询问,找出所有相关区域,然后用自定义比较器排一下序即可。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // 删去 x 中所有 c
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper); #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} template<class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
} inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
} //min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
return min <= aim && aim <= max;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< double > VD;
typedef vector< VI > VVI;
typedef vector< SI > VSI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e4 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; int sgn(double x) {
if(fabs(x) < EPS) return ;
return x > ? : -;
} double dist(PDD a,PDD b) {
return sqrt((a.ft - b.ft) * (a.ft - b.ft) + (a.sd - b.sd) * (a.sd - b.sd));
} struct MAP{
double U, D, L, R, Area, ratio; // 上下左右和面积以及长宽比
PDD center; // 中心点
string name; MAP() {}
MAP(string s) {
stringstream sin(s);
double x1, y1, x2, y2; sin >> name >> x1 >> y1 >> x2 >> y2;
L = min(x1, x2);
R = max(x1, x2);
U = max(y1, y2);
D = min(y1, y2);
center = MP((L + R) / , (U + D) / );
Area = (R - L) * (U - D);
ratio = fabs((R - L) / (U - D) - 0.75);
} bool cover(PDD x) {
return x.ft >= L && x.ft <= R && x.sd >= D && x.sd <= U;
} bool operator< (const MAP &x) const {
return Area > x.Area;
}
};
vector< MAP > maps; string tmp;
map< string, PDD > loc;
string target;
int level; struct MyCmp{
bool operator() (const MAP &x, const MAP &y) const {
PDD tar = loc[target]; if(sgn(x.Area - y.Area) == ) {
double a = dist(tar, x.center);
double b = dist(tar, y.center); if(sgn(a - b) == ) {
if(sgn(x.ratio - y.ratio) == ) {
a = dist(tar, MP(x.R, x.D));
b = dist(tar, MP(y.R, y.D)); if(sgn(a - b) == ) return x.L < y.L;
return a > b;
}
return x.ratio < y.ratio;
}
return a < b;
}
return x.Area > y.Area;
}
}; int main(){
//freopen("MyOutput.txt","w",stdout);
//freopen("input.txt","r",stdin);
//INIT();
getline(cin, tmp);
while(getline(cin, tmp)) {
if(tmp == "LOCATIONS") break;
maps.PB(MAP(tmp));
} while(getline(cin, tmp)) {
if(tmp == "REQUESTS") break;
stringstream sin(tmp);
double x, y; sin >> tmp >> x >> y;
loc[tmp] = MP(x, y);
} while(getline(cin, tmp)) {
if(tmp == "END") break;
stringstream sin(tmp); sin >> target >> level;
printf("%s at detail level %d ", target.c_str(), level); if(loc.find(target) == loc.end()) printf("unknown location\n");
else {
set< MAP, MyCmp > sm;
// 找出所有包含target地点的map
foreach(i, maps) if(i->cover(loc[target])) sm.insert(*i); if(sm.size() == ) printf("no map contains that location\n");
else {
auto it = sm.begin();
double t = ; while(it != sm.end()) {
if(it->Area != t) {
t = it->Area;
if(!--level) break;
}
++it;
} if(level) printf("no map at that detail level; using %s\n", sm.rbegin()->name.c_str());
else printf("using %s\n", it->name.c_str());
}
}
}
return ;
}

UVA 511 Do You Know the Way to San Jose?的更多相关文章

  1. Uva 511 Updating a Dictionary

    大致题意:用{ key:value, key:value, key:value }的形式表示一个字典key表示建,在一个字典内没有重复,value则可能重复 题目输入两个字典,如{a:3,b:4,c: ...

  2. UVA 11100 The Trip, 2007 (贪心)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. UI中经常出现的下拉框下拉自动筛选效果的实现

    小需求是当你在第一个下拉框选择了国家时,会自动更新第二个省份的下拉框,效果如下 两个下拉选择Html如下: <select id="country_select"> & ...

  4. python爬虫爬取全球机场信息

    --2013年10月10日23:54:43 今天需要获取机场信息,发现一个网站有数据,用爬虫趴下来了所有数据: 目标网址:http://www.feeyo.com/airport_code.asp?p ...

  5. 美国政府关于Google公司2013年度的财务报表红头文件

    请管理员移至新闻版块,谢谢! 来源:http://www.sec.gov/ 财务报表下载↓ 此文仅作参考分析. 10-K 1 goog2013123110-k.htm FORM 10-K   UNIT ...

  6. 2017年USNews美国大学研究生专业排名

    2017年USNEWS美国大学研究生专业排名最佳商学院排名 排名 学校 费用 注册人数 #1 Harvard University Boston, MA $61,225 per year (full- ...

  7. 【习题 5-11 UVA 12504 】Updating a Dictionary

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 不确定某个map里面是否有某个关键字的时候. 要用find来确定. 如果直接用访问下标的形式去做的话. 会强行给他加一个那个关键字( ...

  8. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  9. UVA 1412 Fund Management (预处理+状压dp)

    状压dp,每个状态可以表示为一个n元组,且上限为8,可以用一个九进制来表示状态.但是这样做用数组开不下,用map离散会T. 而实际上很多九进制数很多都是用不上的.因此类似uva 1601 Mornin ...

随机推荐

  1. AES加密php,java,.net三种语言同步实现加密、解密

    话不多数上代码: java::: /* * To change this license header, choose License Headers in Project Properties. * ...

  2. c++ GetAsyncState() 函数

    函数原型 SHORT GetAsyncKeyState(int vKey); 例:若判断 回车键 if(GetAsyncKeyState(VK_RETURN)&0x8000) ( return ...

  3. delphi常见的错误

    ******************************* * 编 译 错 误 信 息 * ******************************* ';' not allowed befo ...

  4. Java——对象

    1.2对象 1.2.1 对象的创建和使用 ①使用new + 构造器创建一个新的对象: ②使用“对象名.对象成员”的方式访问对象成员(包括属性和方法). public class Animal { pu ...

  5. selenium 无头浏览器headless browser

    无头浏览器,即没有界面的浏览器,浏览器该有的功能特性都有. if browser.lower() == "chrome": # 无头浏览器 chrome_opt = webdriv ...

  6. DataWorks2.0的“业务流程”与1.0的“工作流”的对比

    DatwWorks终于升级2.0了,心情万分激动之余,又有一丝担忧.因为,没法再创建新的旧版工作流了...新版抛弃了“工作流”这个概念,引入了“业务流程”和“解决方案”两个新的概念.于是,作为团队Le ...

  7. luoguP3951 小凯的疑惑/P2662 牛场围栏

    其实就是当年sxy给我讲的墨墨的等式,只是当时比较菜听得似懂非懂. 小凯的疑惑 去年noipday1t1,当时随便猜了个结论结果猜对了,现在瞎证一下,答案是a*b-a-b. 设a为a,b中较小的一个, ...

  8. macOS cataline 10.15 升级后问题一览

    1. git无法使用.报错如下 xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), m ...

  9. 秦曾昌人工智能课程---5、KNN和朴素贝叶斯

    秦曾昌人工智能课程---5.KNN和朴素贝叶斯 一.总结 一句话总结: 拟合和概率:构建机器学习模型,一般有拟合和概率两种方式 轻学无用:一定要保证学有所用,要深入学习,比如之前做的安卓,一定要学通, ...

  10. SecureCRT是最常用的终端仿真程序,简单的说就是Windows下登录UNIX或Liunx服务器主机的软件,本文主要介绍SecureCRT的使用方法和技巧

    SecureCRT是最常用的终端仿真程序,简单的说就是Windows下登录UNIX或Liunx服务器主机的软件,本文主要介绍SecureCRT的使用方法和技巧 VanDyke CRT 和 VanDyk ...