山东财经大学新生赛暨天梯赛选拔赛

链接:https://ac.nowcoder.com/acm/contest/547/A
来源:牛客网
 

题目描述

在英语中,依靠单词的大小写拼写复合词的做法,叫做"骆驼拼写法"(CamelCase)。比如,backColor这个复合词,back第一个字母b为小写,color的第一个字母为大写。

这种拼写法在正规的英语中是不允许的,但是在编程语言和商业活动中却大量使用。比如,sony公司的畅销游戏机PlayStation,play和station两个词的词首字母都是大写的。

"骆驼拼写法"又分为两种。第一个词的首字母小写,后面每个词的首字母大写,叫做"小骆驼拼写法"(lowerCamelCase);第一个词的首字母,以及后面每个词的首字母都大写,叫做"大骆驼拼写法"(UpperCamelCase),又称"帕斯卡拼写法"(PascalCase)。

它之所以被叫做"骆驼拼写法",是因为大小写的区分使得复合词呈现"块状"(bump),看上去就像骆驼的驼峰(hump)。

这种变量命名方法非常适合于编程时的变量命名。

现在给你N行单词,要求你把每行单词按照小骆驼拼写法的规则进行拼写,然后输出

输入描述:

第一行一个数字N(0<N<100),表示行数,之后有N行。

每行有不定数目的单词,以空格分隔。

每个单词由不定长度的英文字母(A~Z,a~z)组成

输出描述:

N行,表示输出

示例1

输入

复制

4
user name
pass word
get message from HTTP response 
find minimum path

输出

复制

