POJ - 2785 4 Values whose Sum is 0

STM32 HAL库定时器中断里读编码器速度准吗?聊聊MG310电机的测速与防溢出处理 本文探讨了STM32 HAL库在定时器中断中读取编码器速度的精度问题,特别针对MG310电机的测速与防溢出处理提供了解决方案。通过对比定时中断法和编码器模式的性能,揭示了硬件编码器接口在降低误差和CPU占用率方面的优势,并详细介绍了CubeMX配置技巧和防溢出处理的工程实践。 阅读详情
The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a + b + c + d = 0 . In the following, we assume that all lists have the same size n .
Input
The first line of the input file contains the size of the lists n (this value can be as large as 4000). We then have n lines containing four integer values (with absolute value as large as 2 28 ) that belong respectively to A, B, C and D .
Output
For each input file, your program has to write the number quadruplets whose sum is zero.
Sample Input
6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45
Sample Output
5
Hint
Sample Explanation: Indeed, the sum of the five following quadruplets is zero: (-45, -27, 42, 30), (26, 30, -10, -46), (-32, 22, 56, -46),(-32, 30, -75, 77), (-32, -54, 56, 30).



思路:枚举所有的话是4000^4,数据太大,肯定要拆分,然后二分查找;分别分成letf[]  和  right[]两个数组;

代码如下:
#include <stdio.h>
#include <algorithm>
using namespace std;
int left[16000005] , right[16000005];
struct node{
	int a, b, c, d;
}s[4005];
int main() {
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n; i++) {
		scanf("%d %d %d %d",&s[i].a, &s[i].b, &s[i].c, &s[i].d);
	}
	int t = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			left[t] = s[i].a + s[j].b;
			right[t] = s[i].c + s[j].d;
			t++;
		}
	}
	int sum = 0;
	sort(left , left + t);
	for(int i = 0; i < t; i++) {
		sum += upper_bound(left,left+t,-right[i])-lower_bound(left,left+t,-right[i]);
	}
	printf("%d\n",sum);
	return 0;
}

upper_bound(a , a+n , m)返回第一个大于m的位置;
lower_bound(a , a+n , m)返回第一个大于等于m的位置;
以上两者类似于二分找到答案;
jetson agx orin开箱及接口介绍 阅读详情

相关推荐

VsCode+JLink+GCC替代Keil开发GD32程序-个人总结

对个人使用vscode+Jlink开发GD32程序做了总结,供需要者参考。

MyCollege1999的博客 2762

UVA 1152 --4 Values whose Sum is 0(枚举--中途相遇法)

4 Values whose Sum is 0 Time Limit:9000MS Memory Limit:0KB 64bit IO Format:%lld & %llu The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how m

持之以恒 550

DIY等离子环:从Class-E电路到七彩辉光,手把手教你打造炫酷科学玩具

本文手把手教你DIY一个炫酷的等离子环科学玩具。从解析等离子体辉光放电原理入手,详细介绍了核心的Class-E自激振荡电路设计、关键元件选型与参数计算,并提供了从物料准备、电路搭建、腔体密封到上电调试的全流程指南。通过调制电路或填充不同气体,还能实现七彩变换与交互效果,是学习高频电路与电磁场知识的绝佳实践项目。

weixin_29305337的博客 633

E - 4 Values whose Sum is 0

Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a + b + c + d = 0 . In

geekword的专栏 498

10行代码搞定QMT实盘交易:手把手教你用Python自动化买卖股票(附完整源代码)

本文提供了一份详尽的QMT实盘交易教程,手把手教你使用Python构建自动化交易系统。内容涵盖环境配置、账户连接、查询与下单等核心代码,并附有完整的源代码示例,帮助开发者快速掌握从零到实盘的完整流程,实现安全可靠的股票自动化买卖。

weixin_29214335的博客 437

NVIDIA DGX Spark (Ubuntu 24.04) 部署Isaac Sim与Isaac Lab:二进制安装与ROS2集成实战

本文详细介绍了在NVIDIA DGX Spark工作站(Ubuntu 24.04系统)上,通过预编译二进制包稳定部署Isaac Sim与Isaac Lab的完整实战流程。文章重点剖析了二进制安装相较于源码编译和pip安装的优势,有效规避了CUDA、PyTorch等关键组件的版本冲突陷阱,并逐步指导完成环境配置、Isaac Lab集成、Conda环境管理以及ROS2 Jazzy的集成,最终构建出完整的机器人仿真与强化学习开发平台。

kite3的博客 396

POJ2785——4 Values whose Sum is 0

题目链接:http://poj.org/problem?id=2785 4 Values whose Sum is 0 题目大意:给你n行4列数,让你在每一列中取一个数,然后相加,问有多少种组合(相加之和为0)? 解题思路:虽然给了15秒,但是直接暴力还是会超时的。接下来讲讲我的做法:首先将前两列任意两项相加得到数组x,再将后两列任意两项相加取反得到数组y,再将y排序,最后依次将x中的元

piaocoder 557

iTunes登录协议逆向与自动化实现

本文详细解析了iTunes登录协议的逆向工程与自动化实现方法,涵盖请求体构造、签名生成和会话管理等关键技术。通过XML结构解析、X-Apple-ActionSignature生成原理及完整登录流程实现,帮助开发者高效完成iTunes自动化登录,提升工作效率。

weixin_26938645的博客 938

poj sum

