华东师范大学2018年机试题

3528. 西班牙馅饼

单点时限: 1.0 sec
内存限制: 256 MB
题目
粉丝问:“我想问一下在你歌词里面的馅饼是什么?”
李志答:“告诉你,西班牙馅饼是怎么一回事。是有一次我一个朋友给我寄了一张明信片,从西班牙寄过来的,明信片的封面是一块馅饼,谢谢你,你惊讶吗?你们惊讶吗?想想啥?你们知道个几把?整天瞎几把猜对不对?挺可笑的。所以答案一公布就这个样子。你再回想一下生活里面有多少个这样的事情,你充满了幻想,充满了好奇,猜哦,瞎几把猜,猜到后面傻逼了吧?没猜到了吧?”

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

输入格式
N,M:表示 N 行 M 列,馅饼的尺寸大小。
以下 N 行 M 列为馅饼每个格子的美味值。
输入中所有数是不超过 100 的正整数。

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

样例
input

3 2
8 15
11 4
2 43

output

69

代码

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int maxn=10010;
int yanghui[maxn][maxn];

int main()
{
	int n,m,temp;
	cin>>n>>m;
	int sum=0;
	for(int i=0;i<n;i++)
	{
	    int ans=0;
		for(int j=0;j<m;j++)
        {
            cin>>temp;
            ans=max(ans,temp);
        }
        sum+=ans;
	}
	cout<<sum;
	return 0;
}

3529. 梵高先生

单点时限: 1.0 sec
内存限制: 256 MB
题目
2009年的最后一天 在义乌隔壁酒吧 李志为了还做唱片欠下来的20W 巡回35场演出 在这晚完成 喝醉了的逼哥哽咽着唱完梵高先生 说最后一次唱这歌。他粗鲁的打断了大家的合唱,然后用最沙哑的嗓音唱了起来,哪天,唯一和他合音的只有一只狗。抬头再看了一眼星空和黑夜,今晚的星星变成了一个三角形的样子,像这样:

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 <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int maxn=10010;
int yanghui[maxn][maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		yanghui[i][0]=1;
		yanghui[i][i]=1;//杨辉三角形每行第一列和最后一列数据都为1
		for(int j=1;j<i;j++)
		{
			yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];//每个数字等于肩上两数字之和
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			printf("%d",yanghui[i][j]);
			if(j<i)
                printf(" ");
		}
		printf("\n");
	}
	return 0;
}

3530. 和你在一起

单点时限: 1.0 sec
内存限制: 256 MB
题目
现场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

代码
这题就是PAT 甲级贪心里的A 1038 Recover the Smallest Number,可以去前面的博文看看,只是改了一个cmp函数而已

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int maxn=10010;
string str[maxn];

bool cmp(string a,string b)
{
    return a+b>b+a;
}

int main()
{
    int n,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
       cin>>str[i];
    }
    sort(str,str+n,cmp);
    string ans;
    for(i=0;i<n;i++)
    {
        ans+=str[i];
    }
    if(ans.size()==0)
        cout<<0;
    else
        cout<<ans;
    return 0;
}


3531. 定西

单点时限: 1.0 sec
内存限制: 256 MB
题目
一个人走走了很多年,发现自己走到了一个很长的,年久失修的楼梯面前。年久失修的意思就是,有 k 个台阶坏了,没法走。楼梯一共有 n 层,你一次能上一阶、两阶或三阶台阶,请问,你从楼梯底部 (0 开始) 走到楼梯顶部,共有多少种走法。

输入格式
输入数据共两行,第一行包含两个自然数 n (1≤n≤100) 和 k (0≤k<n),第二行包含 k 个自然数 Xi (1≤Xi≤n),数字之间用一个空格隔开,表示损坏的台阶的序号(从楼梯底部到楼梯顶部,台阶序号依次为 1 到 n)。

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

样例
input

5 2
2 4

output

2

代码

#include <cstdio>
#include <algorithm>
#include <string>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int maxn=1000010;
int dp[maxn];

int main()
{
    int n,i,k=0,temp;
    scanf("%d%d",&n,&k);
    fill(dp,dp+maxn,-1);
    for(i=0;i<k;i++)
    {
       scanf("%d",&temp);
       dp[temp]=0;
    }
    dp[0]=1;
    if(dp[1]!=0)
        dp[1]=1;
    if(dp[2]!=0)
        dp[2]=dp[1]+dp[0];
    if(dp[3]!=0)
        dp[3]=dp[2]+dp[1]+dp[0];
    for(i=4;i<=n;i++)
    {
        if(dp[i]!=0)
        dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
    }
    cout<<dp[n];
    return 0;
}

3532. 热河路

单点时限: 2.0 sec
内存限制: 256 MB
奔跑。跌倒。奔跑。
题目
热河路有一家开了好多年的理发店,不管剪什么样的发型,你只要付五块钱。现在我们来到了热河路。我们可以将其抽象成一个如下的序列:
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 <cstdio>
#include <algorithm>
#include <string>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int maxn=1000010;
string str[maxn];

int main()
{
    int n,i,j,a;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
       scanf("%d",&a);
       j=floor(sqrt(a*2.0));
       a-=((1+j)*j)/2;
       j++;
       while(a>j)
       {
           a-=j;
           j++;
       }
       if(a==1)
        printf("1\n");
       else
        printf("0\n");
    }
    return 0;
}

3533. 庙会

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

输入格式
三个整数 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 <cstdio>
#include <algorithm>
#include <queue>
#include <algorithm>
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    int m,n,k,i;
    cin>>m>>n>>k;
    int x,y;
    for(i=0;i<k;i++)
    {
        x=(i%m)+1;
        y=(i%n)+1;
        printf("%d %d\n",x,y);
    }
    return 0;
}

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值