2020-2021JMU蓝桥校选

学习不是记模板,而是学习思想

7-1 邪恶学长的代码 (5分)

又是一次蓝桥校选,根据传统先膜拜一下HX大佬,哦当然还有LJL,JXJ,HJQ等给位大佬。 只要输出这个,HX就会保佑我们不爆零,成功签到。

输入格式:
这题没有输入

输出格式:
输入样例:
输出样例:
//
// _ _ _ _______ _______ _ _____ _ ___ //
//| | | | | |
\ / / | | | | | | | | \ / ///
//| | _ | | | | | \ / | | | | | | | |
| |\ / //
//| |
| || | |_ | | / \ | | | || | | _ |/ \ //
//|
_/|| || //_\ |_| ||| || |//_//
// //
// _ _ _ ___ __ ____ ______ ____ //
//| | | | | |/ _ \ \ \ / /\ \ / / _ / | //
//| |
| |
| | | | | \ V / \ V /| | | _
_ \ //
//| _ | || | || | | | | | | || |) | //
//|
| |
|___/ __\ || || |/|_/ //
//

把所有\变为\就行了,第一次做的时候/\还没分清,搞反了。

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string>
#include<string.h>
#include<set>
#define inf 0x3f3f3f3f
typedef long long ll;

using namespace std;
/*
//
// _        _ _       _______  _______   _   _____   _   ___  __//
//| |      | | |     |_   _\ \/ /_   _| | | |_   _| | | | \ \/ ///
//| |   _  | | |       | |  \  /  | |   | |   | |   | |_| |\  / //
//| |__| |_| | |___    | |  /  \  | |   | |___| |   |  _  |/  \ //
//|_____\___/|_____|   |_| /_/\_\ |_|   |_____|_|   |_| |_/_/\_\//
//                                                              //
// _   _     _  ___   __   ____   ______  ____                  //
//| | | |   | |/ _ \  \ \ / /\ \ / /  _ \/ ___|                 //
//| |_| |_  | | | | |  \ V /  \ V /| | | \___ \                 //
//|  _  | |_| | |_| |   | |    | | | |_| |___) |                //
//|_| |_|\___/ \__\_\   |_|    |_| |____/|____/                 //
//
*/
int main()
{
	cout<<"//"<<endl
<<"// _        _ _       _______  _______   _   _____   _   ___  __//"<<endl
<<"//| |      | | |     |_   _\\ \\/ /_   _| | | |_   _| | | | \\ \\/ ///"<<endl
<<"//| |   _  | | |       | |  \\  /  | |   | |   | |   | |_| |\\  / //"<<endl
<<"//| |__| |_| | |___    | |  /  \\  | |   | |___| |   |  _  |/  \\ //"<<endl
<<"//|_____\\___/|_____|   |_| /_/\\_\\ |_|   |_____|_|   |_| |_/_/\\_\\//"<<endl
<<"//                                                              //"<<endl
<<"// _   _     _  ___   __   ____   ______  ____                  //"<<endl
<<"//| | | |   | |/ _ \\  \\ \\ / /\\ \\ / /  _ \\/ ___|                 //"<<endl
<<"//| |_| |_  | | | | |  \\ V /  \\ V /| | | \\___ \\                 //"<<endl
<<"//|  _  | |_| | |_| |   | |    | | | |_| |___) |                //"<<endl
<<"//|_| |_|\\___/ \\__\\_\\   |_|    |_| |____/|____/                 //"<<endl
<<"//"<<endl;
}

7-2 真正的送分题 (10分)

看到邪恶的驰神给大家的送分(ming)题,善良的jxj决定给大家出一道真正的送分题。

给两个整数,输出它们的平均数即可,忽略小数部分。即⌊(a+b)/2⌋。

输入格式:
输入在一行中给出2个整数A和B。(0<=A<=264-1,0<=B<=264-1)

(题目有多组样例,处理到文件结束)

输出格式:
对每一组输入,在一行中输出A+B的值。

