天天看点

HDU-5190-Go to movies Go to movies Go to movies

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(1≤n,m≤100) .  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(1≤ai,bi≤100) , 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 BestCoder Round #34  

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
    组。
输入包含多组数据,对于每组数据,第一行包含两个整数
    
     n
    和
    
     m
    ,
    
     n
    表示有多少学生参加,
    
     m
    表示提供团购的电影院数。
接下来
    
     m
    行,每行两个整数
    
     a
    和
    
     b
    ,表示每个电影院提供的团购方案,可以用
    
     b
    元买
    
     a
    张票。
    
     (1≤n,m,a,b≤100)
          

输出描述

对于每组数据,选择一个电影院,输出最少的花费。      

输入样例

3 2
2 2
3 5      

输出样例

4      

Hint

样例解释,可以团购两次电影院1,花费4.