Additive equations (ZOJ-1204)

人体检测技术之TOF 智能人脸/视频锁领域的人体检测需求是要求远距离达到1m左右即可,一旦在此距离内检测人,则锁唤醒进行人脸识别,视频录制等操作。所以,人体检测技术非常关键。选型主要是几个维度:1.支持检测的距离范围,能否准确输出距离信息2.支持检测FOV3.场景适应性如何,如人体衣服颜色4.环境适应性如何,夏天高温环境下的测距是否准确5.批量一致性情况。 阅读详情

 We all understand that an integer set is a collection of distinct integers. Now the question is: given an integer set, can you find all its addtive equations? To explain what an additive equation is, let's look at the following examples: 
    1+2=3 is an additive equation of the set {1,2,3}, since all the numbers that are summed up in the left-hand-side of the equation, namely 1 and 2, belong to the same set as their sum 3 does. We consider 1+2=3 and 2+1=3 the same equation, and will always output the numbers on the left-hand-side of the equation in ascending order. Therefore in this example, it is claimed that the set {1,2,3} has an unique additive equation 1+2=3.
    It is not guaranteed that any integer set has its only additive equation. For example, the set {1,2,5} has no addtive equation and the set {1,2,3,5,6} has more than one additive equations such as 1+2=3, 1+2+3=6, etc. When the number of integers in a set gets large, it will eventually become impossible to find all the additive equations from the top of our minds -- unless you are John von Neumann maybe. So we need you to program the computer to solve this problem.

Input

The input data consists of several test cases. 
The first line of the input will contain an integer N, which is the number of test cases. 
Each test case will first contain an integer M (1<=M<=30), which is the number of integers in the set, and then is followed by M distinct positive integers in the same line.

Output

For each test case, you are supposed to output all the additive equations of the set. These equations will be sorted according to their lengths first( i.e, the number of integer being summed), and then the equations with the same length will be sorted according to the numbers from left to right, just like the sample output shows. When there is no such equation, simply output "Can't find any equations." in a line. Print a blank line after each test case.

Sample Input
3
3 1 2 3
3 1 2 5
6 1 2 3 5 4 6

Output for the Sample Input

1+2=3

Can't find any equations.

1+2=3
1+3=4
1+4=5
1+5=6
2+3=5
2+4=6
1+2+3=6

 代码如下:

#include<bits/stdc++.h>
using namespace std;
int a[33],l,b[33],n,flag;
void dfs(int s,int pos,int len)
{
    for(int i=pos+1;i<n;i++)
    {
       if(len==l&&s==a[i])
       {
           flag=0;
           for(int j=0;j<l-1;j++)
            cout<<b[j]<<'+';
           cout<<b[l-1]<<'='<<s<<endl;
       }
       if(s+a[i]<=a[n-1])
       {
           b[len]=a[i];
           dfs(s+a[i],i,len+1);
       }
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        flag=1;
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        for(l=2;l<n;l++)
            dfs(0,-1,0);
        if(flag)
            cout<<"Can't find any equations.\n";
        cout<<endl;
    }
    return 0;
}


OpenClaw使用ClawHub安装skill网络不稳定?Rate limit exceeded报错?试试这个国内高速镜像工具! 使用 ClawHub 安装 Skill 时遇到 🌐 网络不稳、❌ Rate limit 或命令不可用?使用这个镜像工具,轻松解决skill安装问题,⚡ 阅读详情

相关推荐

树莓派5搭建ROS1开发环境:从系统安装到环境变量配置

本文详细指导如何在树莓派5上搭建ROS1开发环境。针对树莓派OS非标准安装路径导致的常见CMake报错问题,提供了从系统烧录、一键安装ROS到关键环境变量配置的完整解决方案,确保工作空间能成功编译,助力机器人项目开发。

weixin_29159127的博客 388

ZOJ 1204(Additive equations)

