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 <cstdio>
#include <cstring>
#include <algorithm>
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;
}

SGU - 186 - The Chain (贪心)的更多相关文章

  1. SGU 186.The Chain

    看懂题就是水题... code #include <iostream> #include <algorithm> using namespace std; int a[110] ...

  2. SGU 186

    总是拆最短的链子  连接长的链子   贪心.... #include <cstdio> #include <cstring> #include <cmath> #i ...

  3. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  4. 今日SGU 5.26

    #include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...

  5. SGU 171 Sarov zones (贪心)

    题目   SGU 171 相当好的贪心的题目!!!!! 题目意思就是说有K个赛区招收参赛队员,每个地区招收N[i]个,然后每个地区都有一个Q值,而N[i]的和就是N,表示总有N个参赛队员,每个队员都有 ...

  6. SGU 280.Trade centers(贪心)

    SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solu ...

  7. sgu 195 New Year Bonus Grant【简单贪心】

    链接: http://acm.sgu.ru/problem.php?contest=0&problem=195 http://acm.hust.edu.cn/vjudge/contest/vi ...

  8. codeforce447 D SGU 548 贪心+优先队列

    codeforce447 D - DZY Loves Modification 题意:有一个n*m的矩阵,每次可以选择一行或者一列,可以得到这行或这列的所有元素sum的积分,然后使这一列/行的每一个元 ...

  9. SGU 296.Sasha vs. Kate(贪心)

    题意: 给出长度为n(<=1000)的一个数.输出删掉k个数字后的最大值. Solution: 简单贪心. s[i]代表数字s的第i位. 从前往后第一个满足s[i]>s[i-1]的位置,最 ...

随机推荐

  1. vmware linux虚拟机与本地物理机共享文件夹

    cd /mnt/hgfs 使用Vmware安装了linux虚拟机后,开发时,为了方便文件的传输等,因此需要使用共享文件夹,减少工作量.共享文件夹需要用到vmware提供的vmware tools工具, ...

  2. noip2019——动态规划刷题历程

    加粗的是值得总结的 从洛谷的普及题开始刷题: 背包式dp(有些技巧的) 1.p2639[USACO09OCT]Bessie的体重问题 -p1049取模意义下01背包 技巧:重量=价值 2.金明的预算问 ...

  3. MySQL 8.0.12 基于Windows 安装教程

    第一步:到MySQL官网下载安装包:https://dev.mysql.com/downloads/mysql/ 第二步:将下载好的安装包(mysql-8.0.12-winx64 .zip)解压到相应 ...

  4. OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档ID 1410.1)

    OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档I ...

  5. (1) openssl基础概念

    1.1 背景知识 对称加密     :加密解密使用同一密钥,加解密速度快.随着人数增多,密钥数量急增n(n-1)/2. 非对称加密 :使用公私钥配对加解密,速度慢.公钥是从私钥中提取出来的,一般拿对方 ...

  6. Mysql 参数优化

  7. 单点登录-CAS

    使用插件 phpCAS ,插件链接:https://github.com/apereo/phpCAS 1. CAS 单点登录流程及插件的API的简介 图片链接来源于wiki:https://wiki. ...

  8. 《C/C++工程师综合练习卷》

    前言 前天拿这个<C/C++工程师综合练习卷>练习了一下,现将错题以及精题分析总结. 错题分析与总结 2 . 下面的程序可以从1-.n中随机等概率的输出m个不重复的数.这里我们假设n远大于 ...

  9. 杭电 1856 More is better (并查集求最大集合)

    Description Mr Wang wants some boys to help him with a project. Because the project is rather comple ...

  10. Spring核心技术(十)——JSR-330标准注解

    从Spring 3.0开始,Spring开始支持JSR-330标准的注解(依赖注入).这些注解和Spring注解扫描的方式是一直的,开发者只需要在classpath中配置相关的jar包即可. 如果开发 ...