题目链接:http://hihocoder.com/contest/mstest2016april1/problems

第一题:输入N,P,W,H,代表有N段文字,每段有ai个字,每行有⌊W/S⌋个字,每页有⌊H/S⌋行,每段结束换行,希望总页数不超过P,求最大的S。

题解: 没什么好说的,本来想二分S,结果发现N才1000,直接暴力。0ms过的。【我才不会说交错语言CE这种事

 #include <cstdio>
#include <cmath>
using namespace std;
int a[];
int main()
{
int t;
int n, w, h, p;
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &n, &p, &w, &h);
for (int i = ; i < n; ++i) scanf("%d", a + i);
for (int s = w; s > ; --s) {
int cnt = ;
for (int i = ; i < n; ++i) {
cnt += ceil((double)a[i] / floor((double)w / s));
}
if (ceil((double)cnt / floor((double)h / s)) <= p) {
printf("%d\n", s);
break;
}
} }
return ;
}

第二题:先给N个字符串allow或deny,然后是一段ip,点分十进制的形式。后面可能会有掩码位数。然后给M个字符串表示ip(无掩码),如果能找到与上面符合的,allow输出YES,deny输出NO,找不到也输出YES。符合是指化成二进制后前掩码位数的数字相同。如果有多个匹配以第一个为标准。

题解:很容易想到字典树,可惜实在是太弱,写了好久,还好是1A。先预处理出0~255的二进制。然后把每个ip化成字符串,几位掩码字符串就截断到几位,否则就是32位。

 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int KIND = ;
const int MAXN = ;
int cnt_node; struct node{
node* nt[];
int flag;
int cnt;
void init(){
memset(nt, , sizeof(nt));
flag = -;
cnt = ;
}
} Heap[MAXN]; inline node* new_node()
{
Heap[cnt_node].init();
return &Heap[cnt_node++];
} void insert(node* root, char *str, int flag, int cnt)
{
for(char *p = str; *p; ++p){
int ch = *p - '';
if(root->nt[ch] == NULL)
root->nt[ch] = new_node();
root = root->nt[ch];
}
if (root->flag == -) {
root->flag = flag;
root->cnt = cnt;
}
} int count(node* root, char *str)
{
int cnt = ;;
int ans = -; //printf("flag - %d\n", root->flag);
if(root->flag != - && root->cnt < cnt) {
cnt = root->cnt;
ans = root->flag; }
for(char *p = str; *p; ++p){
int ch = *p - '';
if(root->nt[ch] == NULL) {
return ans;
}
root = root->nt[ch];
if(root->flag != - && root->cnt < cnt) {
cnt = root->cnt;
ans = root->flag;
}
}
return ans;
} int num[][];
void init()
{
for (int i = ; i <= ; i++) {
for (int j = ; j < ; j++) {
if (i & ( << j)) num[i][ - j - ] = ;
}
}
// for (int i = 0; i < 20; ++i) {
// for (int j = 0; j < 8; ++j)
// printf("%d", num[i][j]); printf("\n");
// }
}
//10000000 01111111 0000/1000 01111101 128.127.8.125/20 void input(char *s)
{
int a[], mark = ;
scanf("%d.%d.%d.%d", &a[], &a[], &a[], &a[]);
//printf("%d %d %d %d", a[0], a[1], a[2], a[3]);
char ch;
scanf("%c", &ch);
if (ch == '/') scanf("%d", &mark); for (int i = ; i < ; ++i) {
for (int j = ; j < ; ++j) {
s[i * + j] = num[ a[i] ][j] + '';
}
}
s[mark] = ;
//printf(" s = %s\n", s);
} int main()
{
init();
int n, m;
while(scanf("%d%d", &n, &m) != EOF)
{
cnt_node = ;
node *root = new_node();
char s[], op[];
for (int i = ; i < n; ++i) {
scanf("%s", op);
input(s);
//printf("%s\n", s);
insert(root, s, *op == 'a' ? : , i);
}
for (int i = ; i < m; ++i) {
input(s);
//printf("%s\n", s);
if (count(root, s) == - || count(root, s) == ) printf("YES\n");
else printf("NO\n");
}
}
return ;
}

第三题:一个机器人只会向右走和向下走,碰到墙才会转弯,问至少改变几块墙(即墙变为空地或空地变为墙),使机器人可以从左上角走到右下角。一开始的方向是向右。

题解:一眼就想到dp,dp[i][j][k]表示从(0,0)走到(i,j)且方向是k的最少花费。k为0表示向右,k为1表示向下。可惜转移那里想了很久,就是有点蒙,重复考虑了一些情况,代码写的比较慢(主要是第二题浪费了太多时间),总之就是没来的提交,赛后A的。

