总体思路

这道题就是一道贪心题。
对我来说,这道题的关键在于他在说什么(黑人问号???),一开始读了几遍都不知道在讲什么,怎么一根绳子对折后就和另一根套上了?
描述上面确实让人比较迷糊,配图也不是很明了。本来配图我感觉可以做的比较好明白一点,就是一根绳子对折,然后,中间部分卷起来,剩下两头留出两个套子。

灵魂画手上线营业!

做法呢就是上面这个理,既然理解到这一步,接下来的事情就很清楚了。 

每次挑绳子时候,先挑短的。
Get it!

避坑指南 notice

1.中间那些存储、计算过程使用的是double类型
2.最后输出要输出整形类型,要类型转换一下
3.如果只有一段绳子,那就不要对折

show you my code

#include<stdio.h>
#include<algorithm>
using namespace std; double rope[]; int main(){
int n;
scanf("%d",&n);
for(int i=;i<n;++i)
scanf("%lf",&rope[i]);
sort(rope,rope+n); double length = rope[];
for(int i=;i<n;++i){
length=length/+rope[i]/;
}
printf("%d",int(length));
return ;
}

PAT1125的更多相关文章

  1. PAT1125:Chain the Ropes

    1125. Chain the Ropes (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

随机推荐

  1. [LeetCode] 316. Remove Duplicate Letters 移除重复字母

    Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...

  2. [LeetCode] 639. Decode Ways II 解码方法 II

    A message containing letters from A-Z is being encoded to numbers using the following mapping way: ' ...

  3. string 与 int double 的转化

    #include <iostream> #include <string> #include <sstream> using namespace std; int ...

  4. 17 JQuery高级----学习笔记

    1. 动画(1) 三种方式显示和隐藏元素 <1> 默认显示和隐藏方式 1. show([speed,[easing],[fn]]) 1. 参数: 1. speed:动画的速度.三个预定义的 ...

  5. Windows 下删除 Docker 容器的方法

    Issue: 删除命令执行失败 如果在 CMD 命令提示符下删除容器可能失败,可切换至 PowerShell 中执行成功. unknown shorthand flag: 'a' in -a See ...

  6. liunx 定时任务执行java程序配置流程

    java jar包使用build fat jar进行打包 ------------------liunx任务创建--------------------------- 1.查看现有任务计划: cron ...

  7. Spring Boot取消默认tomcat启动,打成war包发布到服务器运行

    一.设置打包方式 在pom.xml中设置打包格式 <packaging>war</packaging> 二.取消Spring Boot的tomcat <!--部署成war ...

  8. CRT远程连接centos7,连接超时

    CRT远程连接centos7,连接超时 问题原因: 宿主机(win10)和虚拟机(centos7)不在同一个网段 在宿主机无法ping通虚拟机, 首先在cmd窗口ipconfig查看一下vmnet的i ...

  9. python学习-70 自定制format

    # 自定义format dic_date = { 'ymd':'{0.year}:{0.month}:{0.day}', 'dmy':'{0.day}-{0.month}-{0.year}' } cl ...

  10. centos7简单部署rancher

    rancher官网文档地址 https://www.cnrancher.com/docs/rancher/v2.x/cn/overview/ 准备机器 两台虚拟机 192.168.56.100 192 ...