本文主要是介绍微软苏州校招笔试 12月27日,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目1 : Lost in the City
-
8 8 ...HSH.. ...HSM.. ...HST.. ...HSPP. PPGHSPPT PPSSSSSS ..MMSHHH ..MMSH.. SSS SHG SH.
样例输出 -
5 4
描述
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.
代码如下:
/************************************************************************* > 转载请注明出处http://blog.csdn.net/acvcla/article/details/42200345> File Name: xiaozhao.cpp > Author: acvcla > QQ:acvcla@gmail.com > Mail: acvcla@gmail.com > 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_backstring 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
-
5 6 3 6 6 2 1
样例输出 -
4
描述
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.
二分T的值即可,二分区间为[1,k+2)。
代码如下:
/************************************************************************* > 转载请注明出处http://blog.csdn.net/acvcla/article/details/42200345> File Name: xiaozhao.cpp > Author: acvcla > QQ:acvcla@gmail.com > Mail: acvcla@gmail.com > 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
-
7 2
样例输出 -
4
描述
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.
给出n和m,要求选一些数(不重复)使得这些数的和为n,乘积为m,n<=100,m<=50,直接搜,开始还想复杂了。orz
代码如下:
/************************************************************************* > 转载请注明出处http://blog.csdn.net/acvcla/article/details/42200345> File Name: xiaozhao.cpp > Author: acvcla > QQ:acvcla@gmail.com > Mail: acvcla@gmail.com > 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++){if(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;
}
这篇关于微软苏州校招笔试 12月27日的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!