题目链接: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. 检测浏览器对HTML5和CSS3支持情况的利器——Modernizr

    Modernizr是什么? Modernizr 是一个用来检测浏览器功能支持情况的 JavaScript 库. 目前,通过检验浏览器对一系列测试的处理情况,Modernizr 可以检测18项 CSS3 ...

  2. jquery , find the event handler,找到jquery中的event handler

    找到 dispatch: function (e) { e = b.event.fix(e); var n, r, i, s, o, u = [], a = d.call(arguments), f ...

  3. 记一次Oracle数据库迁移部署

    --20141230部署脚本(按照时间顺序从上往下) --命令行,导出要部署的数据库数据(无分号) --expdp RMB3/test123@orcl3 SCHEMAS=RMB3 directory= ...

  4. POJ 1151 Atlantis(离散化)

    点我看题目 题意 : 就是给你n个矩形的最左下角和最右上角的点的坐标,然后将这n个矩形的面积求出来. 思路 : 离散化求矩形面积并.离散化具体介绍.将横纵坐标离散开来分别存,然后排序,也可以按照黑书上 ...

  5. http://blog.csdn.net/zhang_xinxiu/article/details/38655311

    一.Activiti下载及简介 1.1.Activiti下载 官网下载地址:http://activiti.org/download.html        Note:下载时不一定要使用最新版本的,最 ...

  6. 详解浏览器缓存机制与Apache设置缓存

    一.详解浏览器缓存机制 对于,如何说明缓存机制,在网络上找到了两张图,个人认为思路是比较清晰的.总结时,上图. 这里需要注意的有两点: 1.Last-Modified.Etag是响应头里的数据 2.I ...

  7. FLV封装格式及分析器工具

    http://blog.csdn.net/leixiaohua1020/article/details/17934487 FLV封装原理 FLV格式的封装原理,贴上来辅助学习之用.     FLV(F ...

  8. ANDROID_MARS学习笔记_S01原始版_008_Looper\Bundle异步消息处理

    一.流程 1.自定义Handler,重写handleMessage(Message msg),用msg得到bundle,从而得到传递过来的数据 2.开启android.os.HandlerThread ...

  9. ContentLoadingProgressBar不显示问题

    ContentLoadingProgressBar需要设置style 并且在XML中布局的位置必须写在content布局的下面 <?xml version="1.0" enc ...

  10. org.springframework.jdbc.datasource

    org.springframework.jdbc.datasource.DataSourceUtils /** * Actually obtain a JDBC Connection from the ...