2014 WAP校园招聘笔试题

Problem's Link:   http://www.doc88.com/p-6751117015483.html


WAP公司笔试题

We are planning an orienteering game.
The aim of this game is to arrive at the goal (G) from the start (S) with the shortest distance.
However, the players have to pass all the checkpoints (@) on the map.
An orienteering map is to be given in the following format.
########
#@....G#
##.##@##
#..@..S#
#@.....#
########
In this problem, an orienteering map is to be given.
Calculate the minimum distance from the start to the goal with passing all the checkpoints.
Specification
* A map consists of 5 characters as following.
You can assume that the map does not contain any invalid characters and
the map has exactly one start symbol 'S' and exactly one goal symbol 'G'.
* 'S' means the orienteering start.
* 'G' means the orienteering goal.
* '@' means an orienteering checkpoint.
* '.' means an opened-block that players can pass.
* '#' means a closed-block that players cannot pass.
* It is allowed to move only by one step vertically or horizontally (up, down, left, or right) to the
next block.
Other types of movements, such as moving diagonally (left up, right up, left down and right down)
and skipping one or more blocks, are NOT permitted.
* You MUST NOT get out of the map.
* Distance is to be defined as the number of movements to the different blocks.
* You CAN pass opened-blocks, checkpoints, the start, and the goal more than once if necessary.
* You can assume that parameters satisfy following conditions.
* 1 <= width <= 100
* 1 <= height <= 100
* The maximum number of checkpoints is 18.

几个样例:

<Input>
5 4
#####
#...#
#S#G#
#####
<Output>
4

<Input>
5 5
#####
#.@@#
#S###
#..G#
#####
<Output>
9

<Input>
5 5
#####
#S..#
##G##
#..@#
#####
<Output>
6

Mean:

M

analyse:

A

Time complexity: O(n)

Source code: 

/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-05-21-23.40
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define  LL long long
#define  ULL unsigned long long
using namespace std;const int maxn = 1e2 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
std::vector<int>path;
const int INF = 1 << 20;
struct Point
{int x, y;bool operator < ( const Point &a )const{return x < a.x || ( x == a.x ) && y < a.y;}
};
std::vector<Point>P;
char mat[maxn][maxn];
int vis[maxn][maxn];
int w, h, s, e;
int d[1 << 20][20];
int dx[] = { -1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
int dist[25][25];
int main() {ios_base::sync_with_stdio( false );cin.tie( 0 );while ( cin >> w >> h ) {map<Point, int>id;P.clear();path.clear();memset( d, 100, sizeof d );memset( dist, 100, sizeof dist );for ( int i = 0; i < h; i++ ) {scanf( "%s", mat[i] );for ( int j = 0; mat[i][j]; ++j ) {char &c = mat[i][j];if ( c == 'S' || c == 'G' || c == '@' ) {P.pb( ( Point ) {i, j} );int sz = P.size();id[P[sz - 1]] = sz;if ( c == 'S' ) { s = sz - 1; }else if ( c == 'G' ) { e = sz - 1; }path.pb( sz - 1 );}}}for ( int i = 0; i < path.size(); i++ ) {Point now = P[path[i]];int x = path[i];//out<<"x "<<x<<endl;dist[x][x] = 0;memset( vis, 0, sizeof vis );vis[now.x][now.y] = 1;queue<Point>q;q.push( now );//cout<<"Bfs"<<endl;while ( !q.empty() ) {now = q.front(); q.pop();for ( int i = 0; i < 4; i++ ) {int nx = now.x + dx[i], ny = now.y + dy[i];if ( nx >= 0 && nx < h && ny >= 0 && ny < w && mat[nx][ny] != '#' && !vis[nx][ny] ) {Point tp = ( Point ) {nx, ny};q.push( tp );vis[nx][ny] = vis[now.x][now.y] + 1;if ( id[tp] ) {dist[x][id[tp] - 1] = vis[now.x][now.y];//cout<<"dist "<<x<<" to "<<id[tp]-1<<' '<<dist[x][id[tp]-1]<<endl;
                        }}}}}d[1 << s][s] = 0;int M = path.size();for ( int i = 0; i < ( 1 << M ); ++i ) {for ( int j = 0; j < M; j++ ) {int p = path[j];for ( int k = 0; 1 << k <= i; k++ ) {if ( i & ( 1 << k ) ) {d[i | ( 1 << p )][p] = min( d[i | ( 1 << p )][p], d[i][k] + dist[k][p] );}}}}cout << d[( 1 << M ) - 1][e] << endl;}return 0;
}