输入样例1:
0 0
输出样例1:
0
输入样例2:
2 3
输出样例2:
2
这题我之前混淆的一点是long long的范围是-263-1到263-1,因为最高位被符号位占了,因此必须要用unsigned long long才能满足题目要求。然后再就是普通的优化了。只有两个都为奇数时,答案是a/2+b/2+1,否则就是a/2+b/2;

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<math.h>
#include<stdio.h>
#define inf 0x3f3f3f3f
typedef unsigned long long ull;

using namespace std;


int main()
{
ull a,b;
while((scanf("%lu %lu",&a,&b))!=EOF)
{
	ull ans=a/2+b/2;
	if(a&1&&b&1)
	cout<<ans+1;
	else 
	cout<<ans; 
	cout<<endl;
}
}

7-3 tly的摩天轮 (15分)

有一天tly去游乐园,看见了摩天轮就兴奋的上去玩,刚坐上去摩天轮就突然抽风开始以一个很快的速度旋转,现在tly想知道自己用多大的力气抓住摩天轮才不会被甩出去。情况紧急,这个时候我们忽略重力,摩擦力等等等。抽象成一个匀速圆周运动的模型。大家快来帮帮我们的tly。

输入格式:
依次输入摩天轮的半径(m)(大于0小于1e6),和tly所在位置的线速度(m/s)(大于0小于1e5),以及tly的质量(kg)(大于0小于1e6)。

输出格式:
在一行中输出tly不会被甩出去至少需要的力气(N),保留3位小数。

输入样例:
1000 8 60
输出样例:
在这里给出相应的输出。例如:

3.840

感觉这题是最简单的一题了,向心力F=mv2/R

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<math.h>
#include<stdio.h>
#define inf 0x3f3f3f3f
typedef unsigned long long ull;

using namespace std;


int main()
{
	double r,v,m;
	cin>>r>>v>>m;
	printf("%.3f\n",m*v*v/r);
}

7-4 谁是龙王2 (12分)

龙王是QQ群聊中推出的一个头衔,每天在群中发言数最多的人将可获得此称号。

现在给你某个群中一天的n条群聊记录,请你找出谁是龙王。(若发言数最多的有多个人,则选择最先发言的为龙王)

输入格式:
第一行一个整数n,表示某个群中一天的n条群聊记录。

接下去n行,每行输入一个name还有一个msg(可能包含空格),格式如下。

name:msg
题目保证:

0<=n<=1e5

每个群的人数不超过200人。

name的长度不超过10个字符。

msg的长度不超过100个字符。

输出格式:
输出龙王的名字。

输入样例1:
10
HX:HXYYDS
LT:HXYYDS
JXJ:HXYYDS
LJL:HXYYDS
TXT:HXYYDS
HX:HXYYDS
LJL:HXYYDS
HJQ:HXYYDS
LFX:HXYYDS
TXT:HXYYDS
输出样例1:
HX
输入样例2
10
TXT:TXT YYDS
TXT:TXT YYDS
TXT:TXT YYDS
LJL:TXT YYDS
LT:TXT YYDS
LMH:TXT YYDS
LJL:TXT YYDS
JXJ:TXT YYDS
HX:TXT YYDS
HJQ:TXT YYDS
输出样例2
TXT
把每一行名字和次数,次序用map存,再遍历寻找次数最大同时次序最小的就行了。
tips:getline(cin,s)是读取一行删除\n但是cin.getline的换行符则保留在缓冲区
这题写的比较慢,对map的掌握不够熟练,读取名字也想了一会

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string>
#define inf 0x3f3f3f3f
typedef unsigned long long ull;

using namespace std;

class p
{
public:
	int cnt;
	int order;
	p(){cnt=0,order=0;}
};
map<string,p> mp;
int main()
{
	int n;
	char ch;
	cin>>n;
	getchar();
	for(int i=0;i<n;++i)
	{
		string s;
		ch=getchar();
		while(ch!=':')
		{
			s+=ch;
			ch=getchar();
		}
		mp[s].cnt++,mp[s].order=i;
		getline(cin,s);
	}
	int maxn=0,minorder=inf;
	string ans="";
	for(map<string,p>::iterator it=mp.begin();it!=mp.end();it++)
	{
		if(maxn<(*it).second.cnt||maxn==((*it).second.cnt&&(*it).second.order<minorder))
		maxn=(*it).second.cnt,ans=(*it).first,minorder=(*it).second.order;
	}
	cout<<ans<<endl;
}
}

