Sumsets POJ - 2549 (从 一个 1000数中,找出四个数,满足 a + b = d -c,且求的d最大)

实测对比:纳芯微NSD1624在光伏逆变器中的性能表现(含温度测试数据) 本文详细评测了纳芯微NSD1624非隔离驱动芯片在光伏逆变器中的性能表现,包括动态效率、高温稳定性及抗干扰能力。实测数据显示,该芯片在800V母线电压下效率峰值达99.03%,高温环境下结温稳定在102.7℃,且传播延迟一致性优异。与竞品相比,NSD1624在总损耗和热阻方面具有显著优势,是光伏逆变器驱动方案的理想选择。 阅读详情

Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S.
Input
Several S, each consisting of a line containing an integer 1 <= n <= 1000 indicating the number of elements in S, followed by the elements of S, one per line. Each element of S is a distinct integer between -536870912 and +536870911 inclusive. The last line of input contains 0.
Output
For each S, a single line containing d, or a single line containing "no solution".
Sample Input
5
2 
3 
5 
7 
12
5
2 
16 
64 
256 
1024
0
Sample Output
12
no solution

题意:从给出的一段序列中挑取 4个数,a,b,c,d使得a+b = d - c,使得d最大;

思路: n为小于1000的数,取出4个数要是 按一般的取法,一定超时,所以你要想想如何利用二分求解;

若 a + b = d - c;

那么 a + c = d - b;

        b +c = d - a;

所以我们先对序列排序,从大到小枚举 d,而 我们把c 看做 a,b,c 中最大的数, 枚举 d - c 的每一种可能性(为什么要每一种呢,因为a,b,c,d中可能有负数,也就是为什么 代码中那个内层循环中为什么 j = n-1,而不是j = i-1了,要全是正数的话,j = i-1,但是有负数,例:-1.-2,7,10;d 最大为7,而 c = 10) 在利用二分求法求a + b = d - c;

代码:

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Max 1010
int n;
int a[Max];
int main()
{
	int i,j;
	while(~scanf("%d",&n)&&n)
	{
		for(i = 0; i < n ; i ++)
			scanf("%d",&a[i]);
		sort(a,a+n);
		int flag =0;
		int res;
		for(i = n-1;i>=0;i--)
		{
			for(j = n -1 ;j>=0;j--)  // 
			{
				if(i==j) continue;
				int sum = a[i]- a[j];
				int l = 0,r = j-1;
				while(l<r)
				{
					int tt = a[l] + a[r];
					if(tt==sum)
					{
						flag = 1;
						res = i;
						break;
					}
					if(tt>sum)
						r--;
					else l++;
				}
				if(flag) break;
			}
			if(flag) break;
		}
		if(flag) printf("%d\n",a[res]);
		else printf("no solution\n");
	}
	return 0;
} 

30天入门 SAP BTP 开发系列之二:了解 SAP BTP Region 的概念,包含账号申请的详细步骤 SAP BTP 的 Region,实际是一组按地理位置划分的、由 SAP 或合作 Hyperscaler 承载的基础设施栈。这些基础设施栈至少包含多可用区网络、对象存储、计算节点及自动化运维等服务。 阅读详情

相关推荐

癌症免疫治疗预测神器TIDE:从原理到实战(避坑指南)

本文详细解析了癌症免疫治疗预测工具TIDE的核心原理及实战应用。TIDE算法通过模拟肿瘤免疫逃逸的两种核心机制(T细胞功能障碍和排除),为临床决策提供精准预测。文章涵盖数据准备、标准化流程、网页工具操作指南及结果解读,帮助科研人员和临床医生避开常见误区,优化免疫治疗策略。

weixin_29309475的博客 207

面试五十题

copy的july的题目 该文章链接:http://blog.csdn.net/v_july_v/article/details/7974418 1. 谈谈你对面向对象编程的认识 面向对象的几大特征:封装、继承、多态,扯扯这些玩意 2. 8月20日,金山面试,题目如下:  数据库1中存放着a类数据,数据库2中存放着以天为单位划分的表30张(比如table_20110909,table_2

