首页 > 其他 > 详细

HDU-5190-Go to movies

时间:2015-03-27 11:03:45      阅读:332      评论:0      收藏:0      [点我收藏+]

Go to movies

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 481    Accepted Submission(s): 284


Problem Description
Winter holiday is coming!As the monitor, LeLe plans to go to the movies.
Because the winter holiday tickets are pretty expensive, LeLe decideds to try group-buying.
 

Input
There are multiple test cases, about 20 cases. The first line of input contains two integers n,m(1n,m100)n indicates the number of the students. m indicates how many cinemas have offered group-buying.

For the m lines,each line contains two integers ai,bi(1ai,bi100), indicating the choices of the group buying cinemas offered which means you can use bi yuan to buy ai tickets in this cinema.
 

Output
For each case, please help LeLe **choose a cinema** which costs the least money. Output the total money LeLe should pay.
 

Sample Input
3 2 2 2 3 5
 

Sample Output
4
Hint
LeLe can buy four tickets with four yuan in cinema 1.
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:  5193 5192 5191 5189 5188 


BestCoder官方答案:

1001 Go to movie

直接枚举去哪个电影院,从中取花费最少的,ans=min(n+ai?1ai?bi)

水题......直接枚举就行,对于每一家电影院。用n个学生除以团购的学生数,如果有余数多加b[i]块钱,否则就是正好a[i]*b[i]块钱。

import java.io.*;
import java.util.*;

public class Main
{

	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		while(input.hasNext())
		{
			int n = input.nextInt();  //n表示参见学生的数量
			int m = input.nextInt();  //m表示团购的电影票数
			int a[] = new int[m];
			int b[] = new int[m];
			int c[] = new int[m];     //c数组记录
			for(int i = 0;i<m;i++)
			{
				a[i]=input.nextInt();
				b[i]=input.nextInt();
				int temp = n/a[i];
				if(n%a[i]>0)
				{
					c[i]=(temp+1)*b[i];
				}
				else 
				{
					c[i]=temp*b[i];
				}
			}
			Arrays.sort(c);
			System.out.println(c[0]);
		}
	}

}
 


老规矩,中文在下面!


Go to movies

 
 Accepts: 624
 
 Submissions: 1515
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
寒假啦!为了打发无聊的时光,同时增进男女之间的感情,身为班长的乐乐打算带领大家看电影。
寒假时期的电影票往往很贵,于是乐乐决定团购。
输入描述
有多组测试数据,大约20组。
输入包含多组数据,对于每组数据,第一行包含两个整数nmn表示有多少学生参加,m表示提供团购的电影院数。
接下来m行,每行两个整数ab,表示每个电影院提供的团购方案,可以用b元买a张票。(1n,m,a,b100)
输出描述
对于每组数据,选择一个电影院,输出最少的花费。
输入样例
3 2
2 2
3 5
输出样例
4
Hint
样例解释,可以团购两次电影院1,花费4.


HDU-5190-Go to movies

原文:http://blog.csdn.net/qq_16542775/article/details/44671129

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!