题意:N张地图,查找某地点在不在某些地图上,若在,使用细节多的地图。使用哪个地图的破要求挺多,细心一点就好。


代码:(Accepted,0.000s)

//UVa511 - Do You Know the Way to San Jose?
//Accepted 0.000s
//#define _XIENAOBAN_
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
#define EPS 1e-7 struct mapdat {
float area,ratio, midx, midy, x1, y1, x2, y2;
int level;
string name;
mapdat(char* n, float& t1, float& t2, float& t3, float& t4) :name(n), midx((t1 + t3) / 2), midy((t2 + t4) / 2) {
if (t1 < t3) x1 = t1, x2 = t3;
else x1 = t3, x2 = t1;
if (t2 < t4) y1 = t2, y2 = t4;
else y1 = t4, y2 = t2;
area = (x2 - x1)*(y2 - y1);
ratio = (float)fabs((y2 - y1) / (x2 - x1) - 0.75);
}
}; inline bool findloc(const mapdat& m, float& x, float& y) {
return x > m.x1&&x<m.x2&&y>m.y1&&y < m.y2;
} inline float dist(const mapdat& m, float& x, float& y) {
return (x - m.midx)*(x - m.midx) + (y - m.midy)*(y - m.midy);
} vector<mapdat> maps;
map<string, pair<float, float> > locs;
char stmp[80];
int l, lev(0);
float t1, t2, t3, t4; int main()
{
#ifdef _XIENAOBAN_
#define gets(T) gets_s(T, 80)
freopen("in.txt", "r", stdin);
#endif
gets(stmp);
while (scanf("%s", stmp) != EOF && strcmp(stmp, "LOCATIONS")) {
scanf("%f%f%f%f", &t1, &t2, &t3, &t4);
maps.push_back(mapdat(stmp, t1, t2, t3, t4));
} sort(maps.begin(), maps.end(), [](mapdat& a, mapdat& b) {return a.area > b.area;});
float a(-1.0);
for (auto& r : maps) {
if (fabs(r.area - a)>EPS)
r.level = ++lev, a = r.area;
else r.level = lev;
}
//for (auto& r : maps) cout << r.level << ' ' << r.name << '\t' << r.midx << ' ' << r.midy << ' ' << r.area << endl;//
while (scanf("%s", stmp) != EOF && strcmp(stmp, "REQUESTS")) {
scanf("%f%f", &t1, &t2);
locs[stmp] = make_pair(t1, t2);
}
while (scanf("%s", stmp) != EOF && strcmp(stmp, "END")) {
scanf("%d", &l);
printf("%s at detail level %d ", stmp, l);
auto nowloc(locs.find(stmp));
if (nowloc == locs.end()) {
printf("unknown location\n");
continue;
}
vector<mapdat> m,nm;
for (const auto& r : maps)
if (findloc(r, nowloc->second.first, nowloc->second.second))
if(r.level!=l)m.push_back(r);
else nm.push_back(r);
if (m.empty()) {
printf("no map contains that location\n");
continue;
}
auto cmp = [&nowloc](mapdat& a, mapdat& b)->bool {
auto& X(nowloc->second.first),& Y(nowloc->second.second);
if (a.level != b.level) return a.level > b.level;
auto da(dist(a, X, Y)),db(dist(b, X, Y));
if (fabs(da - db) > EPS) return da < db;
if (fabs(a.ratio - b.ratio) > EPS) return a.ratio < b.ratio;
da = (X - a.x2)*(X - a.x2) + (Y - a.y1)*(Y - a.y1);
db = (X - b.x2)*(X - b.x2) + (Y - b.y1)*(Y - b.y1);
if (fabs(db - da) > EPS) return da > db;
return a.x1 < b.x1;
};
if (nm.empty()) {
sort(m.begin(), m.end(), cmp);
if (m[0].level < l) printf("no map at that detail level; ");
printf("using %s\n", m[0].name.c_str());
continue;
}
sort(nm.begin(), nm.end(), cmp);
printf("using %s\n", nm[0].name.c_str());
}
return 0;
}

分析:状态不好没认真编,编的比较乱比较丑。还没开始优化,想着先提交个试试,结果这也0.000s通过了。。。看来数据比较水。那就不改动不优化了。

