首页 > 代码库 > 微软苏州校招笔试 12月27日

微软苏州校招笔试 12月27日

题目1 : Lost in the City

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.

Fortunately, Little Hi has a map of the city. The map can be considered as a grid of N*M blocks. Each block is numbered by a pair of integers. The block at the north-west corner is (1, 1) and the one at the south-east corner is (N, M). Each block is represented by a character, describing the construction on that block: ‘.‘ for empty area, ‘P‘ for parks, ‘H‘ for houses, ‘S‘ for streets, ‘M‘ for malls, ‘G‘ for government buildings, ‘T‘ for trees and etc.

Given the blocks of 3*3 area that surrounding Little Hi(Little Hi is at the middle block of the 3*3 area), please find out the position of him. Note that Little Hi is disoriented, the upper side of the surrounding area may be actually north side, south side, east side or west side.

输入

Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2~N+1: each line contains M characters, describing the city‘s map. The characters can only be ‘A‘-‘Z‘ or ‘.‘.
Line N+2~N+4: each line 3 characters, describing the area surrounding Little Hi.

输出

Line 1~K: each line contains 2 integers X and Y, indicating that block (X, Y) may be Little Hi‘s position. If there are multiple possible blocks, output them from north to south, west to east.

样例输入
8 8
...HSH..
...HSM..
...HST..
...HSPP.
PPGHSPPT
PPSSSSSS
..MMSHHH
..MMSH..
SSS
SHG
SH.
样例输出
5 4
给出一个n*m的图和一个3*3的图,要求你输出3*3的原图的中心位置的坐标。直接暴力匹配。需要注意一下图是可以旋转的,在求出坐标之后需要先排个序,去个重就好。

代码如下:

/************************************************************************* 
    > 转载请注明出处<a target=_blank href=http://www.mamicode.com/"http://blog.csdn.net/acvcla/article/details/42200345">http://blog.csdn.net/acvcla/article/details/42200345 >



题目2 : HIHO Drinking Game

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Little Hi and Little Ho are playing a drinking game called HIHO. The game comprises N rounds. Each round, Little Hi pours T milliliter of water into Little Ho‘s cup then Little Ho rolls a K-faces dice to get a random number d among 1 to K. If the remaining water in Little Ho‘s cup is less than or equal to d milliliter Little Hi gets one score and Little Ho drinks up the remaining water, otherwise Little Ho gets one score and Little Ho drinks exactly d milliliter of water from his cup. After N rounds who has the most scores wins.

Here comes the problem. If Little Ho can predict the number d of N rounds in the game what is the minimum value of T that makes Little Ho the winner? You may assume that no matter how much water is added, Little Ho‘s cup would never be full.

输入

The first line contains N(1 <= N <= 100000, N is odd) and K(1 <= K <= 100000).
The second line contains N numbers, Little Ho‘s predicted number d of N rounds.

输出

Output the minimum value of T that makes Little Ho the winner.

样例输入
5 6
3 6 6 2 1
样例输出
4
Hi和Ho在玩一个游戏,游戏有n(n为奇数)个回合,每个回合hi给ho T的水,然后ho投掷一枚k个面的骰子(点数从1到k),记向上的点数为d,若ho杯子里的水<=d那么hi得一分,同时ho将杯子里的水喝完,若>d则ho得一分并喝掉d的水,n个回合之后分多的人获胜。现在知道了每次投掷骰子的n次结果,问T的最小值是多少ho才能获胜。

二分T的值即可,二分区间为[1,k+2)。

代码如下:

/************************************************************************* 
    > 转载请注明出处<a target=_blank href=http://www.mamicode.com/"http://blog.csdn.net/acvcla/article/details/42200345">http://blog.csdn.net/acvcla/article/details/42200345>


题目3 : Divided Product

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Given two positive integers N and M, please divide N into several integers A1, A2, ..., Ak (k >= 1), so that:

1. 0 < A1 < A2 < ... < Ak;

2. A1 + A2 + ... + Ak = N;

3. A1, A2, ..., Ak are different with each other;

4. The product of them P = A1 * A2 * ... * Ak is a multiple of M;

How many different ways can you achieve this goal?

输入

Two integers N and M. 1 <= N <= 100, 1 <= M <= 50.

输出

Output one integer -- the number of different ways to achieve this goal, module 1,000,000,007.

样例提示

There are 4 different ways to achieve this goal for the sample:

A1=1, A2=2, A3=4;

A1=1, A2=6;

A1=2, A2=5;

A1=3, A2=4.

样例输入
7 2
样例输出
4

给出n和m,要求选一些数(不重复)使得这些数的和为n,乘积为m,n<=100,m<=50,直接搜,开始还想复杂了。orz

代码如下:

<span style="font-size:18px;">/************************************************************************* 
    > 转载请注明出处<a target=_blank href=http://www.mamicode.com/"http://blog.csdn.net/acvcla/article/details/41732447">http://blog.csdn.net/acvcla/article/details/41732447 >


微软苏州校招笔试 12月27日