博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SGU - 186 - The Chain (贪心)
阅读量:6973 次
发布时间:2019-06-27

本文共 1548 字,大约阅读时间需要 5 分钟。

186. The Chain

time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output



Smith has N chains. Each chain is the sequence of successively connected links. The length of each chain is known: the first chain contains L1 links, the second - L2, ..., the last one - LN. 
He can make a following series of actions in a minute: 
1. to unchain one link 
2. to remove or to put into the unchained link some other links of any chain 
3. to chain the link 
Your task is to determine the minimum time which will take the smith to connect all the chains in one line, i.e. the chain will look like a chain made up of successively connected links.
Input
The first line contains natural number N<=100. The second line contains L1, L2, ..., LN (1<=Li<=100, for all i = 1..N).
Output
Output the only integer number - the solution to the problem.
Sample test(s)
Input
 
2 3 4
Output
 
1

Author: Michael R. Mirzayanov
Resource: ACM International Collegiate Programming Contest 2003-2004 
North-Eastern European Region, Southern Subregion
Date: 2003 October, 9






思路:好无耻的英语。说的这么拐弯抹角真的好吗?题意应该是这种。先从一个chain上拆下一个link。然后能够连接两个chain,仅仅到全部chain都连起来为止,这里算一分钟。所以先从短链開始拆更省时,贪心....

AC代码:

#include 
#include
#include
using namespace std;int a[105];int main() { int n; while(scanf("%d", &n) != EOF) { for(int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a+n); int i = 0, j = n-1, ans = 0; while(i < j) { a[i]--; j--; if(a[i] == 0) i++; ans++; } printf("%d\n", ans); } return 0;}

转载地址:http://ptesl.baihongyu.com/

你可能感兴趣的文章
GridView动态添加新行
查看>>
使用Kazoo去增删改查zookeeper
查看>>
C# 实现系统关机、注销、重启、休眠、挂起
查看>>
SQL server 2000常用字符串长度总结
查看>>
征服Perl——哈希——里程碑M7
查看>>
遇到女神应该使用什么样的暗恋思维
查看>>
HA(heartbeat)主备模式实现lvs群集的高可用性
查看>>
mtr路由监控
查看>>
容器编排 Docker Compose
查看>>
KVM 使用virtio驱动Windows server 虚拟机
查看>>
我的Oracle 9i学习日志(15)-- 表的管理
查看>>
mysql5.7更改密码
查看>>
adb无线网络调试
查看>>
Nginx+Keepalived搭建高可用负载均衡集群
查看>>
防火墙示例-用简单规则集保护网络
查看>>
记一次开发过程中的思维转换
查看>>
8. Accordion模拟菜单,Accordion动态绑定数据,模拟菜单点击
查看>>
基于Spring源码分析AOP的实现机制
查看>>
Windows Server 2016 Hyper-v Nested Virtualization
查看>>
30种图像动画特效算法(C#多线程版)(中)
查看>>