对于每一个点都有向下和向右两种情况,每一种情况都有可能是从左边和上边转移过来的。比如向下的可能是下面两种情况,向右同理。

 #include <cstdio>
#include <algorithm>
using namespace std;
char mp[][];
int dp[][][];
int n, m; int isWall(int i, int j) { if (i == n || j == m || mp[i][j] == 'b') return ; return ; }
int notWall(int i, int j) { if (i == n || j == m || mp[i][j] == 'b') return ; return ; } int main()
{
scanf("%d%d", &n, &m);
for (int i = ; i < n; ++i) scanf("%s", mp[i]); for (int i = ; i < n; ++i) {
for (int j = ; j < m; ++j) {
if (i == ) {
if (j == ) {
dp[i][j][] = ;
dp[i][j][] = notWall(i, j+);
} else {
dp[i][j][] = dp[i][j-][];
dp[i][j][] = dp[i][j-][] + notWall(i, j+);
}
} else {
if (j == ) {
dp[i][j][] = dp[i-][j][] + notWall(i+, j);
dp[i][j][] = dp[i-][j][];
} else {
dp[i][j][] = min(dp[i][j-][], dp[i-][j][] + notWall(i+, j));
dp[i][j][] = min(dp[i-][j][], dp[i][j-][] + notWall(i, j+));
}
} dp[i][j][] += isWall(i, j);
dp[i][j][] += isWall(i, j);
}
}
printf("%d\n", min(dp[n - ][m - ][], dp[n-][m-][]));
return ;
}

第四题没做。。。。。跪、、、

总之就是GG了。。。。

微软2016校园招聘4月在线笔试 ABC的更多相关文章

  1. hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)

    hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...

  2. 微软2016校园招聘4月在线笔试 A FontSize

    题目链接:http://hihocoder.com/problemset/problem/1288 分析:题目中所求的是最大的FontSize(记为S),其应该满足P*[W/S]*[H/S] > ...

  3. 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 Little Hi runs a web server. Sometimes he has to deny acces ...

  4. [Hihocoder 1289] 403 Forbidden (微软2016校园招聘4月在线笔试)

    传送门 #1289 : 403 Forbidden 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi runs a web server. Someti ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. 【java】Servlet 工程 web.xml 中的 servlet 和 servlet-mapping 标签

    摘录某个工程的 web.xml 文件片段: 访问顺序为1—>2—>3—>4,其中2和3的值必须相同. url-pattern 标签中的值是要在浏览器地址栏中输入的 url,可以自己命 ...

  2. 我的第一个BAE python应用

    第一步 用baidu帐号登陆开发者中心 http://developer.baidu.com/ Baidu的引导,帮助说明已经很详细, 这里不重复. 第二步,创建新版本 用svn  check out ...

  3. linux删除某类型文件的命令

    使用linux命令行,删除某目录下某类型的文件,如:删除.rar结尾的所有文件. 命令如下: find . -name "*.rar" -type f -print -exec r ...

  4. CSS display 属性详解

    定义display 属性设置是否及如何显示元素. 继承性: No 说明 这个属性用于定义建立布局时元素生成的显示框类型.对于 HTML 等文档类型,如果使用 display 不 谨慎会很危险,因为可能 ...

  5. C++引用的实质

    转自探索c++的底层机制 在看这篇文章之前,请你先要明白一点:那就是c++为我们所提供的各种存取控制仅仅是在编译阶段给我们的限制,也就是说是编译器确保了你在完成任务之前的正确行为,如果你的行为不正确, ...

  6. 几种 Docker 监控工具对比

    轻量级虚拟化容器 Docker,自发布以来便广受业界关注,在开源界和企业界掀起了一阵风.Docker 容器相对于 VM 有以下几个优势:启动速度快:资源利用率高:性能开销小. 从图中可以看出 Dock ...

  7. 关于PIL库的一些概念

    关于PIL库的一些概念 pil能处理的图片类型pil可以处理光栅图片(像素数据组成的的块). 通道一个图片可以包含一到多个数据通道,如果这些通道具有相同的维数和深度,Pil允许将这些通道进行叠加 模式 ...

  8. Postman(API & HTTP请求调试插件)和Apizza fiddler

    http://blog.csdn.net/u011012932/article/details/51456263#comments

  9. 常见 jar包详解

        常见 jar包详解 jar包 用途 axis.jar SOAP引擎包 commons-discovery-0.2.jar 用来发现.查找和实现可插入式接口,提供一些一般类实例化.单件的生命周期 ...

  10. BZOJ_1221_ [HNOI2001]_软件开发(最小费用流,网络流24题#10)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1221 n天,每天需要r个毛巾,用完以后可以洗,要么花fa洗a天,要么花fb洗b天,毛巾不够了可 ...