Codeforces 488 B. Candy Boxes(构造)

环境科研人必备:手把手教你用EPISuite 4.1批量预测化合物毒性(附ECOSAR实战) 本文详细介绍了EPISuite 4.1在环境毒理学研究中的应用,重点解析了ECOSAR模块的化合物毒性预测技术。通过批量处理实战和科研案例,帮助环境科研人员快速评估化学物质对水生生态系统的风险,提升工作效率。文章还涵盖了EPISuite核心模块的功能分类及ECOSAR模型的技术原理与算法特点。 阅读详情

Candy Boxes

题目链接:

http://codeforces.com/problemset/problem/488/B

解题思路:

codeforces官方题解:

Let's sort the four numbers in ascending order: a, b, c, d (where x1, x2, x3, x4 are used in problem statement). So .

With some basic math, we can get a: d = 1: 3 and a + d = b + c.

Solution 1:

If n = 0, just output any answer (such as {1, 1, 3, 3}). If n = 1, just output {x, x, 3x, 3x}, where x is the known number. If n = 4, just check whether the four known numbers meet the condition.

If n = 2, let x, y denote the known numbers (x ≤ y). No solution exists if 3x < y. Otherwise we can construct a solution {x, y, 4x - y, 3x}(certainly other solutions may exist).

If n = 3, let x, y, z denote the known numbers (x ≤ y ≤ z). No solution exists if 3x < z. Otherwise the solution can only be {x, y, z, 3x},  or {x, y, x + z - y, z}.

Solution 2:

The known numbers are no larger than 500, so all numbers are no larger than 1500 if solution exists. We enumerate x from 1 to 500, yfrom x to 3x, then {x, y, 4x - y, 3x} is a solution. For each solution, check if it matches the known numbers.

Solution 3:

If n = 0, just output any answer (such as {1, 1, 3, 3}). If n = 1, just output {x, x, 3x, 3x}, where x is the known number. If n = 4, just check whether the four known numbers meet the condition.

Otherwise, we can enumerate the 1 or 2 missing number(s), and check if the four numbers meet the condition.

题目大意:

给你4个数,x1<=x2<=x3<=x4, 且(x1+x2+x3+x4)/2 ==(x2+x3)/2==x4-x1。

已知n<=4个数,现在要构造4-n个数,让这4个数满足上述条件。

算法思想:

由四个数的关系我们可以解得:3*x1==x4,x1+x4==x2+x3。

由于n<=4可以直接分类讨论即可。

但是我的做法是枚举x1,贪心构造满足条件的4个数。

AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int a[5],t;
        if(n == 0){
            printf("YES\n");
            printf("1\n1\n3\n3\n");
        }
        else{
            scanf("%d",&a[0]);
            if(n == 1){
                printf("YES\n");
                printf("%d\n%d\n%d\n",a[0],a[0]*3,a[0]*3);
            }
            else if(n == 2){
                scanf("%d",&a[1]);
                sort(a,a+2);
                if(a[0]*3 < a[1])
                    printf("NO\n");
                else{
                    printf("YES\n");
                    printf("%d\n%d\n",a[0]*4-a[1],a[0]*3);
                }
            }
            else if(n == 3){
                scanf("%d%d",&a[1],&a[2]);
                sort(a,a+3);
                if(a[2] == 3*a[0]){
                    printf("YES\n");
                    printf("%d\n",a[0]*4-a[1]);
                }
                else if(a[2] < 3*a[0] && a[2] == a[0]*4-a[1]){
                    printf("YES\n");
                    printf("%d\n",3*a[0]);
                }
                else if(a[2] % 3 == 0 && a[2]/3*4-a[0] == a[1]){
                    printf("YES\n");
                    printf("%d\n",a[2]/3);
                }
                else
                    printf("NO\n");
            }
            else if(n == 4){
                scanf("%d%d%d",&a[1],&a[2],&a[3]);
                sort(a,a+4);
                if(a[3] != 3*a[0] || a[2] != a[0]*4-a[1])
                    printf("NO\n");
                else
                    printf("YES\n");
            }
        }
    }
    return 0;
}




