A. Amr and Music
解题思路:给出n种乐器学习所需要的时间,以及总共的天数, 问最多能够学多少门乐器,并且输出这几门乐器在原序列中的序号(不唯一)
按照升序排序,为了学到最多的乐器,肯定要选择花费时间最少的来学习 然后用结构体来储存该门乐器在原序列中的序号。
1 second
256 megabytes
standard input
standard output
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively.
The second line contains n integers ai (1 ≤ ai ≤ 100), representing number of days required to learn the i-th instrument.
In the first line output one integer m representing the maximum number of instruments Amr can learn.
In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
4 10 4 3 1 2
4 1 2 3 4
5 6 4 3 1 1 2
3 1 3 4
1 3 4
0
In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument.
/*287 div2 A*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node
{
int first;
int second;
} a[105];
bool cmp(Node n1,Node n2){
return n1.first<n2.first;
} int main()
{
int n,k,i,j,sum=0;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i].first);
a[i].second=i;
}
sort(a+1,a+n+1,cmp);
for(i=1;i<=n;i++)
{
if(sum+a[i].first<=k)
sum=sum+a[i].first;
else
break;
}
printf("%d\n",i-1);
for(j=1;j<i;j++)
printf("%d ",a[j].second);
}
A. Amr and Music的更多相关文章
- ffmpeg常用转换命令,支持WAV转AMR
音频转换: 1.转换amr到mp3: ffmpeg -i shenhuxi.amr amr2mp3.mp3 2.转换amr到wav: ffmpeg -acodec libamr_nb -i shenh ...
- 微信录音接口的调用以及amr文件转码MP3文件的实现
最近实现录音功能,主要涉及到录音的上传和下载,以及转码问题.微信,QQ默认的的音频文件是amr格式的,而播放器却不识别amr格式的音频,必须尽行转码.amr文件分为两种,一种是通用的amr格式,这种文 ...
- AMR 转mp3 失败
private void changeToMp3(String sourcePath) { File source = new File(sourcePath); String mp3TargetPa ...
- Web 播放声音(AMR 、WAVE)
最近甚是苦闷,属于边学边做,跳进了很多坑,别提有多惨了,不过结果还是不错滴,纵观前后,一句话足以概括 “痛并快乐着” ~~~ ok,我少说废话,下面来总结下 Web 播放声音一些注意事项. 说到 We ...
- Web 播放声音 — AMR(Audio) 篇
本文主要介绍 AMR(Aduio) 播放 AMR 格式 Base64码 音频. 1.必备资料 github AMR 开源库 :https://github.com/jpemartins/amr.js用 ...
- Web 播放声音 — Flash 篇 (播放 AMR、WAV)
本文主要介绍 Flash 播放 AMR 格式 Base64码 音频. 在此之前么有接触过 Flash ,接触 AS3 是一头雾水,不过幸好有 TypeScript 和 JavaScript 的基础看起 ...
- ffmpeg centos6.5上安装(测试 amr 转换为 mp3)
1. 下载相关源码包 wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz wget http://sourcefo ...
- web页面如何播放amr的音频文件
这个需求由来已久,公司的语音订单很多,每次客服都是从服务器down下语音来听.很不方便..于是我就上网扒拉看有么有什么web播放器能播放amr格式的音频文件,amr百度百科 总之找了很久.,,然后发现 ...
- amr转MP3
using System; using System.Threading; using System.IO; using System.Diagnostics; using System.Securi ...
- 手机浏览器,微信中播放amr录音
由于微信公众号开发中,临时素材只有三天的有效期,但是客户要求所有录音永久保存,永久素材数量又有限制,故只能把录音保存到服务器上.但是存到服务器上有一个问题,手机微信中无法直接播放amr录音.无意中发现 ...
随机推荐
- UWP 开发APP准备工作
每新建一个UWP之后,都要进行一番相同的处理步骤,才能使Mobile的使用体验更好,故总结如下: 1.订阅Mobile后退导航事件 在App.xaml.cs文件中OnLaunched方法中添加 Sys ...
- MySQL · 答疑解惑 · 备库Seconds_Behind_Master计算
背景 在mysql主备环境下,主备同步过程如下,主库更新产生binlog, 备库io线程拉取主库binlog生成relay log.备库sql线程执行relay log从而保持和主库同步. 理论上主库 ...
- Maven配置,使用IntelliJ IDEA和Maven创建Java Web项目
1. 下载Maven 官方地址:http://maven.apache.org/download.cgi 解压并新建一个本地仓库文件夹 2.配置本地仓库路径 3.配置maven环境变量 4 ...
- 多年js学习累计总结
http://www.codesec.net/list/6/ 大神http://www.cnblogs.com/tylerdonet/p/5543813.html
- python字符串、列表、元组
字符串的常用方法: name.count('h')统计h在name中出现的次数 name.find('h')查找h的索引 '?'.join(name)使用问好拼接 name.encode('gb231 ...
- vue封装http请求
import axios from 'axios' import isObject from 'lodash/isObject' const http = function (api, data = ...
- HDU 1047 Integer Inquiry( 高精度加法水 )
链接:传送门 思路:高精度水题 /************************************************************************* > File ...
- mac上用VMWare虚拟机装Linux-Ubuntu
1.下载vmware fusion for Mac 网上有很多,大家自己找吧 2.安装Vmware 3.序列号可以在网上找,或者淘宝几块钱买一个(记得买对应版本的) 4.之后就下一步,完成就好 安装U ...
- 自备LocalDateTime工具类
package cn.zytao.taosir.common.utils; import java.time.Instant; import java.time.LocalDate; import j ...
- 原生JS中 callback,promise,generator,async-await 的简介
callback,promise,generator,async-await 的简介 javascript异步的发展历程. ES6 以前: 回调函数(callback):nodejs express ...