码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-12-27 23:09:22      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:微软苏州校招笔试

题目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://blog.csdn.net/acvcla/article/details/42200345">http://blog.csdn.net/acvcla/article/details/42200345</a> 
    > File Name: xiaozhao.cpp 
    > Author: acvcla 
    > QQ:acvcla@gmail.com  
    > Mail: acvcla@gmail. 
    > Created Time: 2014年12月27日 星期一 22时34分13秒 
*************************************************************************/  
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<climits>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back

string str[200];
string area[3];
int n, m;
void rotate()
{

    int n=3;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            swap(area[i][j],area[j][i]);
    for(int i=0;i<n;i++)
        for(int j=0;j<n/2;j++)
            swap(area[i][j],area[i][n-1-j]);
}
bool judge(int x,int y)
{
	for(int i=0;i<3;i++)
	for(int j=0;j<3;j++) {
		if(area[i][j]!=str[x+i][j+y])return false;
	}
	return true;
}
void solve()
{
	vector<pair<int,int> >v;
	v.clear();
    for(int i=0;i<4;i++) {
        for(int i=0;i+2<n;i++) {
            for(int j=0;j+2<m;j++) {
            	if(judge(i,j)) {
            		v.push_back(make_pair(i+2,j+2));
            	}
            }
        }
        rotate();
    }
    sort(v.begin(), v.end());
    int cnt=unique(v.begin(), v.end())-v.begin();
    for(int i=0;i<cnt;i++)cout<<v[i].first<<' '<<v[i].second<<endl;
}
int main()
{
    while(cin>>n>>m) {
	    for(int i=0;i<n;i++)cin>>str[i];
	    for(int i=0;i<3;i++)cin>>area[i];
	    solve();
	}
	return 0;
}




题目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://blog.csdn.net/acvcla/article/details/42200345">http://blog.csdn.net/acvcla/article/details/42200345</a>
    > File Name: xiaozhao.cpp 
    > Author: acvcla 
    > QQ:acvcla@gmail.com  
    > Mail: acvcla@gmail. 
    > Created Time: 2014年12月27日 星期一 22时34分13秒 
*************************************************************************/  
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<string.h>
#include<cmath>
using namespace std;
const int maxn =1e5;
typedef long long LL;
int d[maxn+10];
bool judge(int T,int n)
{
	int x1=0,x2=0,rL=T;
	for(int i=1;i<=n;i++) {
		if(rL>d[i]) {
			rL-=d[i];
			x2++;
			rL+=T;
		}else {
			rL=T;
			x1++;
		}
	}
	return x1<x2;
}
int solve(int n,int k)
{
	int L=1,R=k+10;
	while(L<R) {
		int M=(L+R)>>1;
		if(judge(M,n))R=M;
		else L=M+1;
	}
	return R;
}
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k)) {
    	for(int i=1;i<=n;i++)scanf("%d",d+i);
    	printf("%d\n",solve(n,k));
    }
    return 0;
}



题目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://blog.csdn.net/acvcla/article/details/41732447">http://blog.csdn.net/acvcla/article/details/41732447</a> 
    > File Name: xiaozhao.cpp 
    > Author: acvcla 
    > QQ:acvcla@gmail.com  
    > Mail: acvcla@gmail. 
    > Created Time: 2014年12月27日 星期一 22时34分13秒 
*************************************************************************/  
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<climits>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int n,m,ans;

void solve(int now_pos,int lft,int lcm){
    if(lft == 0){
        if(lcm == m)ans++;
        return ;
    }
    for(int i=now_pos;i<=lft;i++){
        solve(i+1,lft-i,__gcd(lcm*i,m));
    }
}
int main(){
	
    while(~scanf("%d%d",&n,&m)){
        ans = 0;
        solve(1,n,1);
        printf("%d\n",ans);
    }
    return 0;
}
</span>


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

标签:微软苏州校招笔试

原文地址:http://blog.csdn.net/acvcla/article/details/42200345

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!