Making a String

原创 2016年08月29日 14:51:49
链接:http://codeforces.com/problemset/problem/624/B

题目:

You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:

  • the i-th letter occurs in the string no more than ai times;
  • the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.

题意:给最多26个字母的出现次序,要求出现次数不同,且每个字母出现的次数不超过所给的次数的最大总数。

分析:贪心,先排个序,从最大的开始考虑,如果相同依次递减。

题解:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;

int n;
int a[27];

int main()
{
	//freopen("in.txt","r",stdin);
	//while(true){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	__int64 sum=a[n];
	for(int i=n-1;i>0;i--){
		if(a[i]>=a[i+1]&&a[i+1]!=0)
			a[i]=a[i+1]-1;
		if(a[i+1]==0)
			a[i]=0;
		sum+=(__int64)a[i];
	}
	cout<<sum<<endl;//}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

codeforces624B Making a String 贪心 排序

B. Making a String time limit per test 1 second memory limit per test 256 megabytes ...

AIM Tech Round (Div. 2)-B. Making a String(贪心)

B. Making a String time limit per test 1 second memory limit per test 256 megabytes ...

做市商策略(Market Making Strategy)

高频交易策略中最主要的一类策略就是Market Making,即通过赚取买卖价差来获取利润,该策略虽然应用于连续竞价机制,但由于与传统的做市商市场类似,所以命名为Market Making。目前有几篇...

Let us learn C in Code <8> decision making

Hi, everyone. Today is April 1. who maybe the April one at this funny day. This chapter we'll learn ...

iOS/iPhoneOS Equalizer with libsox - making it a .framework

iOS/iPhoneOS Equalizer with libsox - making it a .framework From:  http://uberblo.gs/2011/04/iosi...

ASSETWriterInput for making Video from UIImages on Iphone Issues

1)Adaptor class AVAssetWriterInputPixelBufferAdaptor * avAdaptor = [AVAssetWriterInputPixelBufferAd...

TOJ 2273 POJ 2818 Making Change DFS C语言

商店有面值为25分、10分、5分、1分的硬币,给出各硬币的数量和要找给顾客的钱数,问怎么使找给顾客的总的硬币数最少。 重温DFS,先是用了最暴力的方法,枚举所有的情况 #include in...

POJ 2818 : Making Change - dfs

(寒假马拉松第一场 P题)题意:商店有面值为25分、10分、5分、1分的硬币,给出各硬币的数量和要找给顾客的钱数,问怎么使找给顾客的总的硬币数最少。分析:DFS,最暴力的方法是枚举所有的情况;——PO...

用SPDY加速web —— ”Making The Web Faster With SPDY“

用SPDY加速web —— ”Making The Web Faster With SPDY“
  • xeseo
  • xeseo
  • 2013-11-22 18:35
  • 1263

Codeforces Round #379 (Div. 2) C. Anton and Making Potions(暴力+二分)

题目链接:http://codeforces.com/contest/734/problem/C【中文题意】让制作n个魔法瓶,普通制作一个魔法瓶花费x秒时间,现在有s魔法值。现在有两种方案可以选择,而...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)