【2027最新版】PCL点云处理算法汇总(C++长期更新版) PCL学习目录。博客长期更新,最近一次更新时间为:2026年11月29日。 阅读详情

相关推荐

数据中心光模块升级实录:从200G QSFP56到400G QSFP-DD的踩坑指南

本文记录了数据中心从200G QSFP56升级至400G QSFP-DD光模块的完整实战经验。文章深入剖析了升级过程中面临的兼容性、链路预算、布线、散热与功耗管理等核心挑战,并提供了具体的解决方案与排坑指南,为高速网络升级提供了宝贵的实践参考。

butter的博客 494

codeforces 488B Candy Boxes

题目链接 B. Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is an old tradition of keepin

madaidao的专栏 655

Vivado与VCS+Verdi联合仿真环境搭建全攻略

本文详细介绍了如何搭建Vivado与VCS+Verdi联合仿真环境,旨在解决Vivado Simulator在大型FPGA验证中速度慢、调试弱的问题。通过指导工具版本配对、环境变量设置、关键参数配置及Xilinx仿真库编译,帮助工程师高效整合Vivado的设计管理、VCS的高速仿真与Verdi的深度调试能力,从而显著提升验证效率。

weixin_29219189的博客 651

Codeforces #488div.2 - 994B - Knights of a Polygonal Table(堆+贪心)

很明显要维护一个大小为k的小顶堆,每次判断小顶堆是否值得被剔除。 需要注意两点: ①力量相同的骑士共用一个堆状态; ②堆为0时可能会导致取空堆的情况; ③10*10^9&amp;gt;INTMAX #include &amp;lt;cstdio&amp;gt; #include &amp;lt;queue&amp;gt; #include &amp;lt;algorithm&amp;gt; using namespace std; struc

Myriad Dreamin 愿逐将属于我的奇迹 512

如何编写 Skill 实现自动化用例生成

Skill 本质上是一组结构化的指令和工具定义,它告诉 AI 模型在特定场景下应该遵循什么流程、调用哪些工具、输出什么格式的内容。元信息:名称、描述、版本等。指令(Instructions):定义 AI 的行为准则和任务流程。工具(Tools):AI 可以调用的外部能力,如文件读写、代码执行、API 请求等。上下文(Context):预设的输入输出格式或示例。编写一个用于自动生成测试用例的 Skill,核心在于定义清晰的指令流程和输出规范。

Cesare的博客 2780

CP AUTOSAR标准之AUTOSAR OS(AUTOSAR_SWS_OS)(二)

AUTOSAR OS是一个Operating System,即操作系统。它最核心的功能是管理任务和事件的调度,不同任务间的同步流,并且提供监控和错误处理功能。或者用最简化理解就是一个函数调度器。

CoolBreeze的博客 661

codeforce 488B. Candy Boxes

488B. Candy Boxes 题意 给定n个数(0 <= n <= 4),添加4 - n 个数,得到4个数,排序好得到x1, x2, x3, x4 使得这四个数满足 (x1 + x2 + x3 + x4) / 4 == (x2 + x3) / 2 == x4 - x1 思路 由(x1 + x2 + x3 + x4) / 4 == (x2 + x3) / 2 == x4 - x1 可得 x1 + x4 == x2 + x3 x4 = 3 * x1 由于给定的n个数不会大于500,我们可以

weixin_45535709的博客 157

YOLOv12模型详解及代码复现

YOLOV12算法详解及Python代码复现

hasakie的博客 6505

amusing joke

A. Amusing Joke time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output So, the New Year holidays are over. Santa C

1160

【DRAM存储器六十六】DDR5介绍--训练相关之CA/CS Training

详述DDR5 CA/CS training过程细节

highman110的博客 226

在 Visual Studio Code 中开发 SAP Fiori 应用并部署到 Cloud Foundry 的完整实战指南

