题目链接: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. 关于 IIS 上的 Speech 设置

    在之前的开发过程中,发现在 微软各个版本的Speech中(从sdk5.1 到 最新的 Speech PlatFarme V11),在本地可以生成音频文件,但是在IIS上却生成无法生成完整的文件. 调试 ...

  2. ExtJS4.2学习(19)在线编辑器Ext.form.HtmlEditor(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-12-24/191.html --------------- ...

  3. 图片上没有line-height垂直居中

    <style> div {     width: 150px;     height: 155px;     line-height: 155px;     border: 1px sol ...

  4. MongoDB实战指南(二):索引与查询优化

    数据库保存记录的机制是建立在文件系统上的,索引也是以文件的形式存储在磁盘上,在数据库中用到最多的索引结构就是B树.尽管索引在数据库领域是不可缺少的,但是对一个表建立过多的索引会带来一些问题,索引的建立 ...

  5. HDU Traffic Real Time Query System

    题目大意是:对于(n, m)的图,给定边a, b查询从a到b要经过的割点的最少数目. 先tarjan算法求双连通然后缩点,即对于每个割点将周围的每个双连通看成一个点与之相连.然后求解LCA即可,距离d ...

  6. Android USB Host 通信程序

    换到了一家新公司,于是就有了新的项目.这次的项目 要用Android SDK与USB HID设备进行通信.第一次接触Android SDK,以及USB,记录下源程序.开发过程以及一些心得. 首先,要感 ...

  7. ruby 线程学习

    i=1 Thread.start{ while true print "Thread 1 \n" i+=1 if i==5 then Thread.kill Thread.curr ...

  8. IIS由于无法创建应用程序域,因此未能执行请求。错误: 0x80070005 拒绝访问

    网站静态页面(.html)是可以访问的,但是动态页面(.aspx)就出错了. 服务器上还有其他网站,但是都可以正常浏览,这就说明不是IIS本身有问题了,问题应该出在网站本身. 百度后,都说是权限问题, ...

  9. 以编程方式使用 Word 中的内置对话框

    使用 Microsoft Office Word 时,有时需要显示用户输入对话框.虽然可以创建自己的对话框,您也许还希望采用使用 Word 中内置对话框的方法,这些对话框在Application 对象 ...

  10. apache开源项目--JMeter

    JMeter是Apache组织的开放源代码项目,它是功能和性能测试的工具,100%的用java实现.