HDU 5135 Little Zu Chongzhi's Triangles

Isaac Sim 6 利用Replicator实现高效语义分割与实例分割(实践指南5.10) 本文详细介绍了如何利用Isaac Sim 6的Replicator工具高效生成语义分割和实例分割数据集。通过虚拟环境自动标注,效率提升20倍以上,特别适用于农业机器人等计算机视觉项目。文章包含环境配置、场景构建、批量标注技巧及实例分割处理等实战指南,帮助开发者快速掌握合成数据生成技术。 阅读详情

Little Zu Chongzhi's Triangles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 470    Accepted Submission(s): 248


Problem Description
Zu Chongzhi (429–500) was a prominent Chinese mathematician and astronomer during the Liu Song and Southern Qi Dynasties. Zu calculated the value ofπ to the precision of six decimal places and for a thousand years thereafter no subsequent mathematician computed a value this precise. Zu calculated one year as 365.24281481 days, which is very close to 365.24219878 days as we know today. He also worked on deducing the formula for the volume of a sphere.

It is said in some legend story books that when Zu was a little boy, he liked mathematical games. One day, his father gave him some wood sticks as toys. Zu Chongzhi found a interesting problem using them. He wanted to make some triangles by those sticks, and he wanted the total area of all triangles he made to be as large as possible. The rules were :

1) A triangle could only consist of 3 sticks.
2) A triangle's vertexes must be end points of sticks. A triangle's vertex couldn't be in the middle of a stick.
3) Zu didn't have to use all sticks.

Unfortunately, Zu didn't solve that problem because it was an algorithm problem rather than a mathematical problem. You can't solve that problem without a computer if there are too many sticks. So please bring your computer and go back to Zu's time to help him so that maybe you can change the history.
 

Input
There are no more than 10 test cases. For each case:

The first line is an integer N(3 <= N<= 12), indicating the number of sticks Zu Chongzhi had got. The second line contains N integers, meaning the length of N sticks. The length of a stick is no more than 100. The input ends with N = 0.
 

Output
For each test case, output the maximum total area of triangles Zu could make. Round the result to 2 digits after decimal point. If Zu couldn't make any triangle, print 0.00 .
 

Sample Input
3 1 1 20 7 3 4 5 3 4 5 90 0
 

Sample Output
0.00 13.64


题目大意:提供一些木棍,每三根首尾相连用来组成一个三角形(长度符合条件),求各个三角形总面积最大是多少。


解题思路:贪心,木棍长度从大到小排序,不能组成三角形的木棍舍去,用海伦公式求出组成的三角形的面积。