//经典深搜DFS,其中参考了别人的代码 #include #include #include using namespace std; int n, a[30], visit[30]; bool flag;  //判断是否有解(即满足题意的等式) void DFS(int start, int depth, int sum)  //深搜 {     if (de

WuchangI的博客 1108

新版股票配资系统源码/股票分析系统技术方案

新版股票配资系统;全套源码支持新股申购功能,包含C#+MySQL开发的后台系统及Spring框架,采用C/S架构。注意:本源码仅限技术学习、功能测试及模拟交易使用,严禁用于非法用途,违者责任自负。

q318136906的博客 1654

ZOJ-1204 Additive equations (DFS)

Additive equations Time Limit: 10 Seconds      Memory Limit: 32768 KB     We all understand that an integer set is a collection of distinct integers. Now the question is: given an integer set, c

U-M-R的博客 1028

【Milvus】实战指南:利用milvus-backup实现高效数据备份与恢复

本文详细介绍了如何利用官方工具milvus-backup为Milvus向量数据库实施高效的数据备份与恢复。文章从备份的必要性出发,逐步讲解了环境准备、配置要点、全量与按需备份操作,以及恢复数据的关键步骤和验证方法,旨在帮助用户构建可靠的数据安全防线,应对误操作或系统故障风险。

weixin_29217235的博客 133

ZOJ 1204.Additive equations

