比赛笔试链接: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. 简单打包 ipa 方式!

    应用的发布也分两种 一种是.打包成ipa上传到国内第3方软件市场,当用户的手机已经JailBreak时,双击下载的ipa文件就可以安装软件 (ipa同android的apk包一样,实质是一个压缩包) ...

  2. Java_关于App class loader的总结

    Java本身是一种设计的非常简单,非常精巧的语言,所以Java背后的原理也很简单,归结起来就是两点: 1.JVM的内存管理 理解了这一点,所有和对象相关的问题统统都能解决 2.JVM Class Lo ...

  3. Flex与.net进行URL参数传递编码处理

    在JS中用到的三种编码方式escape 对应于Flex中是一样的,并且支持相互的解码 var a:String = "超越梦想#"; trace(escape(a)); //%u8 ...

  4. js 遮罩层 loading 效果

    //调用方法 //关闭事件<button onclick='LayerHide()'>关闭</button>,在loadDiv(text)中,剔除出来 //调用LayerSho ...

  5. passing ‘const ’ as ‘this’ argument of ‘’ discards qualifiers 错误处理

    示例程序: #include <iostream> #include <set> using   namespace std ; class   StudentT { publ ...

  6. Latest node.js & npm installation on Ubuntu 12.04

    转自:https://rtcamp.com/tutorials/nodejs/node-js-npm-install-ubuntu/ Compiling is way to go for many b ...

  7. [LintCode] Happy Number 快乐数

    Write an algorithm to determine if a number is happy. A happy number is a number defined by the foll ...

  8. [CareerCup] 18.10 Word Transform 单词转换

    18.10 Given two words of equal length that are in a dictionary, write a method to transform one word ...

  9. CSS水平居中

    三种情况:1.行内元素(文本.图片等) 给父元素设置text-align:center;来实现 2.定宽块状元素 <style> div{ border:1px solid blue; w ...

  10. JAVA 打出jar包

    1.eclipse下导出 jar包:选择项目右键--->Export...----> 选择java下的JAR file---->next--->选择存入路径--->nex ...