题目链接: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. Oracle 分析函数 "ORA-30485: 在窗口说明中丢失 ORDER BY 表达式"

    跟顺序有关的几个分析函数row_number.rank.dense_rank.lead和lag的over窗口里,都必须有order_by_clause.其他几个如:first_value.last_v ...

  2. RAC,客户端连接失败ORA-12514

    今天上午,某项目运维组的同事过来求助:"某系统的应用有问题了,WEB页面打开以后出现ORACLE的ORA-12514错误,貌似监听有问题了!" 该系统的数据是采用RAC部署的模式, ...

  3. 一步步学习ASP.NET MVC3 (2)——入门程序

    请注明转载地址:http://www.cnblogs.com/arhat 在上一节中,我们只是简单的介绍了什么是MVC及MVC的运行原理.而本节呢,主要来实现下一ASP.NET MVC3的开发流程,并 ...

  4. DB天气app冲刺第七天

    今天估计得分应该是最差的了. 今天因为完全没准备所以在界面UI上面根本就是相当于没弄.结果今天的各组报告里自己做得很不好.不过好在只是项目的中间期,不碍大事. 今天也完成了任务.可以说超额了也.因为吃 ...

  5. bug - colorWithPatternImage:

    // 在ios5之前, 再通过以下方法设置背景时, 有闪屏bug self.view.backgroundColor = [UIColor colorWithPatternImage:<#(no ...

  6. Codeforces Round #237 (Div. 2)

    链接 A. Valera and X time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inp ...

  7. Spring3 +mybatis3 之 MapperScannerConfigurer

    之前一直使用"org.mybatis.spring.mapper.MapperFactoryBean"这个类在spring中配置mybatis的dao接口,后来发现如果dao太多话 ...

  8. 163. Missing Ranges

    题目: Given a sorted integer array where the range of elements are [lower, upper] inclusive, return it ...

  9. Java-Swing嵌入浏览器(一)

    今天要说的额是浏览器的第一个版本是用DJnative-swt和swt包开发的调用本地浏览器和webkit浏览器的示例 这是我的工程目录[源码见最后]: src下为写的源码,lib为引入的swt和DJn ...

  10. 【HDOJ】3311 Dig The Wells

    Steiner Tree.概念就不讲了,引入0号结点.[1, n+m]到0连一条边,权重表示挖井的费用.这样建图spfa求MST即满足所求解. /* 3311 */ #include <iost ...