题目链接: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. notepad++去换行(简单、快捷)

    文本处理问题 这个方式可以快捷处理, 不用Linux命令, linux 与window之间的文件转换很烦人, 这个方法可以处理

  2. 关于a标签的href属性值的区别

    一.href="javacript:;"  这种用法不正确,这么用的话会出现浏览器访问“javascript:;”这个地址的现象: 二.href="javacript:v ...

  3. 城里城外看SSDT

    引子 2006年,中国互联网上的斗争硝烟弥漫.这时的战场上,先前颇为流行的窗口挂钩.API挂钩.进程注入等技术已然成为昨日黄花,大有逐渐淡出之势:取而代之的,则是更狠毒.更为赤裸裸的词汇:驱动.隐藏进 ...

  4. [转]C# 将类的内容写成JSON格式的字符串

    将类的内容写入到JSON格式的字符串中 本例中建立了Person类,赋值后将类中内容写入到字符串中 运行本代码需要添加引用动态库Newtonsoft.Json 程序代码: using System; ...

  5. PAT_A1094#The Largest Generation

    Source: PAT A1094 The Largest Generation (25 分) Description: A family hierarchy is usually presented ...

  6. k8s 存储 nfs服务

    1.所有节点安装nfs yum install nfs-utils -y 2.配置nfs服务端,在master节点上 vim exports /data 10.0.0.0/24(rw,async,no ...

  7. python简介与安装

    Python简介和环境搭建 于 20世纪80年代末,Guido van Rossum发明了Python,初衷据说是为了打发圣诞节的无趣.1991年首次发布,是ABC语言的继承,同时也是一种脚本语言.取 ...

  8. scikit-learn 应用

    首先是sklearn的官网:http://scikit-learn.org/stable/ 在官网网址上可以看到很多的demo,下边这张是一张非常有用的流程图,在这个流程图中,可以根据数据集的特征,选 ...

  9. 16-MySQL-Ubuntu-数据表的查询-分组与聚合(五)

    分组(group by)一般与聚合结合使用 (1)查询按性别分组 select gender from students group by gender; (2)查询按性别分组并统计每组的数量sele ...

  10. python接口自动化(get请求)

    python接口自动化(get请求) get请求的目的:查询资源 一.导包 二.请求的URL 三.请求的参数 四.获取请求的URL 五.获取响应的状态码 六.获取响应的本文信息 #导包 import ...