华东师范2018研究生复试上机题题解

 3533. 庙会

假设在周末舞会上,男士们和女士们进入舞厅时,各自排成一队。跳舞开始时,依次从男队和女队的队头上各出一人配成舞伴。规定每个舞曲能有一对跳舞者。若两队初始人数不相同,则较长的那一队中未配对者等待下一轮舞曲。现要求写一个程序,模拟上述舞伴配对问题。

输入格式

三个整数 m , n , k (1≤m,n≤150,1≤k≤4000 ),分别表示男士人数、女士人数、几轮舞曲。

输出格式

输出各轮舞曲的配对方案。

样例

Input

2 4 6

Output

1 1
2 2
1 3
2 4
1 1
2 2
#include
#include
#include
#include
using namespace std;

int M,N,K;
queue women;
queue men;

int main()
{
	while(scanf("%d%d%d",&M,&N,&K)!=EOF)
	{
		while(!men.empty()) men.pop();
		while(!women.empty()) women.pop();
		for(int i=1;i<=M;i++)
		men.push(i);
		for(int i=1;i<=N;i++)
		women.push(i);
		for(int i=0;i

3532. 热河路

我们可以将其抽象成一个如下的序列:

110100100010000100000……

请你找出这个无穷序列中指定位置上的数字。

输入格式

第一行一个正整数 n (1≤n≤1500000 ),表示询问次数。

接下来的 n 行,每行一个正整数 ai (1≤ai≤109 ),ai 表示在序列中的位置。

输出格式

输出 n 行,每行为一个 0 或 1 ,表示该序列第 ai 位上的数字。

样例

Input

4
3
14
7
6

Output

0
0
1
0
#include
#include
#include
#include
using namespace std;
const int maxn=1e9+5;

int N;
bool a[maxn]={false};
void begin()
{
	//memset(a,0,sizeof(a));
	int cnt=0;
	for(int i=1;i

3531. 定西

一个人走走了很多年,发现自己走到了一个很长的,年久失修的楼梯面前。年久失修的意思就是,有 k 个台阶坏了,没法走。

楼梯一共有 n 层,你一次能上一阶、两阶或三阶台阶,请问,你从楼梯底部 (0 开始) 走到楼梯顶部,共有多少种走法。

输入格式

输入数据共两行,第一行包含两个自然数 n (1≤n≤100 ) 和 k (0≤k

输出格式

输出数据仅包含一个整数,表示所有可行走法的总数。

样例

Input

5 2
2 4

Output

2

注意特判最后一级台阶是否是坏的!!

#include
#include
#include
#include
using namespace std;
const int maxn=105;

int N,K;
bool mark[maxn];
int dp[maxn]; //dp[i]表示到i为止的走法总数 
int begin(int N)
{
	if(!mark[N]) return 0;
	if(mark[1]) dp[1]=1;
	else dp[1]=0;
	if(mark[2]) dp[2]=dp[1]*mark[1]+1;
	else dp[2]=dp[1];
	if(mark[3]) dp[3]=dp[1]*mark[1]+dp[2]*mark[2]+1; 
	//else dp[3]=dp[1]+dp[2];
	else dp[3]=dp[2];
	//cout<

3530. 和你在一起

 

现场4分10秒,小哥跟着逼哥嘶吼,泪流满面。我要和你在一起,直到我不爱你。有这么 n 个数字,联成一排拼到一起便是我爱你的时间,那么我们会在一起多久呢

例如: n=3 时,3 个整数 13,312,343 联接成的最长时间为: 34331213。
又如: n=4 时,4 个整数 7,13,4,246 联接成的最长时间为: 7424613。

输入格式

n (1≤n≤20 ),表示 n 个数。

接下来一行 n 个正整数,大小不超过 104 。

输出格式

拼成的最长时间。

样例

Input

3
623 583 413

Output

623583413
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn=105;
int N;
vector ans;

bool cmp(string a,string b)
{
	return a>b;
}
int main()
{
	while(scanf("%d",&N)!=EOF)
	{
		string str;
		for(int i=0;i>str;
			ans.push_back(str);
		}
		sort(ans.begin(),ans.end(),cmp);
		for(int i=0;i

 3529. 梵高先生

音的只有一只狗。

抬头再看了一眼星空和黑夜,今晚的星星变成了一个三角形的样子,像这样:

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
...

现在给你一个正整数 n ,请你给出星空的前 n 行。

输入格式

输入文件共一行,包含一个正整数 n (1≤n≤20 )。

输出格式

输出文件共 n 行,即星空的前 n 行。每行包含若干正整数,这些正整数之间用一个空格隔开(不能有多余的空格),最后一个正整数后面没有空格。

样例

Input

4

Output

1
1 1
1 2 1
1 3 3 1
#include
#include
#include
#include
using namespace std;
int N;
int a[20][20];

int main()
{
	while(scanf("%d",&N)!=EOF)
	{
		memset(a,0,sizeof(a));
		a[1][1]=1;
		printf("1\n");
		for(int i=2;i<=N;i++)
		{
			for(int j=1;j<=i;j++)
			{
				a[i][j]=a[i-1][j-1]+a[i-1][j];
				if(j!=i) printf("%d ",a[i][j]);
				else printf("%d\n",a[i][j]);
			}
		}
	}
	return 0;
}

 3528. 西班牙馅饼

现在我们看见了这个西班牙馅饼长什么样,西班牙馅饼是个矩形形状,想不到吧。我们可以把它抽象成一个 N 行 M 列的正整数矩阵。每个格子有一个“美味值”,由于一些不可告人的原因我们对于这个馅饼没行只能吃一口,港岛妹妹说如果她吃到美味值为 k 的馅饼,就会给我做出美味值为 k 的红烧肉。问红烧肉最多能有多好吃。

输入格式

N ,M :表示 N 行 M 列,馅饼的尺寸大小。

以下 N 行 M 列为馅饼每个格子的美味值。

输入中所有数是不超过 100 的正整数。

输出格式

一个正整数,表示红烧肉最多能有多好吃。

样例

Input

3 2
8 15
11 4
2 43

Output

69
#include
#include
#include
#include
#include
using namespace std;
int N,M;

int main()
{
	while(scanf("%d%d",&N,&M)!=EOF)
	{
		int ans=0; 
		for(int i=0;imax) max=x; 
			}
			ans+=max;
		}
		printf("%d\n",ans);
	}
	return 0;
}

 

你可能感兴趣的:(机试准备)