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. tmp note

    cat file.txt > /dev/null 2>&1 丢弃错误和标准输出 systemctl isolate multi-user.target 切换回多用户命令行模式 sy ...

  2. windows定时执行python脚本

    from:http://blog.csdn.net/Gpwner/article/details/77882131

  3. JS动态添加元素的事件动态绑定

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. 使用Auto Layout中的VFL(Visual format language)——代码实现自动布局

    本文将通过简单的UI来说明如何用VFL来实现自动布局.在自动布局的时候避免不了使用代码来加以优化以及根据内容来实现不同的UI. 一:api介绍 1.NSLayoutConstraint API NSL ...

  5. Intel CPU参数查询网站

    链接:https://ark.intel.com/#@Processors

  6. Java多线程的同步方式和锁机制

    Object.wait(miliSec)/notify()/notifyAll() 线程调用wait()之后可以由notify()唤醒,如果指定了miliSec的话也可超时后自动唤醒.wait方法的调 ...

  7. 9. InnoDB通用表空间

    9. InnoDB通用表空间 通用表空间是InnoDB 使用CREATE TABLESPACE语法创建的共享表空间.本节中的以下主题描述了常规表空间功能和功能: 通用表空间功能 创建通用表空间 将表添 ...

  8. docker的网络(基础)

    Docker的网络子系统是可插拔的,使用驱动程序.默认情况下存在多个驱动程序,并提供核心网络功能: bridge:docker默认的网络驱动.如果未指定驱动程序,则这是需要创建的网络类型.当应用程序在 ...

  9. CSS--基础块级元素与内联元素

    在CSS中,html中的标签元素大体被分为三种不同的类型:块状元素.内联元素(又叫行内元素)和内联块状元素.在HTML和XHTML中,块级元素不能继承自行内元素(即不能嵌套在行内元素),<p&g ...

  10. tornado框架基础09-cookie和session

    01 cookie 在上节,我们简单了解了登录过程,但是很明显,每次都需要登录,但是在平常逛网站的只需要登录一次,那么网站是如何记录登录信息的呢? 有没有什么办法可以让浏览器记住登录信息,下次再次打开 ...