CF581C:Developing Skills解题报告
来源:互联网 发布:汉邦网络摄像机默认ip 编辑:程序博客网 时间:2024/06/13 23:53
原题是这样的,The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.
Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.题意不难。。。大致思路是把数组中的数拿出个位部分然后降序排序(然后就涉及到排序、、= =#),把这些数都加到10。如果数组还没有遍历一遍而数字k已经加完了,那这是结果直接输出就行。如果数组遍历一遍之后k还有多,那就去掉个位剩下的几十随意分配到这些数上就行。另外有一个限制是每个数不能超过100,所以有一个限制条件n*10,当n个数全部能加到100时,最后结果能达到最大的n*10,所以在前面无需考虑这一条限制。
PS.刚开始用快排提了几次都是超时,但是实在想不到怎么提高排序的效率,猛然想到STL,改完果然一遍就AC了。。。= =#贴出代码:
#include <iostream>#include <algorithm>#include <stdio.h>using namespace std;int main(){ int n,m,i,p[100010],sum; while(scanf("%d%d",&n,&m)!=EOF){ sum=0; for(i=0;i<n;i++){ scanf("%d,",&p[i]); sum+=p[i]/10; p[i]=p[i]%10; }//将输入的数先进行处理,只取个位存入数组 sort(&p[0],&p[n]);//忘记怎么降序排序了,这样凑合着用吧 for(i=n-1;i>=0;i--){ if((p[i]+m)>=10){//尽可能多地把数组中小于10的数都加到10 sum++; m-=(10-p[i]); }else{//如果一遍没有遍历玩m已经加完了就可以直接break了 break; } } if(m>=10){//遍历一遍m不为0就能把十位部分随意分配 sum+=m/10; } if(sum>=(n*10)){//总的一个限制,使每个数保证不会超过100 sum=n*10; } printf("%d\n",sum); } return 0;}
- CF581C:Developing Skills解题报告
- 解题报告 之 CodeForces 581C Developing Skills
- Developing Skills
- Developing Skills
- Codeforces 581C Developing Skills
- Developing Skills(优先队列)
- codeforces 581C Developing Skills
- cf 591 C. Developing Skills
- CF 581C Developing Skills
- coderforce 581C. Developing Skills
- codeforces 581C Developing Skills
- CodeForces 581C Developing Skills
- Codeforces-581C-Developing Skills
- Codeforces 581C Developing Skills 贪心
- codefoces 581C Developing Skills(贪心)
- Codeforces Round #322 C Developing Skills
- CodeForces 581C - Developing Skills(模拟)
- codeforces 581-C. Developing Skills(贪心)
- QT5 学习之路03---开发环境搭建
- LeetCode 题解(250) : Closest Binary Search Tree Value II
- 学习笔记 - 用FileReader读取文本文件并打印出来
- kmeans聚类的实现
- JAVA验证字符串长度(包括汉字)
- CF581C:Developing Skills解题报告
- Java处理双引号
- 学习笔记 - java FileWriter对文本文件的写入
- 样式浅谈2
- hibernate开发几个提示!
- Google C++ Style Guide的哲学
- QT5 学习之路04---QT5基本对话框1
- CF#310-E - Case of Chocolate-(set+贪心)/(线段树+离散化)/(隐式线段树)
- 循环和递归的异同