比赛笔试链接:http://hihocoder.com/contest/ntest2015april/problems

题目就不贴了。

1、推箱子。

思路:纯模拟。

代码(28MS):

 #include <bits/stdc++.h>
using namespace std; const int MAXV = ; const char str_op[] = "dulr";
int fx[] = {, -, , };
int fy[] = {, , -, }; inline int id(char c) {
static const char op[] = "dulr";
return strchr(op, c) - op;
} char op[MAXV];
int len;
char mat[][];
int n, m, s; int sx, sy, vx, vy, ex, ey; void init() {
for(int i = ; i <= n; ++i)
for(int j = ; j <= m; ++j) {
if(mat[i][j] == '') sx = i, sy = j;
if(mat[i][j] == '') ex = i, ey = j;
if(mat[i][j] == '') vx = i, vy = j;
}
} bool solve() {
int x1 = sx, y1 = sy, x2 = vx, y2 = vy;
for(int i = ; i < len; ++i) {
int f = id(op[i]);
int new_x = x1 + fx[f], new_y = y1 + fy[f];
if(new_x == x2 && new_y == y2) {
int pp = x2 + fx[f], qq = y2 + fy[f];
if(mat[pp][qq] != '') {
x1 = new_x, y1 = new_y;
x2 = pp, y2 = qq;
}
} else if(mat[new_x][new_y] != '') {
x1 = new_x, y1 = new_y;
}
if(x2 == ex && y2 == ey) return true;
}
return false;
} int main() {
memset(mat, '', sizeof(mat));
scanf("%d%d%d", &m, &n, &s);
for(int i = ; i <= n; ++i)
for(int j = ; j <= m; ++j) scanf(" %c", &mat[i][j]);
init();
while(s--) {
scanf("%d %s", &len, op);
puts(solve() ? "YES" : "NO");
}
}

2、井字棋

思路:俗称井字过三关。题目没有提到的三种不合法情况:

①XO都有3连

②X有3连,但是count(X)=count(O)

③O有3连,但是count(X)-1=count(O)

其他不难。人工手动枚举大法好。简单粗暴不易出错。

不过我又成功在通过样例之前把代码交了上去导致WA20(不算罚时就是好啊)

代码(15MS):

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long LL; int f[][] = {
{, , },
{, , },
{, , },
{, , },
{, , },
{, , },
{, , },
{, , }
}; char mat[];
int wino[], winx[];
int T; void build_check(int win[], char c) {
for(int i = ; i < ; ++i) {
win[i] = ;
for(int j = ; j < ; ++j)
if(mat[f[i][j]] != c) win[i] = ;
}
} int build_count(char c) {
return count(mat, mat + , c);
} bool next_win(char c) {
int win[];
for(int i = ; i < ; ++i) if(mat[i] == '_') {
mat[i] = c;
build_check(win, c);
if(count(win, win + , )) return true;
mat[i] = '_';
}
return false;
} int solve() {
int xcnt = build_count('X'), ocnt = build_count('O');
if(xcnt != ocnt && xcnt - != ocnt) return puts("Invalid"); build_check(winx, 'X');
build_check(wino, 'O');
if(count(winx, winx + , ) > && count(wino, wino + , ) > ) return puts("Invalid");
if(count(winx, winx + , ) > && xcnt == ocnt) return puts("Invalid");
if(count(wino, wino + , ) > && xcnt - == ocnt) return puts("Invalid"); if(count(winx, winx + , ) > ) return puts("X win");
if(count(wino, wino + , ) > ) return puts("O win"); if(build_count('_') == ) return puts("Draw"); if(next_win(xcnt == ocnt ? 'X' : 'O')) return puts("Next win");
return puts("Next cannot win");
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%s", mat);
scanf("%s", mat + );
scanf("%s", mat + );
solve();
}
}

3、连连看

思路:参照最小转弯问题:http://www.cnblogs.com/oyking/p/3756208.html

估计直接来个heap+dijkstra也能100分把。