给出一个整数集合,判断是否能用集合里的元素构造加法等式,若能则输出按顺序输出所有等式。 简单DFS()应用。 /* ZOJ 1204 Additive equations Sample Input 3 3 1 2 3 3 1 2 5 6 1 2 3 5 4 6 Output for the Sample Input 1+2=3 Can't find any equations. 1+2=

That 2078

Ubuntu22.04下ROS2与PX4仿真环境搭建全流程解析

本文详细解析了在Ubuntu22.04系统下搭建ROS2与PX4仿真环境的全流程,包括系统准备、ROS2 Humble安装、PX4飞控环境部署、ROS2与PX4通信桥梁搭建等关键步骤。针对常见问题提供了解决方案,并分享了性能优化和开发调试技巧,帮助开发者快速构建无人机仿真开发环境。

weixin_29248653的博客 609

zoj 1204 Additive equations

ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题。所以我很是天真的就以为要用集合做,结果发现网上都是用数组简单明了地实现了,显得我的代码,特么地超级恶心!!!!!!! 在这里存档一下,别人就不要看了,ZOJ的格式也真是恶心。。。居然因为这个也弄了好久...

weixin_30245867的博客 154

高通SA8155P车载Camera开发避坑指南:从硬件拓扑到AIS服务调试全流程

本文详细解析了高通SA8155P车载Camera开发全流程,从硬件拓扑设计到AIS(Automotive Imaging System)服务调试,涵盖关键组件配置、软件架构剖析及高级调试技巧。通过实战经验分享,帮助开发者避开常见陷阱,优化系统性能,适用于智能驾驶系统的环境感知开发。

weixin_42550597的博客 332

GEE:连续变化检测 CCDC 提取断点信息(干扰时间、干扰幅度、干扰次数)

本文将介绍在 Google Earth Engine (GEE) 平台上连续变化检测与分类(Continuous Change Detection and Classification, CCDC)提取扰动时间、干扰幅度、干扰次数信息,并下载到本地的代码。

养乐多的博客 1946

【zoj1204】Additive equations 一天一个入门算法

做不明白算法,记录一下每天写算法的心得,先从把答案看懂开始吧,哎 We all understand that an integer set is a collection of distinct integers. Now the question is: given an integer set, can you find all its addtive equations? To explain what an additive equation is, let’s look at the follo

weixin_53472121的博客 798

GMSL转eDP芯片MAX9686X(ADI)

MAX96860/MAX96862/MAX96864解串器可以把单路或双路GMSL转换成eDP V1.4a,支持820MHzPCLK的无压缩的24bpp(每个像素的位数)视频,或660MHz的30bpp视频。芯片的GMSL支持NRZ编码的6Gbps/187Mbps的GMSL2,PAM4编码的12Gbps/187Mbps的GMSL3。同时支持单线(COAX模式)双向全双工传输控制数据和video数据。支持DSC压缩的芯片,最大支持像素时钟1080MHz@24bpp或者864MHz@30bpp,传输方式包括同轴

qflook的博客 2853

ZOJ1204 Additive equations,DFS+set+仿函数+剪枝

这题有点挑战,首先是输出是按字典序的,这里我是用了set嵌套set实现去重复,以及利用仿函数实现按字典序排序。其次是如果对数据处理不好就会出现TLE,所以先对输入数据按照从大到小排序,然后确定循环的上下界来实现剪枝。150ms,贡献了4个TLE,泪奔。。。不过仿函数以及STL容器

Neo Fung的专栏 1544

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

ZOJ 1204 Additive equations

题目地址:点击打开链接 思路:先排序,再依次输出式子短的 AC代码: #include #include using namespace std; int pos[31]; int a[31]; int flag,num,n; void print(int sum) { int i; for(i=pos[num-1]+1; i<n; i++) {

Java识堂,一个有干货的微信公众号 1475

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

zoj 1204 Additive equations dfs

11047: Additive equations 时间限制:1 Sec内存限制:128 MB 提交:60解决:26 [提交] [状态] [讨论版] [命题人:admin] 题目描述 We all understand that an integer set is a collection of distinct integers. Now the question is: ...

喵喵喵 305

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

ZOJ 1204 Additive equations

A - Additive equations Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 1204 Description     We all understand that an integer set

CSU_ACM Solution Library 510

ZOJ 1204Additive equations

很久一起折腾过这道题。印象中折腾了很久,但是一直弄不出来。现在有了经验,顺利做出来了,感觉非常棒,自己终于有了提升。 Search Problems,用Dfs解。由于没有考虑数字排序的问题错了几次。   //ZOJ 1204Additive equations #inclu

zillion217的专栏 704

zoj 1204 Additive equations

2. 使用flag标记是否存在Additive equations,如果flag = -1,表示不存在。2. cnt个数相加,起始位置是1,从1到m-2,如果(起始位置+cnt>m)表示这个数处理完毕。3. dfs(起始位置,已经相加的数的个数,最大需要相加个数,和)。1. 从2个数相加开始,到3个数相加,逐个递增,最多m-1个数相加。2. 使用哈希表,判断相加结果是否存在。1. 排序 sort()函数。1. 使用栈path记录。4. dfs处理过程。

JJPa8and23的博客 146

ZOJ1204 Additive equations

紧接着,如果剩余需要寻找的加数个数不为0,那么来一个循环,因为最后一个数是最大的,一定不参与左边等式的构成,所以循环的范围为前一个加数的后一位置到m-num的前一个位置(这种情况即剩余的加数都挤在数组最后一个元素前面)。对于输入数据,应当存起来,因此开一个intSet数组存放一组的输入数据,为方便后续处理以及满足输出要求,对数组进行从小到大排序;对于Search函数,由于数组从小到大排序,查找的末位置默认为数组的最后一个元素位置,因此只需传入查找的初位置以及需查找的数字(即和值)即可。

Olyvia_111的博客 162

ZOJ1204-Additive equations

#include<stdio.h> #include<iostream> #include<algorithm> using namespace std; int m; int num; int a[35]; int pos[31]; bool exist; void print(int sum) { for(int i=pos[num-1]+1; i&l...

zjutsunny的博客 157

zoj - 1204 - Additive equations

先分层,然后进行深度优先遍历。 #include #include using namespace std; const int maxn = 30 + 10; //每组数据最多有30个数 int n, ok, C[maxn], a[maxn]; //n为每组数据的个数,ok标记是否有等式存在,C用来存路径,a为输入的数组 bool search(int

无节操 1925
上一篇: 逃离迷宫(HDU-1728)
下一篇: Rescue(HDU-1242)
绿蚁.r
博客等级 码龄10年 4粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值