Codeforces Round 943 (Div. 3)

A. Maximize?

比赛时居然卡了10分钟,主要问题没有读清题是输出y的值,一直输出最大的结果(一定要都读清题再下笔)

B. Prefiquence

双指针问题,主要还是练的题少。

C. Assembly via Remainders

构造题,我主要卡在会发现如果x+a[i]小的话,会发现会有a[i+1]会整除x+a[i]

题目中ai的值很小,所以设第一个数大于500即可,这样不会出现整除的情况。

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N=510;

int a[N];
void solve()
{
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)cin>>a[i];
	cout<<"700";
	int x=700;
	for(int i=0;i<n-1;i++)
	{
		cout<<" "<<x+a[i];
		x+=a[i];
	}
	cout<<endl;
} 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while (t--) {
		solve();
	}
} 

D. Permutation Game

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N=200010;

int p[N],a[N];
int n,k,b,s;
int st[N];
//ps:本题问题主要出现在我想到他俩不能在一个位置,但是题目中并没有说
//不能在同一位置
//主要点在一直呆在该点直至结束,如果在回到该点,则一定小
 
int get(int x)
{
	memset(st,0,sizeof st);
	int cnt=0,sum=0;
	int ans=0;
	while(cnt<=k&&st[x]==0)
	{
		st[x]=1;
		ans=max(ans,sum+(k-cnt)*a[x]);
		sum+=a[x];
		x=p[x];
		cnt++;
	}
	return ans;
}
void solve()
{
	cin>>n>>k>>b>>s;
	for(int i=1;i<=n;i++)cin>>p[i];
	for(int i=1;i<=n;i++)cin>>a[i];
	int x=get(b);
	int y=get(s);
	if(x==y)cout<<"Draw"<<endl;
	else if(x>y)cout<<"Bodya"<<endl;
	else cout<<"Sasha"<<endl; 
} 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while (t--) {
		solve();
	}
} 

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值