比赛笔试链接: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. BZOJ3293: [Cqoi2011]分金币

    Description 圆桌上坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一些金币,最终使得每个人的金币数目相等.你的任务是求出被转手的金币数量的最小值. Inpu ...

  2. XCode编译文件过多导致内存吃紧解决方法

    XCode编译文件过多导致内存吃紧解决方法 /Users/~~/Library/Developer/Xcode/DerivedData 1) 然后 找到编译文件 删除 就好了哦 快去试试看吧

  3. 总结新系统部署时,Oracle的一些注意事项:

    1.Oracle安装时,要选择字符集为中文编码,数据库重要角色设置密码时,不要用数字开头,不然后面会报一些错误提示 2.emp导出的数据dmp格式,导入时要在服务器导入,具体没有试,要找机会试试,转化 ...

  4. nodejs之async异步编程

    1.什么是异步编程? 异步编程是指由于异步I/O等因素,无法同步获得执行结果时, 在回调函数中进行下一步操作的代码编写风格,常见的如setTimeout函数.ajax请求等等. 示例:  for (v ...

  5. JSch - Java实现的SFTP(文件上传详解篇)

    JSch是Java Secure Channel的缩写.JSch是一个SSH2的纯Java实现.它允许你连接到一个SSH服务器,并且可以使用端口转发,X11转发,文件传输等,当然你也可以集成它的功能到 ...

  6. Jquery用法

    $this.closest("dd").addClass("selected").siblings().removeClass("selected&q ...

  7. CAS单点登录配置

    见http://download.csdn.net/detail/u010786672/6942715下载.

  8. 解决Odoo日期(时间)无效的问题 [转]

    环境Server: Ubuntu Kylin 14 + GreenOdoo-7.0-linux64, GreenOdoo-8.0-linux64客户端: winXP+firefox 31 (类似问题发 ...

  9. mysql修改数据表名

    在使用mysql时,经常遇到表名不符合规范或标准,但是表里已经有大量的数据了,如何保留数据,只更改表名呢? 可以通过建一个相同的表结构的表,把原来的数据导入到新表中,但是这样视乎很麻烦. 能否简单使用 ...

  10. array_sum函数 number array_sum

    数组的概念 数组就是一个用来存储一系列变量值的命名区域,每个数组元素有一个相关的索引,也成为关键字,它可以用来访问元素. PHP允许间隔性地使用数字或字符串作为数组的索引. 2.数字索引数组 2.1 ...