HDU-5190-Go to movies

78 篇文章 0 订阅
14 篇文章 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+ai1aibi)
   
   

水题......直接枚举就行,对于每一家电影院。用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
    
    组。
输入包含多组数据,对于每组数据,第一行包含两个整数
    
    
     
     n
    
    
    
    
     
     m
    
    
    
    
     
     n
    
    表示有多少学生参加,
    
    
     
     m
    
    表示提供团购的电影院数。
接下来
    
    
     
     m
    
    行,每行两个整数
    
    
     
     a
    
    
    
    
     
     b
    
    ,表示每个电影院提供的团购方案,可以用
    
    
     
     b
    
    元买
    
    
     
     a
    
    张票。
    
    
     
     (1n,m,a,b100)
    
    
输出描述
对于每组数据,选择一个电影院,输出最少的花费。
输入样例
3 2
2 2
3 5
输出样例
4
Hint
样例解释,可以团购两次电影院1,花费4.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值