摘要:本文介绍如何以ABAP RAP服务为后端,通过VS Code和SAP Fiori工具将Fiori应用一键部署到SAP BTP Cloud Foundry环境。主要内容包括:1) 开发环境配置(VS Code+Fiori工具);2) 架构流程说明(MTA打包、Approuter路由);3) 权限准备(业务Catalog分配);4) 创建带Approuter的MTA项目;5) 连接ABAP OData服务并生成Fiori应用。文中还针对常见问题(如服务不可见、部署失败)提供了解决方案参考。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 387

Codeforces 488B - Candy Boxes (构造)

题意 如果有一个序列满足(a1 + a2 + a3 + a4) / 4 = (a2 + a3) / 2,并且等于a4 - a1那么这个序列符合条件的。 现在给出4个数中的n个,判断能否构造出这么一个序列。 思路 这是我写过最长的DIV2 - B( TДT) 解这个题目之前,首先要推出两条式子 x4=3x1 4x1=x2+x3 读取输入

一只冰熊 1313

【RT-DETR实战】112、NCNN模型转换与层实现支持:从模型文件到推理引擎的硬核实战

本文详细记录了将RT-DETR模型部署到NCNN框架的全过程及关键要点。作者首先遇到MultiHeadAttention等算子不支持的问题,通过ONNX中间转换和自定义层实现解决。文章具体介绍了PyTorch到NCNN的权重转换技巧、模型优化方法(包括量化和线程优化)以及调试经验,强调逐层对比输出、预处理检查和边界情况测试的重要性。最后分享了保持转换流程可复现性的实用建议,指出手动调试虽然耗时但能加深对模型的理解,体现了工程师在解决技术难题时的专业精神与成就感。

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 53

Codeforces 488B - Candy Boxes

B. Candy Boxes 题目链接:http://codeforces.com/problemset/problem/488/B time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output ...

weixin_33735077的博客 170

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Codeforces 488B Candy Boxes(水)

题目链接:Codeforces 488B Candy Boxes #include #include #include using namespace std; int arr[4]; bool judge () { int a[4]; memcpy(a, arr, sizeof(arr)); sort(a, a + 4); for (int i = 1; i < 4; i

不慌不忙、不急不躁 888

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Codeforces 488B Candy Boxes【思维+分类讨论】

B. Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is an old tradition of keeping 4 boxes of candies

mengxiang000000 558

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Codeforces Round #278 (Div. 2)B. Candy Boxes

http://codeforces.com/contest/488/problem/B 两份代码 这道题虽然不难,但是好麻烦的说= =,还是自己思维不够纯熟,不能很有条理的写下每一种情况,从题目要求可以得到 a 这些就足够了,剩下就是不断判断,第一份是WArush出来的,第二份是整理下思维重写的,虽然看不出来啥区别= = #include #include using namespace

GoodGame_fpcsong 503

Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

B. Candy Boxes  Problem's Link:   http://codeforces.com/contest/488/problem/B   Mean:  T题目意思很简单,不解释。 analyse: 这道题还是很有意思的,需要考虑到各种情况才能AC。 解这个题目之前,首先要推出两条式子   x4=3x1  4x1=x2+x3 然后就是分类讨论,枚举各种情况

北岛知寒 229

CF #278 (Div. 2) B.(暴力枚举+推导公式+数学构造)

B. Candy Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output 题目链接:http://codeforces.com/contest/488/problem/B

代码艺术的道与术 1200

codeforces 488 D. Strip

D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alexandra has a paper strip with n numbers on it. L

whai的专栏 646

codeforces 488 E. Prefix Product Sequence

E. Prefix Product Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Consider a sequence [a1, a2, ...

whai的专栏 707

Codeforces 488 C. Fight the Monster(模拟)

题目链接:http://codeforces.com/problemset/problem/488/A 解题思路:Codeforces官方题解:

piaocoder 750

HDU5100 Chessboard(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5100 解题思路:BestCoder官方题解:

piaocoder 879

HDU5109 Alexandra and A*B Problem(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5109 解题思路:BestCoder官方题解:

piaocoder 825
上一篇: HDU5100 Chessboard(数学题)
下一篇: 搞ACM的你伤不起(转)
yphacker
博客等级 码龄12年 199粉丝 540原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址