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. Sentry 监控 - Snuba 数据中台架构(编写和测试 Snuba 查询)

    系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...

  2. watch异步操作

    异步操作: 1.ajax, 2.定时器 3.点击事件 4.数据库操作 特点:代码不等待,后续代码会继续执行. watch:{ //watch作用监测已经存在的数据 newVal 新值,oldVal 旧 ...

  3. Go语言核心36讲(Go语言实战与应用十六)--学习笔记

    38 | bytes包与字节串操作(上) 前导内容: bytes.Buffer基础知识 strings包和bytes包可以说是一对孪生兄弟,它们在 API 方面非常的相似.单从它们提供的函数的数量和功 ...

  4. 基于Ubuntu 18.04.5 LTS 部署Ceph集群测试及Ceph RDB的使用。

    1.ceph简介 Ceph在一个统一的系统中独特地提供对象.块和文件存储 1.1 ceph官网架构图 1.2 架构解释   CEPH 对象存储 CEPH 块设备 CEPH 文件系统 RESTful 接 ...

  5. CF30E. Tricky and Clever Password

    被你谷翻译诈骗了兄弟. 不过下次可以拿去诈骗其他人. 考虑枚举B,显然结论有B作为回文串越长越好,这个可以使用manacher,或者直接二分hash. 然后考虑翻转末尾串,然后记录其匹配到第 \(i\ ...

  6. PHP 获取两个日期相差多少年,多少月,多少天,多少小时,并填充数组

    PHP 获取两个日期相差多少年,多少月,多少天,多少小时,并填充数组 <?php /** * 获取两个日期相差多少年,多少月,多少天,多少小时,并填充数组 * @param [type] $st ...

  7. Golang gRPC调试工具

    目录 Golang gRPC调试工具 1. 命令行工具 grpcurl 1.1 安装 1.2 验证 1.3 注册反射 1.4 使用示例 2. web调试工具grpcui 2.1 安装 2.2 验证 2 ...

  8. rkhunter使用

    1.下载地址:http://jaist.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.6/ 2.上传至Linux后解压 3.编译安装 [root@t ...

  9. rabbit mq的安装

    rabbit mq的安装分为window的安装和linux的安装. window的安装: 1,需要安装 安装Erlang  下载地址http://www.erlang.org/downloads 我选 ...

  10. 阿里云ECS磁盘性能测试

    阿里官方给出的性能指标 顺序读 测试命令 fio -directory=/var/lib/data -direct=1 -iodepth=1 -thread -ioengine=libaio -ran ...