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录音.无意中发现 ...
随机推荐
- IE,表头固定
<html> <head> <title>表头固定</title> <style type="text/css"& ...
- iOS系统结构
应用交互层.多媒体层.核心服务层.系统层. 参考官方文档apple Develop GuidesiOS Technologies IOS分为四级结构,由上到下为可触摸层,媒体层,核心服务层,核心系统层 ...
- css——定位
position absolute:绝对定位 1.以页面的左上角为原点 2.不保留原来的位置 3.z-index可以调整图层顺序 如果想实现以父级元素左上角为原点.则:父级相对,子级绝对 在子级绝对的 ...
- UVALive-8079 Making a Team 排列组合公式化简
题目链接:https://cn.vjudge.net/problem/UVALive-8079 题意 n个人组队,队伍人数小于等于n,每个队伍需要4个不同的职务的领导. 问这n个人可以组成多少队? n ...
- Flask入门系列(转载)
一.入门系列: Flask入门系列(一)–Hello World 项目开发中,经常要写一些小系统来辅助,比如监控系统,配置系统等等.用传统的Java写,太笨重了,连PHP都嫌麻烦.一直在寻找一个轻量级 ...
- shell试题
1.按单词出现频率降序排序! 2.按字母出现频率降序排序! The months of learning in Old Boy education are the few months that I ...
- Python-基础-day5
1.内置函数 2.文件操作 操作文件时,一般需要经历如下步骤: 打开文件 操作文件 一.打开文件 文件句柄 = file('文件路径', '模式') 注:python中打开文件有两种方式,即:open ...
- 新手学python-Day3-模块
模块就是引入别人写的,官方写的工具库,就像扳手,钳子,电锯
- SM32 USART与USB接收不定数据方法,标准库、HAL库都适用
很多时候,我们使用串口或USB接收数据时,往往不知道PC端会发多长的数据下来, 为了解决这个不定数据接收问题,在此各提供一个解决思路. 串口数据不定接收: 由于STM32单片机带IDLE中断,所以利用 ...
- JS 一个简单的隔行变色函数
//输入要隔行变色的标签名 function setbgColor(tr){ var tr = document.getElementsByTagName("tr"); for(v ...