Making a String
来源:互联网 发布:上海人工智能公司排名 编辑:程序博客网 时间:2024/05/18 01:54
链接:http://codeforces.com/problemset/problem/624/B
题目:
题意:给最多26个字母的出现次序,要求出现次数不同,且每个字母出现的次数不超过所给的次数的最大总数。
分析:贪心,先排个序,从最大的开始考虑,如果相同依次递减。
题解:
题目:
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 thanai 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;}
0 0
- CF624B - Making a String
- B. Making a String
- Making a String
- B. Making a String【水题】
- Codeforces 624B Making a String 【水题】
- codeforces624B Making a String 贪心 排序
- B - Making a String-----CodeForces 624B
- CodeForces 624B Making a String
- CodeForces 624B - Making a String
- AIM Tech Round (Div. 2)--B. Making a String
- Codeforces AIM Tech Round (Div. 2) B. Making a String
- cf#AIM Tech Round -B. Making a String-贪心/set
- CodeForces 624 B. Making a String(贪心)
- CodeForces 624B Making a String(贪心)
- Making a Kite
- Making a Plugin System
- Making a Standard Request
- Making a LoRa Gateway
- Android从上往下滑动或从下往上滑动结束Activity
- Media Data之多媒体数据库(二)MediaProvider
- 关于天嵌2440提供的jflash工程不能连接开发板的问题
- 多级目录makefile例子
- 求本月的第一个周一
- Making a String
- Bmob 后端云服务平台
- insert into 语句的三种写法
- java短信接口
- HDU1536->SG函数
- 工作流Activiti的学习总结(六)Antiviti的安装详细过程
- 第三方控件PullToRefresh使用过程
- [SCOI2005]超级格雷码
- C#学习日记-接口于类