跳到正文

题解

题解

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

文章信息

发布
2023年9月27日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 2 分钟
题目
P9652

版本

  1. v1当前

思路

这题你很蒙吗?

看看测试点吧!

测试点

原版
代码
1 5 4 ->1 1 1 1 1
2 3 8 ->2 2 3
1 5 10 ->1 1 1 7 7
2 6 34 ->1 1 4 5 1 4
1 3 1 ->-1

许多测试点都有1,所以…

改进版
代码
1 5 4 ->1 1 1 1 1
2 3 8 ->1 1 7
1 5 10 ->1 1 1 7 7
2 6 34 ->1 1 1 1 1 30
1 3 1 ->-1

np=1->至少n-2个1

np=2->至少n-1个1

x-n+2<0 -> -1

初步调试

C++
#include<iostream>
using namespace std;
int main(){
	int k;
	cin>>k;
	for(int i=1;i<=k;i++){
		int op,n,x;
		cin>>op>>n>>x;
		if(x-n+2>0){
			for(int i=0;i<=n-3;i++){
				cout<<1<<" ";
			}
		    if(op==1){
			    ?
		    }
    		if(op==2){
    			cout<<1<<" "<<?<<endl;
    		}
    		continue;
		}
		cout<<-1<<endl;
		
	}
	return 0;
}

再调试

其他的数相等,是x-n+2

C++
#include<iostream>
using namespace std;
int main(){
	int k;
	cin>>k;
	for(int i=1;i<=k;i++){
		int op,n,x;
		cin>>op>>n>>x;
		if(x-(n-2)>0){
			for(int i=0;i<=n-3;i++){
				cout<<1<<" ";
			}
		    if(op==1){
			    cout<<x-n+2<<" "<<x-n+2<<endl;
		    }
    		if(op==2){
    			cout<<1<<" "<<x-n+2<<endl;
    		}
    		continue;
		}
		cout<<-1<<endl;
		
	}
	return 0;
}

谢谢!

原文