alexingcool的专栏 7787

用deepseek对GPU服务器进行压力测试

利用 DeepSeek 模型对 GPU 服务器进行压力测试,核心思路是通过,验证 GPU 服务器在计算、显存、网络等维度的承载能力,同时观察稳定性与性能瓶颈。

weixin_42795092的博客 1619

NOI 3.5 哈希 1551: Sumsets

题目来源:http://noi.openjudge.cn/ch0305/1551/1551: Sumsets总时间限制: 1000ms    内存限制: 65536kB描述Given S, a set of integers, find the largest d such that a + b +c = d where a, b, c, and d are distinct elements o...

da_kao_la的博客 716

Deepseek+Word插件:一键搞定论文翻译与润色的学术写作新革命

本文介绍了Deepseek Word插件如何革新学术写作流程,实现论文翻译与润色的一键操作。该插件深度集成于Word环境,能智能完成中英互译、语法修正、术语统一及逻辑优化,显著提升写作效率与文本质量,是研究者的高效AI助手。

weixin_29252171的博客 540

音频降采样系数

如果需要把8K, 16K, 32K, 48K采样率的音频数据降为4K的音频数据, 最简单的方法根据降频倍数来取点, 但是线性度不好. 另一种线性度好一点的方法是: 取适当个数的点数, 各点乘以各自点的系数, 然后相加取平均值. 降频倍数与系数的关系如下: 2倍:     {0.3, 0.4, 0.3} 4倍:    {0.15, 0.2, 0.3, 0.2, 0.15} 8倍:   {0

joans123的专栏 4653

2.5英文题面翻译

描述 Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. 输入 Several S, each consisting of a line containing an integer 1 <= n <= 1000 indicating the number of elements in S, follo

qq_64149314的博客 6323

从Verilog到GDS:手把手教你搞定Calibre LVS物理验证(附常见报错解决)

本文详细介绍了从Verilog到GDS的Calibre LVS物理验证全流程,包括工具链配置、RTL到SPICE网表转换、LVS运行配置及高级技巧。重点解析了常见报错如网络不匹配、器件不匹配和电源引脚缺失的解决方案,帮助工程师高效完成芯片物理验证,确保设计正确性。

culing2941的博客 515

UVA10125 POJ2549 Sumsets【暴力+二分】

Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each consisting of a line containing an integer 1 ≤ n ≤ 1000 indicating the number of elements in S, followed by the el

海岛Blog 556

Open3D 计算点云的主曲率【2027最新版】

本文介绍了点云主曲率计算的方法与实现。通过分析曲面局部几何形状的主曲率(最大和最小方向),基于法线构建投影矩阵和协方差矩阵,使用奇异值分解计算曲率。代码采用Open3D实现,包括点云加载、法线估计、邻域搜索和曲率映射可视化功能。系统支持交互式点云文件选择,将曲率值映射为色彩进行直观展示,为点云处理中的特征提取和分割任务提供基础几何特征。实现过程包含了法线去中心化、协方差矩阵构建和特征值归一化等关键步骤,完整展示了从理论到实践的曲率分析流程。

点云侠的博客 549

手把手教你学Simulink--基于车联网与智能交通系统的场景实例:基于车联网(V2X)的实时路况信息共享与处理

《基于Simulink的车联网(V2X)实时路况共享系统仿真》摘要:本文详细介绍使用Simulink构建V2X智能交通系统的完整方法。系统包含交通路网建模、V2X通信实现(支持DSRC/C-V2X标准)、多源路况信息融合、动态路径规划等核心模块。通过对比实验,验证V2X可使平均车速提升52%,行程时间缩短34%,显著提升交通效率。文章还探讨了AI预测调度、车辆编队等高级应用,为智慧交通系统开发提供实用参考。所需工具包括Simulink、SimEvents及无线通信工具箱等。

MHD0815的博客 743

Sumsets POJ - 2229(完全背包,划分DP)

Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7: 1+1+1+1+1+1+1 1+1+1+1+1+2 1+1+1+2+2 1+1+1+4 1

tomjobs的博客 457

点云结构面智能识别与裂隙网络分析系统

点云结构面智能识别系统摘要 本系统采用深度学习与传统几何算法融合的方法,实现岩石结构面的智能识别与分析。系统包含7个核心模块:点云预处理、结构面识别、分组分割、参数计算、粗糙度分析、裂隙网络生成和可视化。技术路线结合PointNet++深度学习架构与RANSAC、区域生长等传统算法,通过预处理→深度学习识别→几何精修→参数计算→网络构建的流程实现高精度分析。预处理模块实现点云降噪、下采样和法向量估计,深度学习模块基于改进的PointNet++架构进行特征提取和分类。系统支持多种点云格式输入,提供完整的结构面

huanghm88的专栏 361

【POJ 2549】Sumsets

2373: 【POJ 2549】Sumsets 题目描述 给出一个整数集合s,找到集合中最大的d,让等式a+b+c=d成立, 其中,a,b,c,d是集合S中不同的元素。 http://noi.openjudge.cn/ch0305/1551/ 输入 有多组数据,每组数据第一行为n(1<=n<=1000),表示S中有n个数据,接下来n行,每行一个整数(-536870912~+53687...

砥安的博客 527

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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

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

POJ 2549---Sumsets(二分枚举)

传送门:http://poj.org/problem?id=2549 Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each consisting of a line containing an integer 1 <= n <= 1000 ind

wardel的博客 455

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 2549 Sumsets

Sumsets Time Limit: 1000MS Memory Limit: 65536K Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, e...

忘梦心的博客 305

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Poj 2549 Sumsets【巧妙枚举】

Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10072   Accepted: 2752 Description Given S, a set of integers, find the largest d such that a + b +

希望的专栏 1002

POJ2549_Sumsets_

Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11294   Accepted: 3101 Description Given S, a set of integers, find the largest d such that a + b +

弱的奋斗之旅 434

poj2549 Sumsets

Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10533   Accepted: 2863 Description Given S, a set of integers, find the largest d such that a + b +

樱花满地集于我心,楪舞纷飞祈愿相随 542

POJ - 2549 Sumsets(折半枚举)

Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10573   Accepted: 2882 Description Given S, a set of integers, find the largest d such that a + b + c

qq_18661257的专栏 782

POJ 2549 Sumsets hash

G - Sumsets Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu SubmitStatus Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c,

Katapeltes 660

POJ -2549 Sumsets(二分,枚举)

Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13364 Accepted: 3668 Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are di...

名字太长容易被发现并打死 406

Sumsets POJ - 2549(折半搜索 哈希表)

Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each consisting of a line containing an integer 1 <= n <=...

tomjobs的博客 576

POJ 2549 Sumsets 折半枚举+二分搜索

我们有1000个数字组成的集合,从中找出所有满足 a + b + c = d 的所有情况(a b c d 是集合中下标不同的四个元素),输出最大的d即可。

qq_53038151的博客 231

POJ - 2549 Sumsets(折半枚举 + 二分)

题目大意:给出一个数字n, 接下来有n个整数 从n个数中找出四个数a、b、c、d使得 a + b + c = d。求出d最大可能是几。 数据范围 n <= 1000 强行枚举的话,一共有1000^4种方式。这是必不可行的。 我们利用折半枚举的思想, a + b = d - c #include <cstdio> #include <cstring> #inc...

辞树 338

poj 2549 Sumsets

N - Sumsets Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2549 Description Given S, a set of integers, find the largest d

wust_ZJX的专栏 790
上一篇: 1071: zdw的嘤嘤嘤(找一字符串的长度,非严格单调递增,(可以用找 非严格单调递增的 dp,写)(也可用找字符串的dp写,这种挺重要))
下一篇: 0和5 51Nod - 1433 (为什么整除找出一个最大的整数能整除3或者9,为什么)
obsorb_knowledge
博客等级 码龄9年 38粉丝 213原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址