牛客练习赛55


等火车

题意:

火车是按照周期经过,询问多个时刻,求每个时刻还要多久才会有火车经过

分析:

小学生基础题吧

代码:

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<vector>
#define LL long long 
using namespace std;
inline LL read() {
    
    
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){
    
    if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){
    
    d=d*10+s-'0';s=getchar();}
    return d*f;
}
int main()
{
    
    
	int s=read(),q=read();
	for(int i=1;i<=q;i++)
	{
    
    
		int a=read();
		if(!(a%s)) printf("%d\n",a%s);
		else printf("%d\n",s-a%s);
	}
	return 0;
}

数字游戏

题意:

2 、 3 、 4 … … 2 n 2、3、4……2n 2342n这几个数
对于每个数我们都可以在一开始擦掉,之后按照乙 → → → → 乙的顺序轮流擦数
直到剩下两个数
如果互质,则甲胜,否则乙胜
问我们有多少种一开始就擦数的方案可以使得乙必胜


分析:

甲必定先擦偶数,乙则先擦奇数
所以我们只需要判断下奇数多还是偶数多就好了

代码:

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<vector>
#define LL long long 
using namespace std;
inline LL read() {
    
    
    LL d=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){
    
    if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){
    
    d=d*10+s-'0';s=getchar();}
    return d*f;
}
int main()
{
    
    
	LL n=read();
	cout<<n-1;
	return 0;
}

最大生成树

题意:

两点之间的边的权值是编号差的绝对值
问最大生成树的最大值能是多少

分析:

因为是最大生成树,所以我们肯定要选绝对值最大的两个点相连
在这里插入图片描述
蓝色的边代表要被加入最大生成树
类似的,我们就能得到答案无非是个关于等差数列的式子:
首项: n − 1 n-1 n1 末项: n / 2 n/2 n/2 项数: n / 2 n/2 n/2
最后感谢下 p y py py的优秀加法

代码:

n=int(input())
t=998244353
p=int(n/2)
print(int(((n-1+p)*p-n+1)%t))

猜你喜欢

转载自blog.csdn.net/qq_35786326/article/details/103539218