View Code

2014 WAP校园招聘笔试题相关推荐

  1. 2014迅雷校园招聘笔试题(C++)

    2014迅雷校园招聘笔试题(C++)     这是迅雷在深圳那边招聘的笔试题!!也快到我们武汉来面试笔试了吧~~ 时间:2013-9-7 地点:北京大学深圳研究生院 技术类别:C++开发 说明:图片是 ...

  2. 2014迅雷校园招聘笔试题答案

    目前暂时只做了选择题部分,不保证没有错误,仅供参考,祝愿大家和我今年都能找到满意的工作哦~ 选择题答案部分 单选题 1.B 2.A p为指针,32位地址的指针大小为4个字节 3.D str为数组,勿忘 ...

  3. 阿里巴巴集团2014秋季校园招聘笔试题

    转载请标明出处,原文地址:http://blog.csdn.net/hackbuteer1/article/details/11931173 第一部分 单选题(前10题,每题2分:后10题,每题3分, ...

  4. 2014阿里巴巴校园招聘笔试题 - 中南站

    转载于:https://www.cnblogs.com/gotodsp/articles/3530329.html

  5. 2014迅雷校园招聘笔试题

    温馨提示:客观题和主观题得分都要超过一定标准,才能获得面试资格,如果一项得分很高,而另外一项得分很低,可能无法获得面试资格. 一.单选题(20题,每题2分) 1.有变量int i = 0; int a ...

  6. [历年IT笔试题]2014迅雷校园招聘笔试题

  7. 2014 创新工场校园招聘笔试题(武汉站)

    第一部分  单选题 第二部分  编程题 (1) 实现堆排序 (2)求一个正整数N的开方,要求不能用库函数sqrt,结果精度在0.001即可. (3)给定一个矩阵intmatrixA[m][n],每行每 ...

  8. 2014创新工场校园招聘笔试题(9.16北京)

    选择题 1. 若进栈序列为a.b.c.d,进栈过程中可以出栈,那么()不可能是一个出栈序列. A.cbad     B.bdca     C.adbc    D.cdba 2. 完全二叉树中编号为i的 ...

  9. 2014阿里巴巴校园招聘笔试题(中南站)

最新文章

  1. 2021年大数据Flink(二十九):Flink 容错机制 Savepoint
  2. Nginx入门笔记之————配置文件结构
  3. 死锁产生原因-竞争不可剥夺资源
  4. Callable和Future
  5. 配置MYSQL基于GTID 主从复制详细解析及步骤
  6. .NET代码混淆学习和解决视频批量转换中.wmv转换出错问题
  7. java中主线程首先执行_java经典面试题:子线程先运行30次主线程,主线程40次,如此循环50次?...
  8. 3班的第一次模拟面试
  9. “约见“面试官系列之各系列目录汇总(建议学习收藏)
  10. 2020-09-01
  11. HTML5新特性基础学习笔记下
  12. 【IDEA】idea 运行测试类报错 Failed to resolve org.junit.platform:junit-platform-launcher:1.5.2
  13. 横向越权访问java_基于ThinkPhp5开发横向越权逻辑漏洞安全指南
  14. 【数据结构】二叉树的python实现
  15. Mac下Android相关配置
  16. 小程序 ---- (引入iconfont,自定义组件内不显示iconfont)
  17. 华为手机照片 计算机,教你华为手机怎么传照片到电脑上去
  18. 偏差方差分解中为什么第三行第六行为零
  19. 视频如何去水印-免费视频水印去除工具
  20. 2022-忙碌的一年

热门文章

  1. 菜鸟建站别发愁,省钱建站新攻略!
  2. 基于场景建模的自动化配置
  3. speedtest命令行测试带宽
  4. 知识科普:布线系统的施工顺序是什么
  5. 通过WebViewJavascriptBridge实现OC与JS交互
  6. Parallel Python实现程序的并行多cpu多核利用【pp模块】
  7. 【剑道之道】亦是生存之道
  8. 【stanford C++】——2.C++中函数
  9. 如何在AjaxPro.net的AjaxMethod中使用session和cookie
  10. 一分钟就可以轻松将文字转换成语音,简单方法讲解