微软2016校园招聘4月在线笔试 ABC
题目链接: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的更多相关文章
- hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)
hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...
- 微软2016校园招聘4月在线笔试 A FontSize
题目链接:http://hihocoder.com/problemset/problem/1288 分析:题目中所求的是最大的FontSize(记为S),其应该满足P*[W/S]*[H/S] > ...
- 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 Little Hi runs a web server. Sometimes he has to deny acces ...
- [Hihocoder 1289] 403 Forbidden (微软2016校园招聘4月在线笔试)
传送门 #1289 : 403 Forbidden 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi runs a web server. Someti ...
- 微软2016校园招聘在线笔试-Professor Q's Software
题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...
- 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]
传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...
- 微软2016校园招聘在线笔试 [Recruitment]
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A company plans to recruit some new employees. There are N ca ...
- 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场
题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...
随机推荐
- unity3d游戏开发——新手引导
GUI实现,如下: 按“G”键开始新手引导 代码如下: using UnityEngine; using System.Collections; public class OkButton : GUI ...
- qt 5 小练习 创建无边框界面
我们大家都知道QT5 自带的界面不是那么美观,并且每个软件我们都发现他们的边框是自定义的,所以我决定写一篇这样的博文,也许已经有许许多多篇大牛写的论文了,但我还是想写一篇记录自己的学习QT的历程 首先 ...
- P1631: [Usaco2007 Feb]Cow Party
还是水题,接近于裸的spfa(个人比较喜欢用spfa,dijkstra不太喜欢用),代码附上 ; type link=^node; node=record t,d:longint; f:link; e ...
- initialize or clean up your unittest within .net unit test
// Use ClassInitialize to run code before running the first test in the class [ClassInitialize()] pu ...
- 使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一)-----初识WiX (转)
原文地址:http://blog.csdn.net/rryqsh/article/details/8274832 Visual Studio 打包安装七宗罪 开发.NET的人,肯定会使用Visual ...
- Nhibernate cookbook 3.0-翻译
/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-ts ...
- 【综述】(MIT博士)林达华老师-"概率模型与计算机视觉”
[综述](MIT博士)林达华老师-"概率模型与计算机视觉” 距上一次邀请中国科学院的樊彬老师为我们撰写图像特征描述符方面的综述(http://www.sigvc.org/bbs/thread ...
- 将java类的泛型集合转换成json对象
一般用extjs开发传输都是用json比较多,这个将来大家也许会用到... ConvertJsonUtils.java package com.sunweb.util.jsonfactory; imp ...
- Chapter 17. Objects and Inheritance(对象与继承)
javascript面向对象编程有几个层面: 1: 单一对象 (covered in Layer 1: Single Objects) 2: 对象之间的 prototype (described i ...
- Firefly官方教程之Distributed使用文档
原地址:http://bbs.gameres.com/thread_224191.html distributed使用文档1.distributed说明该模块主要封装了各个服务进程间进行通信的方法.n ...