[刷题]算法竞赛入门经典(第2版) 5-12/UVa511 - Do You Know the Way to San Jose?的更多相关文章

  1. [刷题]算法竞赛入门经典(第2版) 4-6/UVa508 - Morse Mismatches

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,10 ms) //UVa508 - Morse Mismatches #include< ...

  2. [刷题]算法竞赛入门经典(第2版) 5-15/UVa12333 - Revenge of Fibonacci

    题意:在前100000个Fibonacci(以下简称F)数字里,能否在这100000个F里找出以某些数字作为开头的F.要求找出下标最小的.没找到输出-1. 代码:(Accepted,0.250s) / ...

  3. [刷题]算法竞赛入门经典(第2版) 5-13/UVa822 - Queue and A

    题意:模拟客服MM,一共有N种话题,每个客服MM支持处理其中的i个(i < N),处理的话题还有优先级.为了简化流程方便出题,设每个话题都是每隔m分钟来咨询一次.现知道每个话题前来咨询的时间.间 ...

  4. [刷题]算法竞赛入门经典(第2版) 4-5/UVa1590 - IP Networks

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1590 - IP Networks #include<iost ...

  5. [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation

    题意:模拟Petri网的执行.虽然没听说过Petri网,但是题目描述的很清晰. 代码:(Accepted,0.210s) //UVa804 - Petri Net Simulation //Accep ...

  6. [刷题]算法竞赛入门经典(第2版) 6-6/UVa12166 - Equilibrium Mobile

    题意:二叉树代表使得平衡天平,修改最少值使之平衡. 代码:(Accepted,0.030s) //UVa12166 - Equilibrium Mobile //Accepted 0.030s //# ...

  7. [刷题]算法竞赛入门经典(第2版) 6-1/UVa673 6-2/UVa712 6-3/UVa536

    这三题比较简单,只放代码了. 题目:6-1 UVa673 - Parentheses Balance //UVa673 - Parentheses Balance //Accepted 0.000s ...

  8. [刷题]算法竞赛入门经典(第2版) 5-16/UVa212 - Use of Hospital Facilities

    题意:模拟患者做手术. 其条件为:医院有Nop个手术室.准备手术室要Mop分钟,另有Nre个恢复用的床.准备每张床要Mre分钟,早上Ts点整医院开张,从手术室手术完毕转移到回复床要Mtr分钟.现在医院 ...

  9. [刷题]算法竞赛入门经典(第2版) 5-11/UVa12504 - Updating a Dictionary

    题意:对比新老字典的区别:内容多了.少了还是修改了. 代码:(Accepted,0.000s) //UVa12504 - Updating a Dictionary //#define _XieNao ...

  10. [刷题]算法竞赛入门经典(第2版) 5-10/UVa1597 - Searching the Web

    题意:不难理解,照搬题意的解法. 代码:(Accepted,0.190s) //UVa1597 - Searching the Web //#define _XIENAOBAN_ #include&l ...

随机推荐

  1. iwebshop两表联查

    $tb_goods = new IQuery('goods as g'); $tb_goods->join='left join miao as m on m.goods_id=g.id'; $ ...

  2. JavaScript作用域链和垃圾回收机制

    作用域链 基本概念: 在了解作用域链和内存之前,我们先了解两个概念,分别是执行环境和变量对象. 执行环境:定义变量或者函数有权访问的其他数据,决定了它们各自的行为.每个对象都有自己的执行环境. 变量对 ...

  3. Oracle SQL 语言分类

     Oracle SQL语句分类 2008-06-17 11:15:25 分类: Linux * 2008/06/17  星期二*蒙昭良*环境:WindowsXP + Oracle10gR2*Oracl ...

  4. js-面试题之字符串

    问题:输入两个字符串,从第一个字符串中删除第二个字符串中的所有字符串不可以使用replace<!--例如:输入"They are students" 和"aeiou ...

  5. 第5章Zabbix自动化监控

    p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; text-align: justify; t ...

  6. Visual Studio 2017创建.net standard类库编译出错原因

    正式版上个月已经Release了,从那时到现在经常会收到更新提示,估计问题还不少吧!其中最吸引我的当然是.net standard与.net core. 刚好最近接触.net standard项目,新 ...

  7. 对象的创建过程(chapter5.7.3)

    总结一下对象的创建过程,假设有一个名为Dog的类: 1. 即使没有显示地使用static关键字,构造器实际上也是静态的方法,因此,当首次创建类型为Dog的对象时(构造器可以看成静态方法),或者Dog类 ...

  8. Windows入门基础:1.关于CreateWindow()函数使用中遇到的问题

    我在实现显示窗口的程序中,遇到一个问题:首先程序没有任何语法错误,编译能够通过,但是就是不能弹出窗口. 后来在MSDN中查询CreateWindow()函数,发现了下面这句话: "If lp ...

  9. python executemany的使用

    使用executemany对数据进行批量插入的话,要注意一下事项: #coding:utf8 conn = MySQLdb.connect(host = "localhost", ...

  10. linux sed命令就是这么简单

    概述 sed命令是一个面向字符流的非交互式编辑器,也就是说sed不允许用户与它进行交互操作.sed是按行来处理文本内容的.在shell中,使用sed来批量修改文本内容是非常方便的. sed命令的选项 ...