A. Amr and Music

解题思路:给出n种乐器学习所需要的时间,以及总共的天数, 问最多能够学多少门乐器,并且输出这几门乐器在原序列中的序号(不唯一)

按照升序排序,为了学到最多的乐器,肯定要选择花费时间最少的来学习 然后用结构体来储存该门乐器在原序列中的序号。

A. Amr and Music

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first line contains two numbers nk (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.

Output

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.

Sample test(s)

input

4 10 4 3 1 2

output

4 1 2 3 4

input

5 6 4 3 1 1 2

output

3 1 3 4

input

1 3 4

output

0

Note

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);
}

  

时间: 2024-12-11 17:38:54

A. Amr and Music的相关文章

部署ffmpeg及amr转mp3方法

简介:FFmpeg是一套可以用来记录.转换数字音频.视频,并能将其转化为流的开源计算机程序:更多介绍请自行百度 环境Centos6.7 编译器:gcc 安装步骤: 1步:安装依赖环境 yum install -y  yasm automake autoconf libtool gcc gcc-c++ 2步:下载源码包, cd  /usr/local/src wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.

java利用ffmpeg将amr、caf转mp3格式

最近再做一个项目,要将手机APP上的文件上传到服务器上来,包括图片.声音.视频文件.起初只有Android版,大家知道,Android的录音格式amr,在电脑上播放不出来,必须转码.因为之前只有Android版的,所以就用jave给方便的解决了.但是后来又增加了iPhone版,传上来的录音格式是caf.jave虽然支持几十种音视频格式,但是却支持不了这个caf格式.后来也尝试了lame,也是不行.网上的资料绝大部分是说在iPhone手机上转的,可是我要在服务器上转.搞了一个星期,没有一点进展.后

ffmpeg常用转换命令,支持WAV转AMR

音频转换: 1.转换amr到mp3: ffmpeg -i shenhuxi.amr amr2mp3.mp3 2.转换amr到wav: ffmpeg -acodec libamr_nb -i shenhuxi.amr amr2wav.wav 3.转换mp3到wav: ffmpeg -i DING.mp3 -f wav test.wav 4.转换wav到amr: ffmpeg -i test.wav -acodec libamr_nb -ab 12.2k -ar 8000 -ac 1 wav2amr

linux下使用ffmpeg将amr转成mp3

说明:AMR格式是智能手机上的常用音频文件格式,比MP3格式的压缩比大.同样时长的AMR文件大概是MP3的十分之一,所以在移动互联项目中应用比较广泛.但目前AMR格式在个人电脑上应用较少,所以目前大部门播放器都不支持AMR,为了解决这个问题我们打算在服务器端将AMR转成MP3,以便在个人电脑上通过浏览器的方式进行播放.最近公司一款基于移动互联网的产品有个短暂的录音(留言)功能,因为录音需要传输到服务器上,所以为了用户体验及节省用户流量,我们采用了AMR的语音格式. 目前并没有找到合适的支持AMR

Codeforces Round #312 (Div. 2) C.Amr and Chemistry

Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals

Codeforces Round #312 (Div. 2) B.Amr and The Large Array

Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some

Codeforces Round #312 (Div. 2)——C暴力技巧——Amr and Chemistry

Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemicals

Codeforces 558C Amr and Chemistry(数论+位运算)

C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n differ

AMR音频文件格式分析

1 概要 如今非常多智能手机都支持多媒体功能,特别是音频和视频播放功能,而AMR文件格式是手机端普遍支持的音频文件格式.AMR,全称是:Adaptive Multi-Rate,自适应多速率,是一种音频编码文件格式,专用于有效地压缩语音频率. AMR音频主要用于移动设备的音频压缩,压缩比非常高,可是音质比較差,主要用于语音类的音频压缩,不适合对音质要求较高的音乐类音频的压缩. 2 AMR编码方式 AMR 一共同拥有16种编码方式. 0-7相应8种不同的编码方式,每种编码方式的採样频率不同; 8-1

PHP 将amr音频文件转换为mp3格式

说下整体思路 1.服务器安装ffmpeg 2.使用ffmpeg -i 指令来转换amr为mp3格式(这个到时候写在PHP代码中,使用exec函数执行即可) 3.在网页端使用HTML5的audio标签来播放mp3文件 下面是操作细节: 一.服务器安装ffmpeg以cenos为例 此处参考:http://my.oschina.NET/ethan09/blog/372435 需要特别注意的是,在下面的方法中,amrnb和amrwb的安装到make环节会请求3gp的一个网址,一般是请求不到的,可以用cr