A. Add Candies(思维)Codeforces Round #683 (Div. 2, by Meet IT)

原题链接: http://codeforces.com/contest/1447/problem/A

在这里插入图片描述
测试样例

input
2
2
3
output
1
2
5
3 3 3 1 2

Note

In the first case, adding 1 candy to all bags except of the second one leads to the arrangement with [2,2] candies.

In the second case, firstly you use first three operations to add 1+2+3=6 candies in total to each bag except of the third one, which gives you [7,8,3]. Later, you add 4 candies to second and third bag, so you have [7,12,7], and 5 candies to first and third bag — and the result is [12,12,12].

题意: 你有 n n n个包,第 i i i个包中有 i i i个糖果,现在你可以进行 m m m个操作,其中第 i i i个操作表述为选择一个包,使得除这个包之外所有的包中的糖果都加上 j j j个糖果,现在你需要使得每个包中的糖果都相同。(不必在乎 m m m个大小)

解题思路: 这是一道思维题,也相当于找规律的题,不要被样例迷惑了。我们发现,如果我们进行 m m m个操作,其中在第 i i i个操作中刚好选择第 i i i个包,那么最后所有的包的糖果都是 1 + 2 + 3... + n 1+2+3...+n 1+2+3...+n个,都是相等的。 这即是正确答案。

AC代码

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>//POJ不支持

#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)

using namespace std;

const int inf=0x3f3f3f3f;//无穷大。
const int maxn=1e5;//限定值。
typedef long long ll;

int t,n;
int main(){
    while(cin>>t){
        while(t--){
            cin>>n;
            cout<<n<<endl;
            rep(i,1,n){
                cout<<i<<" ";
            }
            cout<<endl;
        }
    }
	return 0;
}
posted @   unique_pursuit  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示