3 2 2 2 3 5
4HintLeLe can buy four tickets with four yuan in cinema 1.
1001 Go to movie 直接枚举去哪个电影院,从中取花费最少的,ans=min(n+ai?1ai?bi)
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]); } } }
寒假啦!为了打发无聊的时光,同时增进男女之间的感情,身为班长的乐乐打算带领大家看电影。 寒假时期的电影票往往很贵,于是乐乐决定团购。
有多组测试数据,大约20 组。 输入包含多组数据,对于每组数据,第一行包含两个整数n 和m ,n 表示有多少学生参加,m 表示提供团购的电影院数。 接下来m 行,每行两个整数a 和b ,表示每个电影院提供的团购方案,可以用b 元买a 张票。(1≤n,m,a,b≤100)
对于每组数据,选择一个电影院,输出最少的花费。
3 2 2 2 3 5
4
样例解释,可以团购两次电影院1,花费4.
原文:http://blog.csdn.net/qq_16542775/article/details/44671129