[刷题]算法竞赛入门经典(第2版) 5-12/UVa511 - Do You Know the Way to San Jose?
题意: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?的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 4-6/UVa508 - Morse Mismatches
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,10 ms) //UVa508 - Morse Mismatches #include< ...
- [刷题]算法竞赛入门经典(第2版) 5-15/UVa12333 - Revenge of Fibonacci
题意:在前100000个Fibonacci(以下简称F)数字里,能否在这100000个F里找出以某些数字作为开头的F.要求找出下标最小的.没找到输出-1. 代码:(Accepted,0.250s) / ...
- [刷题]算法竞赛入门经典(第2版) 5-13/UVa822 - Queue and A
题意:模拟客服MM,一共有N种话题,每个客服MM支持处理其中的i个(i < N),处理的话题还有优先级.为了简化流程方便出题,设每个话题都是每隔m分钟来咨询一次.现知道每个话题前来咨询的时间.间 ...
- [刷题]算法竞赛入门经典(第2版) 4-5/UVa1590 - IP Networks
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1590 - IP Networks #include<iost ...
- [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation
题意:模拟Petri网的执行.虽然没听说过Petri网,但是题目描述的很清晰. 代码:(Accepted,0.210s) //UVa804 - Petri Net Simulation //Accep ...
- [刷题]算法竞赛入门经典(第2版) 6-6/UVa12166 - Equilibrium Mobile
题意:二叉树代表使得平衡天平,修改最少值使之平衡. 代码:(Accepted,0.030s) //UVa12166 - Equilibrium Mobile //Accepted 0.030s //# ...
- [刷题]算法竞赛入门经典(第2版) 6-1/UVa673 6-2/UVa712 6-3/UVa536
这三题比较简单,只放代码了. 题目:6-1 UVa673 - Parentheses Balance //UVa673 - Parentheses Balance //Accepted 0.000s ...
- [刷题]算法竞赛入门经典(第2版) 5-16/UVa212 - Use of Hospital Facilities
题意:模拟患者做手术. 其条件为:医院有Nop个手术室.准备手术室要Mop分钟,另有Nre个恢复用的床.准备每张床要Mre分钟,早上Ts点整医院开张,从手术室手术完毕转移到回复床要Mtr分钟.现在医院 ...
- [刷题]算法竞赛入门经典(第2版) 5-11/UVa12504 - Updating a Dictionary
题意:对比新老字典的区别:内容多了.少了还是修改了. 代码:(Accepted,0.000s) //UVa12504 - Updating a Dictionary //#define _XieNao ...
- [刷题]算法竞赛入门经典(第2版) 5-10/UVa1597 - Searching the Web
题意:不难理解,照搬题意的解法. 代码:(Accepted,0.190s) //UVa1597 - Searching the Web //#define _XIENAOBAN_ #include&l ...
随机推荐
- 在ExpressJS中设置二级域名跨域共享Cookie
问题:我使用expressjs和mongostore来管理session.下面是expressjs中的设置. app.configure(function(){ app.use(express.ses ...
- 基于模糊聚类和最小割的层次化网格分割算法(Hierarchical Mesh Decomposition)
网格分割算法是三维几何处理算法中的重要算法,具有许多实际应用.[Katz et al. 2003]提出了一种新型的层次化网格分割算法,该算法能够将几何模型沿着凹形区域分割成不同的几何部分,并且可以避免 ...
- 请一定记得升级java虚拟机
对于吃货出身又需要保持体重的我,出门一定要带男票,因为这样就可以把见到的好吃的都买给他吃,就当是自己吃了[汗].偶尔做梦还是会梦到自己一个角落里偷吃东西,听到有脚步声,抬起头,大哭起来:“我饿了.” ...
- Linux 搭建svn版本库
一.安装svn服务器端yum install subversion 从镜像下载安装svn服务器端 如果后面执行“svnadmin create /usr/local/svn/sunny”提示 ...
- Knockout Mvc Compoment FrameSet
Knockout Mvc Compoment FrameSet 框架文件结构 01- 网站(表现层),mvc主要作用视图展示. 02- 模型(Model),主要作用承载视图数据结构,网站前后台 ...
- [SinGuLaRiTy] 2017-03-27 综合性测试
[SinGuLaRiTy-1013] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 这是 三道 USACO 的题...... 第一题:奶牛飞 ...
- [笔记]GBDT理论知识总结
一. GBDT的经典paper:<Greedy Function Approximation:A Gradient Boosting Machine> Abstract Function ...
- matlab 2016a破解中文版安装教程
之前电脑重装过,所以要重新安装一个matlab,在大三的时候学过matlab,信息老师给的安装包,但是不知道放哪里去了,记忆力不好,找了些网上的教程和下载地址,真的是坑,一些都是不行的,在这里记录下m ...
- java复习(7)---集合类、泛型
本节主要结合用例讲述Java中Map类.Set类.List类如何使用. Java中有封装好的集合类,常用的有Map类.Set类.List类,简单说明一下他们的用法. List类,常用有ArrayLis ...
- Linux防火墙配置—访问外网WEB
一.实验目标 1.本次实验在"Linux基础网络搭建实验"的基础上,在外网虚拟机上搭建WEB服务,并分别配置外网和网关的防火墙规则,使内网能够访问WEB服务 2.Linux基础网络 ...