PAT 1125

news/2024/10/21 3:35:50/

第二题很多人都说是赫夫曼树,我就排了个序就过了,之后推敲了一下这个逻辑是可行的,当然赫夫曼树也是正解,有兴趣的同学可以用赫夫曼树做一下

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;int main(){int n, i;double s[10005], len = 0;scanf("%d", &n);for (i = 0; i < n; i++) {scanf("%lf", &s[i]);}sort(s, s + n);len = s[0];for (i = 1; i < n; i++) {len = len / 2 + s[i] / 2;}int l = (int)(len);if (l <= len) {printf("%d\n", l);}else {printf("%d\n", l - 1);}return 0;
}



http://www.ppmy.cn/news/373629.html

相关文章

P1125 [NOIP2008 提高组] 笨小猴

P1125 [NOIP2008 提高组] 笨小猴 题目描述 笨小猴的词汇量很小&#xff0c;所以每次做英语选择题的时候都很头疼。但是他找到了一种方法&#xff0c;经试验证明&#xff0c;用这种方法去选择选项的时候选对的几率非常大&#xff01; 这种方法的具体描述如下&#xff1a;假设…

PAT甲级 1125

PAT甲级 1125 题目 Chain the Ropes解析代码 题目 Chain the Ropes Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain them into one piece, as shown by the figure. The resulti…

P1125

数组/桶的思想&#xff1a;笨小猴 要求 1.计算一个单词中每个字母出现的次数&#xff0c;并找出出现的次数与出现最小的次数 方案 1.利用桶的思想 桶算法模板 用处&#xff1a;记录数组或字符串中每个值出现的次数 场景&#xff1a;字符串&#xff0c;数组&#xff0c;字…

1125 Chain the Ropes

题目 题意&#xff1a;将两段绳子对折连接在一起可获得的最大长度 #include<iostream> #include<algorithm> using namespace std; int main() {int n;cin>>n;int s[n];for(int i0; i<n; i)cin>>s[i];sort(s,sn);int anss[0];for(int i1; i<n;…

洛谷P1125 笨小猴 题解

洛谷 P1125 [NOIP2008 提高组] 笨小猴 题解 题目描述 笨小猴的词汇量很小&#xff0c;所以每次做英语选择题的时候都很头疼。但是他找到了一种方法&#xff0c;经试验证明&#xff0c;用这种方法去选择选项的时候选对的几率非常大&#xff01; 这种方法的具体描述如下&#xf…

信息学奥赛一本通:1125:矩阵乘法

1125&#xff1a;矩阵乘法 时间限制: 1000 ms 内存限制: 65536 KB 提交数: 34833 通过数: 18995 【题目描述】 计算两个矩阵的乘法。nm阶的矩阵A乘以mk阶的矩阵B得到的矩阵C 是nk阶的&#xff0c;且C[i][j] A[i][0]B[0][j] A[i][1]B[1][j] …… A[i][m-1]B[m-…

HLK-LD1125H-24G人体测距微波雷达

** HLK-LD1125H-24G人体测距微波雷达 ** 概述 转载官方概述&#xff1a; HLK-LD1125H-24G 是一款高灵敏度 24GHz 毫米波人体存在检测雷达模块。区别于传统雷达通过检测人体移动的大幅度动作或者微小幅度的肢体动作来判断人体存在&#xff0c;本模块主要特点是通过检测积累人…

poj 1125

题目简答&#xff0c;考floyd算法。代码如下&#xff1a; #include<iostream> #include<iomanip> #include<cstdlib> #include<string.h> #define INTMAX 10000 using namespace std;int visit[101]; int path[101][101]; int cons[101][101]; int n;v…