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 + ;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
std::vector<int>path;
const int INF = << ;
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[ << ][];
int dx[] = { -, , , };
int dy[] = {, -, , };
int dist[][];
int main() {
ios_base::sync_with_stdio( false );
cin.tie( );
while ( cin >> w >> h ) {
map<Point, int>id;
P.clear();
path.clear();
memset( d, , sizeof d );
memset( dist, , sizeof dist );
for ( int i = ; i < h; i++ ) {
scanf( "%s", mat[i] );
for ( int j = ; 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 - ]] = sz;
if ( c == 'S' ) { s = sz - ; }
else if ( c == 'G' ) { e = sz - ; }
path.pb( sz - );
}
}
}
for ( int i = ; i < path.size(); i++ ) {
Point now = P[path[i]];
int x = path[i];
//out<<"x "<<x<<endl;
dist[x][x] = ;
memset( vis, , sizeof vis );
vis[now.x][now.y] = ;
queue<Point>q;
q.push( now );
//cout<<"Bfs"<<endl;
while ( !q.empty() ) {
now = q.front(); q.pop();
for ( int i = ; i < ; i++ ) {
int nx = now.x + dx[i], ny = now.y + dy[i];
if ( nx >= && nx < h && ny >= && ny < w && mat[nx][ny] != '#' && !vis[nx][ny] ) {
Point tp = ( Point ) {nx, ny};
q.push( tp );
vis[nx][ny] = vis[now.x][now.y] + ;
if ( id[tp] ) {
dist[x][id[tp] - ] = vis[now.x][now.y];
//cout<<"dist "<<x<<" to "<<id[tp]-1<<' '<<dist[x][id[tp]-1]<<endl;
}
}
}
}
}
d[ << s][s] = ;
int M = path.size();
for ( int i = ; i < ( << M ); ++i ) {
for ( int j = ; j < M; j++ ) {
int p = path[j];
for ( int k = ; << k <= i; k++ ) {
if ( i & ( << k ) ) {
d[i | ( << p )][p] = min( d[i | ( << p )][p], d[i][k] + dist[k][p] );
}
}
}
}
cout << d[( << M ) - ][e] << endl;
}
return ;
}

2014 WAP校园招聘笔试题的更多相关文章

  1. google2013校园招聘笔试题(全国)

    google2013校园招聘笔试题 1. 单项选择题1.1如果把传输速率定义为单位时间内传送的信息量(以字节计算)多少.关于一下几种典型的数据传输速率:1.使用USB2.0闪存盘,往USB闪存盘上拷贝 ...

  2. Microsoft 2013校园招聘笔试题及解答

    Microsoft 2013校园招聘笔试题及解答 题目是自己做的,求讨论.吐槽.拍砖 1.      Which of the following callingconvension(s) suppo ...

  3. Microsoft2013校园招聘笔试题

    Microsoft2013校园招聘笔试题 继续求拍砖!!!! 1. You are managing the database of a book publichser, you currently ...

  4. C# - 2017微软校园招聘笔试题 之 MS Recognition[待解决]

    MS Recognition 在线提交: hihoCoder 1402 http://hihocoder.com/problemset/problem/1402 类似: OpenJudge - I:P ...

  5. 京东2017校园招聘笔试题 【第K个幸运数】

    题目描述 4和7是两个幸运数字,我们定义,十进制表示中,每一位只有4和7两个数的正整数都是幸运数字. 前几个幸运数字为:4,7,44,47,74,77,444,447... 现在输入一个数字K,输出第 ...

  6. 九度OJ 1531 货币面值(网易游戏2013年校园招聘笔试题) -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1531 题目描述: 小虎是游戏中的一个国王,在他管理的国家中发行了很多不同面额的纸币,用这些纸币进行任意的组合可以在 ...

  7. PPS2013校园招聘笔试题

    转载请标明出处,原文地址:http://blog.csdn.net/hackbuteer1/article/details/11473405 一.简答题 (1)一位老师有2个推理能力很强的学生,他告诉 ...

  8. Microsoft2013校园招聘笔试题及解答

    继续求拍砖!!!! 1. You are managing the database of a book publichser, you currently store the book orders ...

  9. 2012Google校园招聘笔试题

    1.已知两个数字为1~30之间的数字,甲知道两数之和,乙知道两数之积,甲问乙:“你知道是哪两个数吗?”乙说:“不知道”.乙问甲:“你知道是哪两个数吗?”甲说:“也不知道”.于是,乙说:“那我知道了”, ...

随机推荐

  1. [ay原创作品]用wpf写了个模仿36Kr网站登录背景的效果

    这里我借鉴了,上周比较火的一个前端文章,人家用js去写的,地址 自己用wpf也写了一个,但是它的  粒子比较,然后连线算法真的很差,他创建了一个加入鼠标点的集合,2个集合进行比较,并且粒子会向鼠标靠近 ...

  2. Node.js 在 PayPal实战

    之前有过一个谈了很多关于PayPal移动到node.js的一个应用平台.作为设置我的免费用户界面的第1部分的延续,我很高兴地说,这些传言是真的,我们的Web应用程序正在从Java迁移到JavaScri ...

  3. c++ bind1st 和 bind2nd的用法

    std::bind1st 和 std::bind2nd将二元函数转换为一元函数,具体用法参加下面的代码. 代码介绍了两种使用方式,第一种是使用std::less和std::greater,第二种是使用 ...

  4. mediawiki的管理与使用

    本文主要讲述搭建好私有的mediawiki之后,管理员可能需要用到的几个功能.   维基百科的设计思路与我以往使用的系统不太一样,以管理员模式进入之后,并没有我预想的添加wiki页面入口,和侧边栏导航 ...

  5. 在java项目中使用log4j的实例

    测试log4j的项目结构 Log4j.properties的路径为    src/config/log4j Log4j.properties文件的内容 下面定义日志输出级别是 INFO,并且配置了2个 ...

  6. 3.C#中的多重委托

    阅读目录 一:多重委托概述   二:多重委托实例    一:多重委托概述 1.委托的调用其实是一个调用列表,可以同时调用多个不同的方法 2.第1个委托加上第2个委托赋予第3个委托,相当于把两个方法按顺 ...

  7. PHP 中 Orientation 属性判断上传图片是否需要旋转(转)

    <?php $image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name'])); $ex ...

  8. mysql用shell建100多字段表并导入

    excel列超过160多个,导入时报错,把excel第一行另存为逗号分隔的csv文件,用shell建表 vim createTable.sh #!/bin/sh str="CA6430M,H ...

  9. 单线程vs多线程

    a.多线程可以说是实现异步的一种方式: b.共同点:多线程和异步操作两者都可以达到避免调用线程阻塞的目的,从而提高软件的可响应性: c.线程消费CPU资源.  异步消费硬件资源: 1.多线程和异步操作 ...

  10. wndows系统命令总结

    window8系统下 打开运行窗口----------鼠标放到任务栏的windows图标下,右击,弹出菜单中如上图或者 打开运行窗口---------按“WIN+R”键, cmd-------打开命令 ...