代码(302MS):

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f; struct Node {
int f, x, y;
Node() {}
Node(int f, int x, int y):
f(f), x(x), y(y) {}
}; int fx[] = {-, , , };
int fy[] = {, , , -}; int dis[][MAXN][MAXN];
int mat[MAXN][MAXN];
bool vis[MAXN][MAXN];
int T, n, m; int bfs(int x1, int y1, int k) {
memset(vis, , sizeof(vis)); vis[x1][y1] = true;
memset(dis, 0x3f, sizeof(dis));
queue<Node> *now = new queue<Node>();
queue<Node> *nxt = new queue<Node>();
int step = , res = ;
for(int i = ; i < ; ++i) now->push(Node(i, x1, y1));
for(int i = ; i < ; ++i) dis[i][x1][y1] = ;
while(step <= k && !now->empty()) {
Node t = now->front(); now->pop();
if(dis[t.f][t.x][t.y] != step) continue;
for(int i = ; i < ; ++i) {
if((t.f + ) % == i) continue;
int x = t.x + fx[i], y = t.y + fy[i], d = dis[t.f][t.x][t.y] + (t.f != i);
if(mat[x][y] == mat[x1][y1] && !vis[x][y] && d <= k) {
vis[x][y] = true;
res++;
}
if(mat[x][y] == && d < dis[i][x][y]) {
dis[i][x][y] = d;
if(t.f == i) now->push(Node(i, x, y));
else nxt->push(Node(i, x, y));
}
}
if(now->empty()) {
step++;
swap(now, nxt);
}
}
return res;
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
memset(mat, 0x3f, sizeof(mat));
for(int i = ; i <= n + ; ++i)
for(int j = ; j <= m + ; ++j) scanf("%d", &mat[i][j]);
for(int i = ; i <= n + ; ++i)
for(int j = ; j <= m + ; ++j)
if(mat[i][j] == INF) mat[i][j] = ; int x, y, k;
scanf("%d%d%d", &x, &y, &k);
printf("%d\n", bfs(x + , y + , k));
}
}

hihocoder 网易游戏2016实习生招聘在线笔试 解题报告的更多相关文章

  1. 微软2016校园招聘在线笔试之Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  2. 腾讯2019年暑期实习生招聘在线笔试技术研究和数据分析方向第二题(python)

    def printindex(n,arr): # n = int(input()) # arr = list(map(int,input().split(' '))) li1=[] li2=[] fo ...

  3. 微软2016校园招聘在线笔试-Professor Q's Software

    题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...

  4. 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...

  5. 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]

    传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...

  6. 微软2016校园招聘在线笔试 [Recruitment]

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A company plans to recruit some new employees. There are N ca ...

  7. 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场

    题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...

  8. USACO 2016 US Open Contest, Gold解题报告

    1.Splitting the Field http://usaco.org/index.php?page=viewproblem2&cpid=645 给二维坐标系中的n个点,求ans=用一个 ...

  9. hihoCoder 1051 补提交卡 最详细的解题报告

    题目来源:补提交卡 解题思路:假设未提交程序的天数为:a1,a2,....,an,补交的张数为M.依次从a1,a2,....,an中去掉连续的 K 天(0<=K<=M),然后再来计算剩余数 ...

随机推荐

  1. Install the Maven in your computer

    While, this blog will talk about installing the Maven in your computer. There are three steps as fol ...

  2. Excel中COUNTIFS函数统计词频个数出现次数

    Excel中COUNTIFS函数统计词频个数出现次数   在Excel中经常需要实现如下需求:在某一列单元格中有不同的词语,有些词语相同,有的不同(如图1所示).需要统计Excel表格中每个词语出现的 ...

  3. iOS 发布遇到的问题 (转载)

    1.ios图片命名Icon-120.png – 120×120 iphone & ipod touch(ios7)  http://blog.csdn.net/xyxjn/article/de ...

  4. webdriver中定位元素,报无法找到元素的问题

    webdriver中定位元素,报无法找到元素的问题时,需要查看以下几点: 1 用火狐的firebug插件定位元素,确保这个元素的定位正确: 2 在火狐的firebug插件的,在html页签中输入fra ...

  5. express3.0安装并使用layout模板

    转自:http://cnodejs.org/topic/5073989b01d0b801480520e4 1.安装 express-partials. 方法一:运行 cmd 用 npm install ...

  6. java中用过滤器解决字符编码问题

    java的web程序经常出现中文乱码的问题,用一个实现了Filter接口的过滤器类可以较好地解决这个问题. 方式一 EncodingFilter import java.io.IOException; ...

  7. thinkphp关联模型的用法

    HAS_ONE(值得注意的是,这是主动关联,外键必须是被关联的表): <?php namespace Home\Model; use Think\Model\RelationModel; cla ...

  8. CSS,bootstrap表格控制当td内容过长时用省略号表示,以及在不使用bootstrap时过长也用省略号表示

    首先需要在table中设置table-layout:fixed; <table style="table-layout:fixed"></table> 然后 ...

  9. Rails problem

    总是wa~ #include <stdio.h> int main() { ]; ], b[]; while(scanf("%d %s %s", &n, a, ...

  10. 【转】C#(ASP.Net)获取当前路径的方法集合

    转自:http://www.gaobo.info/read.php/660.htm //获取当前进程的完整路径,包含文件名(进程名). string str = this.GetType().Asse ...