7-5 爱瞎跑的学长 (20分)

tly还在游乐园里玩,从摩天轮上幸存下来后,又来到了鬼屋,可是刚一进去入口就被堵住了,鬼屋中有许多工作人员扮演的NPC,tly害怕的只能绕着他们走,厉害的是这个鬼屋还有好几层,通过梯子相连,可以爬上也可以爬下,爬一次楼梯算一步,切记如果梯子联通的地方有鬼的话tly就不会爬那个梯子(通过梯子联通定义为两个地方至少有一个梯子),快来帮他算一算至少要走几步才能走出鬼屋。题目会给出地图,其中.为可以走的地方,*为NPC的位置,+为梯子,P为tly现在在的地方,E为出口。 路径规则:左为l,右为r,上为b,下为f,向上一层为u,向下一层为d

输入格式:
输入一个t(<10),为测试的组数,每一组独立。每组输入一个n(<50),为鬼屋的层数,x,y为鬼屋每层的的行数和列数(x<=100,y<=100),然后依次输入从下网上层的地图。

输出格式:
对每一组输入,在一行中输出走出鬼屋的步数和路径。如果走不出来就输出"xie’e"。 如果有多个答案,输出路径字典序最小的。

输入样例:
2
3 4 5
P…
****.
***…
**.




**.++



.**
****E

1 3 3
P**
E


输出样例:
11 rrrrfflfuru

这题写的可以说是很慢了

一开始还用dfs做,没有意识到最小的步数,当以前常做的题目了,直接爆炸,补题的时候用bfs还是拿不了满。

7-6 区间和 (25分)

现有一长度为n的序列,问有多少个连续子序列的和大于等于这个子序列的长度乘以x

输入格式:
第一行两个整数n,x 第二行有n个整数 0<n<=100000

输出格式:
输出一个整数,表示多少个连续子序列的和大于等于这个子序列的长度乘以x

输入样例:
4 3
3 2 1 5
输出样例:
在这里给出相应的输出。例如:

3

这个题目的难度是数一数二的,我们可以先对数列中每个数都-=x,这样把大于等于子序列长度*x转化成>=0,简单了很多,其次因为要处理区间和,所以前缀和处理是能够简化一些,但是如果暴力还是要O(n2),因此我们可以继续观察这个前缀和数列,我们可以先固定一个数作为左边界,那么任意一个在它右边且值大于它的数都可以和他组成一个满足题意的子序列,比赛中我是想用lower_Bound做的,但是忽略了lower_bound的使用条件——对排序好的数组才能处理。后面才想到可以用逆序数,其实我们要求的可以理解为正序数,因此把总数和逆序数相减就能求出答案。
逆序数的两种求法

#include<iostream>
#include<algorithm>

using namespace std;

class p
{
public:
	int v;
	int sqc;
};
int sum[(int)1e5+5];
int tmp[(int)1e5+5];
int ni=0;
void merge(int l,int r)
{
	int mid=(l+r)/2;
	int p1=l,p2=mid+1;
	int k=l;
	while(k<=r)
	{
		if(p1>mid)
		tmp[k++]=sum[p2++];
		else if(p2>r)
		tmp[k++]=sum[p1++];
		else if(sum[p1]>sum[p2])
		tmp[k++]=sum[p2++],ni+=p2-k;//printf("l=%d r=%d p2=%d k=%d\n",l,r,p2-1,k-1);
		else
		tmp[k++]=sum[p1++];
	}
	for(int i=l;i<=r;++i)
	sum[i]=tmp[i];
}
void divide(int l,int r)
{
	if(l>=r)
	return;
	int mid=(l+r)/2;
	divide(l,mid);
	divide(mid+1,r);
	merge(l,r); 
}
int main()
{
	int n,x,num;
	cin>>n>>x;
	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
	scanf("%d",&num);
	num-=x;
	sum[i]=sum[i-1]+num;
	}
	divide(0,n);
	cout<<n*(n+1)/2-ni<<endl;
}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值