userName
passWord
getMessageFromHttpResponse
findMinimumPath
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include<algorithm>
using namespace std;
const int MAX = 1000005 ;
const int inf = 0x3f3f3f3f ;
typedef long long LL ;
string s ;
char a[MAX] ;
int main()
{
	int n ;
	cin >> n ;
	char ch = getchar() ;
	while(n--){
		gets(a);
		int len = strlen(a) ;
		for(int i = 0 ; i<len ; i++ ){
			if( (a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z') ){
				a[i] = tolower(a[i]) ;
			}
		}
		for(int i = 0 ; i<len ; i++ ){
			if(i==0 ){
				if(a[i]>='A'&&a[i]<='Z'){
					a[0] -=32 ;
 				}
			}
			else{
				if(a[i-1]==' '){
					if(a[i]>='a'&&a[i]<='z'){
						a[i]-=32 ;
					}
					
				}
			
			}
		}
		for(int i = 0 ; i<len ; i++ ){
			if(a[i]!=' '){
				printf("%c",a[i]);
			}
		}
		printf("\n");
	}

    return 0;

}

链接:https://ac.nowcoder.com/acm/contest/547/B
来源:牛客网
 

题目描述

在电影《流浪地球》中,人们为了逃离太阳系而选择建造巨大的行星发动机进行加速,

同时在经过木星轨道的时候利用了其引力弹弓效应进行加速。

那什么是引力弹弓效应呢?

李永乐老师专门为此出了一个视频:

点击学习

在学完什么是引力弹弓后,用你刚才所学的知识,来看下面的问题:

现在有一个超级大球向右运动,速度为X m/s,有n个小球向左运动,速度为Y m/s。

每个小球的质量都远小于其左边的球,同时也远大于其右边的小球。(各个球实际质量特别小,忽略其之间的引力)

且各个球之间的碰撞均为完全弹性碰撞

现在给你一个 X和 Y ,

在不考虑相对论效应的情况下,若要让最右边的小球的速度达到光速的1%(光速 C = 299792458 m/s),

求最小的碰撞次数(0<X+Y<=299792458)。

输入描述:

第一行一个数N (0<N<200)

表示测试样例的数目

第二行到第N+1行,每行两个数字 X,Y

输出描述:

一个数字,表示小球的数目

示例1

输入

复制

2
1 2
10 20

输出

复制

20
17

备注:

最左边的大球不被算在n内

结论 :  

       右边的小球是向左 速度是 Y  , 左边大球是向右 速度为 X , 根据结论 ,  x 每次向左靠近大球 都会获得一个回来的速度, 因为小球相对大球速度为 X + Y , 要保证小球回来的时候(小球回来的时候方向和大球一样,都向右,那么相对速度为 abs|V小球- V大球| )速度相对 大球为  2*X , 所以小球的速度为 2*X + y  ; 然后每次都迭代,一直到小球的速度达到 光速的0.01 倍时停止. 

#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include<algorithm>
using namespace std;
const double C = 299792458;
const int MAX = 1000005 ;
const int inf = 0x3f3f3f3f ;
typedef long long LL ;
double ans = C *0.01 ;
int main()
{	
	int n ;
	cin >> n ;
	while(n--){
		
		double x , y ;
		scanf("%lf%lf",&x,&y);
		int cnt = 0 ;
		double t = y ;
 		while(y<ans){
			y = t + 2*x ;
			x = y ;
			cnt++ ;
		}
		printf("%d\n",cnt);
		
	}

    return 0;

}

链接:https://ac.nowcoder.com/acm/contest/547/C
来源:牛客网
 

题目描述

所谓“Retina”是一种显示标准,是把更多的像素点压缩至一块屏幕里,从而达到更高的分辨率并提高屏幕显示的细腻程度。

例如在普通的屏幕上,一个字符是对应着一个像素,而在retina的屏幕上,一个字符由四个像素显示

例如

山财大的“山“字的点阵图如下:

在普通屏幕上的显示效果是这样的

而在retina屏幕上的效果是:

Retina的具体显示效果,由一个可以调节的“缩放比例”确定,

缩放比例为200%即意味着原来由一个 * 号组成的图案,现在由上下左右的4个 * 组成,

现在给你一个缩放比例,要求你输出对应的“山”

输入描述:

一个小于10的数字,表示放大比例

(例如 2 即为放大200%)

输出描述:

对应的”山“字图形

示例1

输入

复制

1

输出

复制

*    *    *
*    *    *
*    *    *
*    *    *
*    *    *
*    *    *
 *********
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include<algorithm>
using namespace std;
const double C = 299792458;
const int MAX = 1000005 ;
const int inf = 0x3f3f3f3f ;
typedef long long LL ;
double ans = C *0.01 ;
int main()
{
	int n ;
	cin >> n ;
	for(int k = 1 ; k <=6*n;k++ ){
		for(int j = 1 ; j<=n ; j++ ){
			cout<<"*";
		}
		for(int j = 1 ; j<=4*n;j++){
			cout<<" " ;
		}
		for(int j = 1 ; j<=n ; j++ ){
			cout<<"*";
		}
		for(int j = 1 ; j<=4*n;j++){
			cout<<" " ;
		}
		for(int j = 1 ; j<=n ; j++ ){
			cout<<"*";
		}
		for(int j = 1 ; j<=4*n;j++){
			cout<<" " ;
		}
		cout<<endl;
	}

	for(int j = 1 ; j<=n ; j++ ){
		for(int i = 1 ; i<=n ; i++ ){
		cout<<" ";
		}
		for(int i = 1 ; i<=9*n ;i++){
			cout<<"*" ;
		}
		for(int i = 1 ; i<=n ; i++ ){
		cout<<" ";
		}
		cout<<endl ;
	}


    return 0;

}

链接:https://ac.nowcoder.com/acm/contest/547/D
来源:牛客网
 

题目描述

英仙座流星雨(学名Perseids)是以英仙座γ星附近为辐射点出现的流星雨,也称英仙座γ流星雨。每年在7月20日至8月20日前后出现,于8月13日达到高潮。与象限仪座流星雨、双子座流星雨并称为北半球三大流星雨。

暑假到了,又是一个去看流星雨的好季节。

看流星雨最重要的是什么?当然是许愿。

当一颗流星出现时,可以对其许愿。

你一次可以选择一颗流星进行许愿,每一个愿望都需要一定的时间才能说完,而且中间不能有中断。

但是流星的持续时间通常都很短,很难在流星消失之前把自己的一个愿望说完。

你可以朝着新出现的流星接着许上一个未许完的愿望,当且仅当前一颗流星消失的瞬间另外一颗流星同时出现,

你不可以在一颗流星还在出现的时候转向其他的流星,这样流星之神会生气,厄运会降临

现在给你每颗流星出现和结束的时间,问你许一个愿望的最大时长是多少?

输入描述:

第一行一个数n n<=1000000

表示流星的数目

接下来每行2个数字 x,y (0<=x,y<=1001000 )

表示流星出现的时间和结束的时间

输出描述:

一个数字,表示最长可以连续许愿的时间

示例1

输入

复制

3
2 3
2 4
1 2

输出

复制

3

说明

1~4
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include<algorithm>
using namespace std;
const int MAX = 1000005 ;
const int inf = 0x3f3f3f3f ;
typedef long long LL ;
struct node {
	int x ;
	int y ;
};
bool cmp(const node& a , const node& b ){
	
	return a.x < b.x ;
}
node a[MAX] ;
int dp[MAX] ;
int main()
{
	int n  ;
	cin >>n ;
	for(int i = 1 ; i<=n ; i++) {
		cin >>a[i].x >>a[i].y ;
	}
	sort(a+1,a+1+n,cmp) ;
	int ans = 0 ;

	for(int i = 1 ; i<=n ; i++ ) {
		dp[a[i].y] = max(dp[a[i].y],dp[a[i].x]+ a[i].y - a[i].x) ;
		ans  = max(ans,dp[a[i].y]) ;
	}
	cout<<ans ;
    return 0;

}

链接:https://ac.nowcoder.com/acm/contest/547/F
来源:牛客网
 

题目描述

LXK有一个序列,从N~1,但是他不小心把序列打乱了,现在他想找你把这串序列复原。

他讨厌用传统的方式排序。所以他用他自己的方式进行复原。

他有K个先进先出的队列

对于某个数字,你可以选择将其放入任意队列之中(不能不放)。

每个队列中队首的数字可以在任意时间出队列。

利用这些队列,聪明的LXK就可以将序列复原回降序。

他想知道这些操作最少需要准备多少个队列?    

输入描述:

一个数N(N<100000)

表示数字的数目

接下来一行 n个数字

输出描述:

一个数k

表示最少需要多少个队列才能满足要求

示例1

输入

复制

5
1 2 3 4 5

输出

复制

5

示例2

输入

复制

7
1 2 5 7 3 4 6

输出

复制

5

最长不下降序列的长度. 

#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include<algorithm>
using namespace std;
const int MAX = 1000005 ;
const int inf = 0x3f3f3f3f ;
typedef long long LL ;
int a[MAX] ;
int low[MAX] ;
int main()
{
	int cnt = 0 ;
	int n ;
	cin >>n ;
	for(int i = 1 ; i<=n ; i++ ) cin >> a[i] ;
	low[++cnt] = a[1] ;
	for(int i = 2 ; i<=n ; i++ ){
		if(a[i]>low[cnt]){
			low[++cnt] = a[i] ;
		}
		else{
			int k = lower_bound(low+1,low+1+cnt,a[i])-low;
			low[k] = a[i] ;
		}
	}
	cout<<cnt ;

    return 0;

}

猜你喜欢

转载自blog.csdn.net/qq_41661809/article/details/88647528
今日推荐