跳到正文

题解

题解:CF148C Terse princess

LJQ0808约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年10月28日
收录
2026年11月3日
更新
2026年11月3日
篇幅
约 2 分钟
题目
CF148C

版本

  1. v1当前

传送门

题解

为了公主发出“哇!”的声音,最优的方案是首项为 11 公比为 22 的等比数列。

同理:发出“哦”的声音,最优的方案是首项为等比数列的最后一项加一,公差为 11 的等差数列。

但当公主发出“哇!”的声音次数为零时,则前面一群一加上等差数列即可。

C++
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
signed main(){
	//HAPPY!
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n,x,y;
	cin>>n>>x>>y;
	if(n==1){
		cout<<"1\n";
		return 0;
	}
	if(x==n-1){
		cout<<"-1\n";
		return 0;
	}
	if(y){
		int val=1;
		cout<<"1 ";
		for(int i=1;i<=y;i++){
			cout<<(val<<=1)<<" ";
		}
		for(int i=1;i<=x;i++){
			cout<<(++val)<<" ";
		}
		for(int i=1;i<n-x-y;i++){
			cout<<"1 ";
		}
		cout<<"\n";
	}
	else{
		for(int i=1;i<=n-x;i++){
			cout<<"1 ";
		}
		int val=1;
		for(int i=1;i<=x;i++){
			cout<<(++val)<<" ";
		}
		cout<<"\n";
	}
	return 0;
}
原文