# include int main(){ int i,j; int n; int sum,s; while(~scanf("%d",n)){ sum=0; for(i=1;;i++){ sum+=i; if(sum>=n&&(sum-n)%2==0) break; } printf("%d\n",i); } return

klfc183的专栏 445

卷积码Viterbi译码算法原理及C语言实现

具体而言,卷积码的编码过程是将输入数据和编码器中的状态进行异或操作,输出码字为各个状态对应的结果。Viterbi译码算法是一种最大似然译码算法,根据接收到的含有噪声的码字,寻找出最有可能的原始数据序列。(2) 递推计算:根据接收到的码字和当前状态,计算下一时刻各个状态的路径度量,并记录每个状态的前驱状态。以上代码实现了一个简单的卷积码Viterbi译码算法,通过接收到的码字进行译码,并输出解码结果。(1) 初始化:将所有状态的路径度量初始化为一个很大的值,选择路径度量最小的状态作为起始状态。

2301_79331421的博客 825

6、Cocos2D游戏开发:精灵添加与角色实现

本文详细介绍了在Cocos2D游戏开发中如何添加背景精灵和玩家角色精灵。通过创建GameScene场景、组织项目资源、使用多分辨率图像适配不同设备,并深入讲解了将角色拆分为上下半身以实现更真实瞄准效果的原理。文章还解析了Cocos2D的图像搜索机制、锚点概念及其应用,以及如何通过父子节点关系管理复合角色。最终实现了猎人角色在场景中的正确显示与定位,为后续动画和交互功能打下基础。

e3f4g5的博客 90

4 Values whose Sum is 0(二分法)

4 Values whose Sum is 0(二分法)

Ema1997的博客 944

解锁RK1126与SC132GS摄像头适配密码:技术与代码全解析

本文详细介绍了瑞芯微RK1126芯片与SC132GS摄像头的适配方法。首先分析了RK1126的四核Cortex-A7处理器、Mali-T860 GPU等硬件特性,以及SC132GS的130万像素、全局快门等技术参数。重点阐述了基于MIPI CSI接口的硬件连接原理和基于V4L2框架的软件驱动设计,并提供了完整的初始化、数据采集和图像处理代码实现。针对常见连接和图像质量问题给出了解决方案,展现了该组合在智能安防、工业检测等领域的应用潜力,为开发者提供了实用的技术参考。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 1498

POJ 2785 4 Values whose Sum is 0

题目: POJ 2785 4 Values whose Sum is 0 ,哈哈,我们今天来看一道稍微简单的二分题嘛,这是选自POJ上的一道题,好了,我们一起来看看题意吧: 考虑到直接复制题目,或者截屏的方式不是很方便阅读,我就把直接题目链接放下面! 题目传送门: POJ 2785 4 Values whose Sum is 0 思路: 这道题你要是写个4重循环那可就太惨了,其实可以是2重循环的,我们计算前两列的分别两两相加的和,用b数组装,然后计算后两列的分别两两相加的和,用c数组装,我们只需要计算

小知识吖 5887

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ-2785 4 Values whose Sum is 0

二分查找POJ-2785 4 Values whose Sum is 0 POJ-2785 题目大意:输入四列数 代表集合a,b,c,d 问ai+bi+ci+di相加等于0的组合有多少种 解题思路:将ab集合每种组合对应的和储存 cd也是一样 然后查找cd集合中是否有ab集合元素的复数 ab集合和cd集合的大小最大可达4000*4000 直接遍历查找会超时 所以用二分查找法(注意在二分查找的时候 ...

鱼头的水题之路 570

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

POJ2785:4 Values whose Sum is 0(二分)

Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x C x D are such that a + b + c + d = 0 .

ACM!荣耀之路! 5093

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

poj 2785 4 Values whose Sum is 0 (二分+枚举)

题目链接:http://poj.org/problem?id=2785 题目大意:  给出四个长度为n的列表(从上到下)                     从每个列表分别取出一个数据,使得相加的结果为0                     问最多存在多少种情况? 解题思路:  n的范围(1                     可以转化为O(2*n^2):

ンZee的解题报告 1156

POJ 2785:4 Values whose Sum is 0

http://poj.org/problem?id=2785 这道题目意思很简单,但是数据量很庞大,就需要设计比较好的算法。 方法一:利用二分搜索算法。根据题意,我们将数据分为左右两个部分,然后将左侧的两列之和加起来,然后排序,在对右侧的两列加起来,二分搜索相应的解的上下限。这里需要注意对一个数出现的上下界的寻找办法,代码要注意,也可以通过STL中的lower_bound与upperbound

BootStar 699

POJ2785 4 Values whose Sum is 0 【枚举】

4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 16000   Accepted: 4625 Case Time Limit: 5000MS Description The SUM problem can

长风的专栏 977

poj 2785 4 Values whose Sum is 0

4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 14474   Accepted: 4137 Case Time Limit: 5000MS Description The SUM problem can

liu_fanyi3的专栏 637

【POJ 2785 --- 4 Values whose Sum is 0 】二分枚举

【POJ 2785 --- 4 Values whose Sum is 0 】二分枚举 Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d ) ∈ A x B x...

来日浅谈的博客 571

POJ 2785:4 Values whose Sum is 0

4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 19331   Accepted: 5783 Case Time Limit: 5000MS Description The SUM problem c

枫闲言的博客 443
上一篇: codeforces 9C Hexadecimal's Numbers
下一篇: 模拟:Fraction HDU - 5912
追逐星辰的光
博客等级 码龄10年 12粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值