SGU 186.The Chain

看懂题就是水题。。。

code

#include <iostream>
#include <algorithm>
using namespace std;
int a[110], n, l, r, ans;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	r = n - 1;
	sort (a, a + n);
	while (l < r) {
		a[l]--, r--;
		if (!a[l]) l++;
		ans++;
	}
	cout << ans;
	return 0;
}

  

时间: 2024-08-05 06:39:28

SGU 186.The Chain的相关文章

SGU 178.Chain

Solution: 一开始做的时候,以为可以将一条长度为n的链分成和n为的任意长度的3部分.结果第二组就Wa了 后来参考了题解,发现是将长度为n的链分成长度为1,x,n-1-x的三条链.再看看题目,不知道是不是自己理解的问题,觉得题目并没有明确说明这一点,仅凭一个n=5,拆成1,1,3 的例子没有体会到这个o(╯□╰)o 不管怎么样,题意是长度为n的链分成长度为1,x,n-1-x的三条链的话,也是很简单的 假设分了k次,那么就会有k个1,和k+1个长度不等的链,k个1,可以组成1~k k个数,那

hdu 3487 Play with Chain

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3487 YaoYao is fond of playing his chains. He has a chain containing n diamonds on it. Diamonds are numbered from 1 to n.At first, the diamonds on the chain is a sequence: 1, 2, 3, …, n.He will perform t

hdu3487Play with Chain(splay)

链接 简单的两种操作,一种删除某段区间,加在第I个点的后面,另一个是翻转区间.都是splay的简单操作. 悲剧一:pushdown时候忘记让lz=0 悲剧二:删除区间,加在某点之后的时候忘记修改其父亲节点. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vec

【HDU3487】【splay分裂合并】Play with Chain

Problem Description YaoYao is fond of playing his chains. He has a chain containing n diamonds on it. Diamonds are numbered from 1 to n.At first, the diamonds on the chain is a sequence: 1, 2, 3, …, n.He will perform two types of operations:CUT a b c

iOS Responder Chain 响应者链

一.事件分类 对于IOS设备用户来说,他们操作设备的方式主要有三种:触摸屏幕.晃动设备.通过遥控设施控制设备.对应的事件类型有以下三种: 1.触屏事件(Touch Event) 2.运动事件(Motion Event) 3.远端控制事件(Remote-Control Event) 今天以触屏事件(Touch Event)为例,来说明在Cocoa Touch框架中,事件的处理流程.首先不得不先介绍响应者链这个概念: 二.响应者链(Responder Chain) 先来说说响应者对象(Respond

设计模式之Chain of Responsibility(职责链)(转)

Chain of Responsibility定义 Chain of Responsibility(CoR) 是用一系列类(classes)试图处理一个请求request,这些类之间是一个松散的耦合,唯一共同点是在他们之间传递request. 也就是说,来了一个请求,A类先处理,如果没有处理,就传递到B类处理,如果没有处理,就传递到C类处理,就这样象一个链条(chain)一样传递下去. 如何使用? 虽然这一段是如何使用CoR,但是也是演示什么是CoR. 有一个Handler接口: public

hdu 5293 Tree chain problem(树链剖分+树形dp)

题目链接:hdu 5293 Tree chain problem 维护dp[u], sum[u],dp[u]表示以u为根节点的子树的最优值.sum[u]表示以u节点的所有子节点的dp[v]之和.对于边a,b,w,在LCA(a,b)节点的时候进行考虑.dp[u] = min{dp[u], Sum(a,b) - Dp(a,b) + sum[u] | (ab链上的点,不包括u } #pragma comment(linker, "/STACK:1024000000,1024000000")

HDU 3980 Paint Chain(博弈 SG)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3980 Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one p

- Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead. 解决方案

<template> <div>{{hello}}</div> <button @click="addOne">add one</button> <button @click="minusOne">minus one</button> </template> 在*.vue组件里有这么一段. 报错信息: (Emitted value instead of an instan