牛客练习赛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))
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值