SGU - 186 - The Chain (贪心)
186. The Chain
memory limit per test: 4096 KB
output: standard output
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
Output
Sample test(s)
Input
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 (贪心)的更多相关文章
- SGU 186.The Chain
看懂题就是水题... code #include <iostream> #include <algorithm> using namespace std; int a[110] ...
- SGU 186
总是拆最短的链子 连接长的链子 贪心.... #include <cstdio> #include <cstring> #include <cmath> #i ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 今日SGU 5.26
#include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...
- SGU 171 Sarov zones (贪心)
题目 SGU 171 相当好的贪心的题目!!!!! 题目意思就是说有K个赛区招收参赛队员,每个地区招收N[i]个,然后每个地区都有一个Q值,而N[i]的和就是N,表示总有N个参赛队员,每个队员都有 ...
- SGU 280.Trade centers(贪心)
SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solu ...
- sgu 195 New Year Bonus Grant【简单贪心】
链接: http://acm.sgu.ru/problem.php?contest=0&problem=195 http://acm.hust.edu.cn/vjudge/contest/vi ...
- codeforce447 D SGU 548 贪心+优先队列
codeforce447 D - DZY Loves Modification 题意:有一个n*m的矩阵,每次可以选择一行或者一列,可以得到这行或这列的所有元素sum的积分,然后使这一列/行的每一个元 ...
- SGU 296.Sasha vs. Kate(贪心)
题意: 给出长度为n(<=1000)的一个数.输出删掉k个数字后的最大值. Solution: 简单贪心. s[i]代表数字s的第i位. 从前往后第一个满足s[i]>s[i-1]的位置,最 ...
随机推荐
- _vimrc配置
set nocompatible set encoding=utf8 set guioptions-=T set number set guifont=consolas:h12 source $VIM ...
- 5.1 qbxt 一测 T2
求和[问题描述] 组合数 C(n,m)是从 n 个物品中取 m 个的方案数. C(n,m)=(n!)/(m!(n-m)!) 斐波那契数列 F 满足,F[0]=F[1]=1,n≥2 时 F[n]=F[n ...
- cmd启动MySQL服务器发生错误
Mysql net start mysql启动,提示发生系统错误 5 拒绝访问 原文:https://blog.csdn.net/angel_guoo/article/details/7919037 ...
- ssh服务使用介绍二
老司机开车了 快上车 上文提到当我们使用ssh远程链接主机的时候,会出现询问的提示,如果我们链接的机器多了,一遍一遍的输入是不是很麻烦?怎么解决如下 vim /etc/ssh/ssh_config 如 ...
- Spring Boot Web开发中Thymeleaf模板引擎的使用
这里使用的是idea 1.新建Spring Boot项目 File-->New-->Project...,然后选择左边的Spring Initializr-->Next,可根据自己的 ...
- 【HTML/XML 3】XML 简介,来源
导读:在标记语言出现之前,计算机中的数据一直都是以神秘的二进制在进行处理,但是,标记语言的出现,慢慢的改变了这种认识.那么,标记语言都经过了什么样的发展呢?它又有什么用处呢? 一.追根溯源(XML的产 ...
- 搜狗大数据总监、Polarr 联合创始人关于深度学习的分享交流 | 架构师小组交流会
架构师小组交流会是由国内知名公司技术专家参与的技术交流会,每期选择一个时下最热门的技术话题进行实践经验分享.第一期:来自沪江.滴滴.蘑菇街.扇贝架构师的 Docker 实践分享 第二期:来自滴滴.微博 ...
- POJ 1379 (随机算法)模拟退火
题目大意: 给定一堆点,找到一个点的位置使这个点到所有点中的最小距离最大 这里数据范围很小,精度要求也不高,我们这里可以利用模拟退火的方法,随机找到下一个点,如果下一个点比当前点优秀就更新当前点 参考 ...
- FZU 1686 dlx重复覆盖
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- Linux(1):基本配置
linux里面的网络(网卡)配置: 1. 输出 setup 命令进行设置 2. 选择 "Network configuration" ,按 回车键 3. 选择 "Devi ...