代码如下:

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
double a[13];
double area(double a,double b,double c)  //海伦公式,已知三角形三边边长求面积
{
    double p=(a+b+c)/2.0;
    return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main()
{
    int n,i;
    double ans;
    while(scanf("%d" ,&n)!=EOF&&n)
    {
        ans=0.0;
        for(i=0;i<n;i++)
            scanf("%lf",&a[i]);
        sort(a,a+n);     //排序
        for(i=n-1;i>=2;i--)  //按边长递减顺序,保证的满足条件的每个三角形边长最大
        {
            if(a[i]<a[i-1]+a[i-2])   //只用判断最长边是否小于另外两边之和
			{
                ans+=area(a[i],a[i-2],a[i-1]);  
				i-=2;
			}
        }                            //若不满足条件,该最长边直接舍去
        printf("%.2f\n",ans );
    }
    return 0;
}


FIFO的工作原理及其设计 FIFO( First Input First Output)简单说就是指先进先出。FIFO存储器是一个先入先出的双口缓冲器,即第一个进入其内的数据第一个被移出,其中一个口是存储器的输入口,另一个口是存储器的输出口。对于单片FIFO来说,主要有两种结构:触发导向结构和零导向传输结构。触发导向传输结构的FIFO是由寄存器阵列构成的,零导向传输结构的FIFO是由具有读和写地址指针的双口RAM构成。FIFO与普通RAM存储器的是没有外部读写地址线(指针),使用方便,但。 阅读详情

相关推荐

SPAD 单光子雪崩二极管

SPAD,全称为,是一种高灵敏度的光电探测器件,能够在非常低的光照水平下检测单个光子。SPAD在工作时,当一个光子被探测器吸收后,能够触发一个雪崩效应,产生一个可以被检测到的电信号。

qq_42786033的博客 1万+

HDU 5135 Little Zu Chongzhi's Triangles(贪心)

题目大意: 给一些线段的长度,要求将他们组合成一些三角形,使得总面积最大。 解题思路: 根据海伦公式,可以贪心解。即变长越大,三角形面积越大。 所以,将所有边排序后,从大到小,如果最大的三条边可以组成三角形,则采用这种组合; 若无法组成三角形,即第二大和第三大的边之和不大于第一大的边(因已经排序,其他限制不用考虑),则丢弃第一大的边,因为之后的边任意组合也不可能与最大边组成三角形。

wujy的专栏 1385

Unity Shader变体优化实战:从内存削减到打包加速

本文深入探讨了Unity项目中Shader变体数量爆炸导致的打包缓慢、内存占用过高及包体臃肿等问题。核心解决方案是通过精准的Shader变体裁剪,即收集项目实际用到的变体形成“白名单”,并利用IPreprocessShaders接口在打包时剔除无用变体。实战表明,该方法能显著提升打包速度并大幅降低运行时内存。

weixin_29300241的博客 217

HDU 5135 Little Zu Chongzhi's Triangles

//状态压缩: #include #include #include #include #include #include using namespace std; const int maxn = (1<<13) - 1; int n; double dp[maxn]; int res[13]; vectorv; double area(int

MrFox 517

美亚杯取证比赛必备:Veracrypt挂载+检材解压保姆级教程(附常见错误排查)

本文提供美亚杯数字取证竞赛的Veracrypt挂载与检材解压保姆级教程。详细解析从分卷压缩包解压(密码格式为MeiyaCup+年份)到使用Veracrypt正确挂载加密容器的全流程,并附有常见错误排查与高级应急方案,帮助选手高效突破技术门槛,顺利进入取证分析阶段。

alice7model的博客 1028

Hive数据仓库分层架构实战:4层黄金模型×6大业务场景×万亿级数据优化方案

根据《2023数据中台成熟度报告》,‌78%的ETL任务性能瓶颈‌源于分层设计不合理。本文基于某头部电商平台PB级数据仓库建设经验,结合金融风控、用户画像、实时大屏等核心场景,深度解析‌ODS→DWD→DWS→ADS‌四层架构设计原则,揭秘‌万亿级数据治理方案‌与‌维度建模20大避坑策略‌。

优快云博客专家,领域包括但不限于:AI、大数据、Python、架构师,有合作、课程、问题、疑惑请私信博主 1480

hdu5135 Little Zu Chongzhi's Triangles(DP)

该题其实是个DP,可能数据比较水,队友排序后从大的开始取都过了。。  我们来说说正解,一开始其实我已经写出来了,只是有一个地方导致了一直在输出一个不是数字的值,赛后才发现是我用memset对一个double类型的数组清-1的原因   ,改了一下就对了 。    直接开一维数组,用二进制表示集合的方法来表示哪些木棍被选取了 。 很简单的状态压缩DP 。 我用的记忆化搜索,该题还可以用三重循环地推

AC_Arthur的专栏 983

Material Studio中分子动力学模拟得到密度density和溶解度参数

使用sketh工具画出全原子分子,以异辛烷为例子。

handsome213的博客 7315

HDU5135-Little Zu Chongzhi's Triangles【状压DP】

Little Zu Chongzhi's Triangles Problem Description Zu Chongzhi (429–500) was a prominent Chinese mathematician and astronomer during the Liu Song and Southern Qi Dynasties. Z...

独钓门前月 492

Google Cameraserver 看门狗CameraServiceWatchdog超时crash原理分析

本文分析了Android CameraServiceWatchdog机制的工作原理。该看门狗用于监控相机服务关键操作(如close、flush)的超时情况,通过定时器线程检测阻塞问题。文章详细讲解了Watchdog的初始化流程、使能方式、内部定时器机制(默认周期100ms,650次循环触发超时),并提供了configureStreams阶段的客制化实现方案。当检测到超时,Watchdog会触发abort生成tombstone日志,便于调试分析。

1128

SAP-ABAP:SAP库存管理核心增强:IF_EX_MB_DOCUMENT_BADI 深度解析

SAP库存管理核心增强:IF_EX_MB_DOCUMENT_BADI 深度解析

baidu_35680696的博客 1446

HDU 5135 Little Zu Chongzhi's Triangles(数学题)

Little Zu Chongzhi's Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 1613    Accepted Submission(s): 889 Problem Descrip

In my way 468

【小白CV教程】YOLOv5+Deepsort实现车辆行人的检测、追踪和计数

【小白CV教程】YOLOv5+Deepsort实现车辆行人的检测、追踪和计数本文禁止转载!项目简介:YOLOv5检测器:DeepSort追踪器:运行demo:训练自己的模型:调用接口:创建检测器:调用检测接口: 本文禁止转载! 项目简介: 使用YOLOv5+Deepsort实现车辆行人追踪和计数,代码封装成一个Detector类,更容易嵌入到自己的项目中。 代码地址(欢迎star): https://github.com/Sharpiless/Yolov5-deepsort-inference 最终效果:

梁瑛平的博客 5万+

HDU 5135 Little Zu Chongzhi's Triangles 状压

原题见HDU 5135给n(n<13)条边,每条边只能用一次,拼成多个三角形,求三角形面积和的最大值。分析1~2122^{12}只有4096,对每个数二进制分解,第i位为1则用aia_i这条边。 预处理出所有的数位和为3的倍数的边。 d[i] i的二进制数位和 f[i] 用了i的二进制所表示的边后,可以组成的三角形面积的最大值。 如果d[i] = d[j]+3且i|j <= i(避免0被1与

Ugly Gardon 730

深度学习工具包 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")

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

hdu5135 Little Zu Chongzhi's Triangles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 1165    Accepted Submission(s): 655 Problem Description Zu Chongzhi (429–500) was

新月 1031

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

hdu5135 Little Zu Chongzhi's Triangles 状压dp

前几天突然得知要去打一站区域赛,时间紧迫,只能拿前几年区域赛的真题来练习了。 此题是2014年广州站第二水题,开始看错了题意,以为两个三角形可以有公共边,后来看了题解发现是两个三角形不可以有公共边 状压dp,数据范围小,直接用1 AC代码 #include #include #include #include #include #include #include #inclu

always_here 472

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

hdu5135Little Zu Chongzhi's Triangles dfs

#include #include #include #include #include using namespace std ; const int maxn = 20 ; double a[maxn] ; double b[maxn] ; int vis[maxn] ; int n ; double get_sum() { double sum = 0 ; for(int i

ijbuhv的专栏 322

HDU_5135 Little Zu Chongzhi's Triangles[爆搜]

传送门:HDU_5135 题意:给你n个木棒,拼出任意个三角形,要求面积和最大,输出max(s); Sample Input 3 1 1 20 7 3 4 5 3 4 5 90 0   Sample Output 0.00 13.64 思路:暴力搜索 代码: #include #include #include #include #includ

code_or_code 870

hdu 5135 Little Zu Chongzhi's Triangles 贪心

Little Zu Chongzhi's Triangles Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 512000/512000K (Java/Other) Total Submission(s) : 3   Accepted Submission(s) : 3 Problem Description Zu Chong

hpugym的专栏 603

hdu 5135 Little Zu Chongzhi's Triangles(分组dp)

题意:给n条边,要求用其中的某些边组成三角形,每条边只能用一次,问最后拼成的三角形面积总和最大是多少. 解析:开始的时候理解错题目要求了,无脑暴力了一段.之后想到dp,因为要把一堆东西分成一组一组,求每一种分法中的最优,所以就姑且叫他分组dp吧.(...) 首先将边按从小到大排序,保证每一个可拼的三角形的状态都能访问到. 接着将n条边分组,n条边最多可以拼出n / 3组三角形

渐近自由 542

HDU 5135 Little Zu Chongzhi's Triangles(状压dp或者贪心)

题目大意:给你n个线段让你任意组成三角形,求组出来的三角形的面积的和最大为多少。 解题思路:首先你得知道海伦公式:S = sqrt(p*(p-a)*(p-b)*(p-c)), p = (a+b+c)/2。 思路一:贪心,按照边的长度进行排序,从大到小判断如果可以构成三角形,就让他构成三角形,这样组成的三角形的面积和一定是最大的。 思路二:状压dp,先暴力求出来所有可以组成的三角形对应的状态和

I am a slow walker, but I never walk backwards! 1610

HDU5135 I - Little Zu Chongzhi's Triangles 状压DP

首先开头膜一发ZB大爷,14广州竟然俩一血,另个一血太难,可能是模拟?反正之后在补吧。 状压DP,网上说贪心也对,但是按照ZB大爷手速,十一分钟写一个不快。 上代码1A 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include &lt...

bandi8620的博客 144

hdu 5135 Little Zu Chongzhi's Triangles(贪心)

hdu 5135 Little Zu Chongzhi's Triangles(贪心) —— black 的专栏 —— waShaXiu

black的专栏 1052
上一篇: poj 2945 Find the Clones
下一篇: HDU 5131 Song Jiang's rank list
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值