微软苏州校招笔试 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://blog.csdn.net/acvcla/article/details/42200345">http://blog.csdn.net/acvcla/article/details/42200345</a>
    > File Name: xiaozhao.cpp
    > Author: acvcla
    > QQ:[email protected]
    > Mail: [email protected]
    > 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:[email protected]
    > Mail: [email protected]
    > 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:[email protected]
    > Mail: [email protected]
    > 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>
时间: 2024-08-24 20:35:47

微软苏州校招笔试 12月27日的相关文章

[HiHoCoder]#1094 : Lost in the City 微软苏州校招笔试 12月27日

时间限制: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 blo

hihocoder #1094 : Lost in the City微软苏州校招笔试 12月27日 (建图不大【暴力枚举】 子图的4种形态 1Y )

#1094 : 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 gri

三周第三次课(12月27日) 3.7 su命令 3.8 sudo命令 3.9 限制root远程登录

三周第三次课(12月27日)3.7 su命令3.8 sudo命令3.9 限制root远程登录 su命令: 用户和工作组管理: su命令用于切换当前用户身份到其他用户身份, 变更时须输入所要变更的用户帐号与密码. 语法: su(选项)(参数) 选项: -c<指令>或--command=<指令>:执行完指定的指令后,即恢复原来的身份: -f或--fast:适用于csh与tsch,使shell不用去读取启动文件: -l或--login:改变身份时,也同时变更工作目录,以及HOME,SHE

周浩晖 - 斗宴(2014年12月27日)

<死亡通知单:暗黑者> 作 者:周浩晖译 者:系 列:暗黑者出 版:时代文华书局字 数:255千字阅读完成:2014年11月10日

数据库练习(16年12月27日)-- 牛客网

数据完整性可以分为四类. 1.实体完整性,实体完整性的目的是确保数据库中所有实体的唯一性,也就是不应出现完全相同的数据记录. 2.区域完整性,匹配完整性要求数据表中的数据位于某一个特定的允许范围内. 3.参考完整性,是用来维护相关数据表之间数据一致性的手段,通过实现参考完整性,可以避免因一个数据表的记录改变而造成另一个数据表内的数据变成无效值. 4.用户自定义完整性,用户自定义由用户根据实际应用中的需要自行定义. 题目: 关于数据完整性,以下说法正确的是?   AD A 引用完整性通过主键和外键

2014年12月27日 迅雷会员账号分享 最新更新

迅雷会员账号分享147327541:1密码1092217迅雷会员账号分享147327541:2密码9079881迅雷会员账号分享817531368:1密码1272054迅雷会员账号分享817531368:2密码1204275迅雷会员账号分享651290788:1 密码9906390迅雷会员账号分享349532055:1 密码8185444迅雷会员账号分享349532055:2 密码0249725迅雷会员账号分享307362307:1 密码3940448迅雷会员账号分享307362307:2 密码

12月27日笔记

复习: 数组:一维,二维,多维 一维:豆角.连续,同一类型. 定义:数据类型[] 数组名=new 数据类型[长度]{.,.,.,.}; 赋值:数组名[下标] = 值 取值:数组名[下标] 灵活运用:与for循环的结合应用. 1.求最大值,最小值. 2.求总和,平均. 3.随机(生成下标)抽值. 数组的应用: (一).冒泡排序. 1.冒泡排序是用双层循环解决.外层循环的是趟数,里层循环的是次数. 2.趟数=n-1:次数=n-趟数. 3.里层循环使用if比较相临的两个数的大小,进行数值交换. 作业:

2016年12月27日 阿里云内部技术分享

Spark机器学习· 实时机器学习http://click.aliyun.com/m/8713/Redis与KV存储(RocksDB)融合之编码方式http://click.aliyun.com/m/8714/阿里技术总监郭东白:创新之歌该如何唱http://click.aliyun.com/m/8715/页面以及全站性能损耗计算http://click.aliyun.com/m/8716/三年0故障总结,提升代码质量的秘诀http://click.aliyun.com/m/8717/pytho

2016年12月27日 星期二 --出埃及记 Exodus 21:22

"If men who are fighting hit a pregnant woman and she gives birth prematurely but there is no serious injury, the offender must be fined whatever the woman's husband demands and the court allows. 人若彼此争斗,伤害有孕的妇人,甚至坠胎,随后却无别害,那伤害她的,总要按妇人的丈夫所要的,照审判官所断的,受