Content

圣诞老人有 \(n\) 颗糖果,他想把这些糖果分发给一些小孩子,并想要每个孩子都能得到不同的糖果数目。求能得到糖果的孩子的最大数目,以及他们各自得到的糖果数。

数据范围:\(1\leqslant n\leqslant 1000\)。

Solution

我们可以往下枚举每个小孩的糖果数目,然后不断地深入搜索,然后得到的第一个合法的方案就是我们想要的得到糖果的孩子的最大数目,直接输出方案即可。

Code

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std; int n, vis[1007]; void dfs(int x) {
if(!x) {
int ans = 0;
for(int i = 1; i <= n; ++i) ans += vis[i];
printf("%d\n", ans);
for(int i = 1; i <= n; ++i)
if(vis[i]) printf("%d ", i);
exit(0);
}
for(int i = 1; i <= x; ++i) {
if(!vis[i]) {
vis[i] = 1;
dfs(x - i);
vis[i] = 0;
}
}
} int main() {
scanf("%d", &n);
dfs(n);
}

CF753A Santa Claus and Candies 题解的更多相关文章

  1. Codeforces 752C - Santa Claus and Robot - [简单思维题]

    题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...

  2. codeforces 748E Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  3. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  4. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. Codeforces Round #389 Div.2 E. Santa Claus and Tangerines

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. Codeforces Round #389 Div.2 D. Santa Claus and a Palindrome

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Codeforces Round #389 Div.2 C. Santa Claus and Robot

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. Codeforces Round #389 Div.2 B. Santa Claus and Keyboard Check

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. Codeforces Round #389 Div.2 A. Santa Claus and a Place in a Class

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. Hi3516开发笔记(三):Hi3516虚拟机基础环境搭建之交叉编译环境境搭建以及开机启动脚本分析

    前言   前面进行了可以传输,那么写一个简单的C程序来交叉编译并传入运行.   虚拟机   上一篇搭建的虚拟机环境,包含了sftp传递文件,网络能ping通,基于上一篇的虚拟机继续搭建.   海思交叉 ...

  2. ElasticJob分布式任务调度应用v2.5.2

    为何要使用分布式任务调度 **本人博客网站 **IT小神 www.itxiaoshen.com 演示项目源码地址** https://gitee.com/yongzhebuju/spring-task ...

  3. CF 585 E Present for Vitalik the Philatelist

    CF 585 E Present for Vitalik the Philatelist 我们假设 $ f(x) $ 表示与 $ x $ 互质的数的个数,$ s(x) $ 为 gcd 为 $ x $ ...

  4. Educational Codeforces Round 89 题解

    昨晚简单 vp 了场比赛找了找状态,切了 5 个题(有一个差点调出来),rk57,还算理想吧,毕竟我已经好久没碰过电脑了( A 签到题不多说,直接输出 \(\min\{a,b,\dfrac{a+b}{ ...

  5. Atom编辑器速查

    简介 Atom 是 Github 开源的文本编辑器,相当于半个IDE.其特点如下: (1)免费开源,多平台支持(Windows.Mac.Linux): (2)界面美观.现代化,使用舒适: (3)多文件 ...

  6. mysql_sql查性能语句

    mysql> SHOW PROCESSLIST; +----+--------+----------------------+-------+-------------+--------+--- ...

  7. [源码解析] PyTorch 分布式 Autograd (5) ---- 引擎(上)

    [源码解析] PyTorch 分布式 Autograd (5) ---- 引擎(上) 目录 [源码解析] PyTorch 分布式 Autograd (5) ---- 引擎(上) 0x00 摘要 0x0 ...

  8. Matlab | 绘制动态曲线(使用 animatedline 对象)

    效果如下: 示例代码: figure('Color','w'); h1 = animatedline; h1.Color = 'r'; h1.LineWidth = 1.0; h1.LineStyle ...

  9. 单元测试在Unity中的应用

    项目描述:简单演示单元测试在Unity中的应用 项目地址:UnityTestRunner_Tutorial - SouthBegonia 项目版本:2020.3.20f1 项目用法:打开就用,代码都放 ...

  10. 学习java的第十三天

    一.今日收获(前两天家里有事,博客都忘了发了,唉) 1.通过看哔哩哔哩看黑马程序员的教学视频,学习了java中的数据类型自动转换.强制转换及注意事项三节 2.简单看了看完全学习手册 二.今日问题 1. ...