R  — In The Airport

Time Limit: 1 sec
Memory Limit: 32 MB

It’s a Wednesday night and Bob is sitting at the airport and waiting for an airplain to Lithuania. The challenge he is facing is to come up with an easy task for the qualification contest on Saturday in KTU. Unfortunately, he doesn’t have any more ideas because it’s already late and he is too exhausted.

To freshen up, he thinks that he should get a drink and a piece of cake. Waitress gives Bob a menu to choose from. As he was too busy thinking about how tired he is, he simply decided to go for a drink and piece of cake which are the closest to the average of all items on the menu. If he needs to choose, he always goes for the cheaper item. Unfortunately waitress is not very good at math, and obviously she needs your help!

INPUT

You are given (T ≤ 100) tests on the first line. Each test starts with a line containing the integers NM,K, where (2 ≤ N ≤ 1000) is the number of items on the menu, (1 ≤ M ≤ N) is the number of cakes on the menu and (1 ≤ K ≤ N) is the number of drinks on the menu. Next line contains exactly N positive integers, where the first M integers specify the prices for cakes, next K integers (0 ≤ Pi ≤ 109) specify drink prices, and the following prices are for all other items on the menu.

OUTPUT

For each test case you have to output a line "Case #T: A B". Where T is the test case number, A specifies the closest price of the cake to the average of all items, and B is the closest price of the drink to the average of all items. Refer sample output for details.

SAMPLE INPUT

2
4 1 1
1 2 3 4
5 1 2
500000000 5 6 1000000000 1000000000

SAMPLE OUTPUT

Case #1: 1 2
Case #2: 500000000 6
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;
import java.io.StreamTokenizer;public class Main
{public static boolean DEBUG = false;public BufferedReader cin;public PrintWriter cout;public StreamTokenizer tokenizer;public int n, m, k;public long total;public long[] mArr, nArr, kArr;public void init(){try {if (DEBUG) {cin = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\OJ\\uva_in.txt")));} else {cin = new BufferedReader(new InputStreamReader(System.in));}} catch (IOException e) {e.printStackTrace();}cout = new PrintWriter(new OutputStreamWriter(System.out));tokenizer = new StreamTokenizer(cin);}public String next(){try {tokenizer.nextToken();if (tokenizer.ttype == StreamTokenizer.TT_EOF)return null;else if (tokenizer.ttype == StreamTokenizer.TT_WORD)return tokenizer.sval;else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) return String.valueOf((int)tokenizer.nval);} catch (IOException e) {e.printStackTrace();}return null;}public void input(){try {n = Integer.parseInt(next());m = Integer.parseInt(next());k = Integer.parseInt(next());total = 0;mArr = new long[m];kArr = new long[k];nArr = new long[n - m - k];for (int i = 0; i < m; i++) {mArr[i] = Long.parseLong(next());total += mArr[i];}for (int i = 0; i < k; i++) {kArr[i] = Long.parseLong(next());total += kArr[i];}int tmpn = n - m - k;for (int i = 0; i < tmpn; i++) {nArr[i] = Long.parseLong(next());total += nArr[i];}} catch (Exception e) {e.printStackTrace();}}public void solve(int t){cout.printf("Case #%d: ", t);int ans1 = 0, ans2 = 0;for (int i = 0; i < m; i++) {long tmp1 = n * mArr[i] - total;long tmp2 = n * mArr[ans1] - total;if (Math.abs(tmp1) < Math.abs(tmp2)) ans1 = i;else if (Math.abs(tmp1) == Math.abs(tmp2) && mArr[i] < mArr[ans1]) ans1 = i;}for (int i = 0; i < k; i++) {long tmp1 = n * kArr[i] - total;long tmp2 = n * kArr[ans2] - total;if (Math.abs(tmp1) < Math.abs(tmp2)) ans2 = i;else if (Math.abs(tmp1) == Math.abs(tmp2) && kArr[i] < kArr[ans2]) ans2 = i;}cout.printf("%d %d", mArr[ans1], kArr[ans2]);cout.println();cout.flush();}public static void main(String[] args){try {Main solver = new Main();solver.init();int t = Integer.parseInt(solver.next());for (int i = 1; i <= t; i++) {solver.input();solver.solve(i);}} catch (Exception e) {e.printStackTrace();}}
}

UVa11968 - In The Airport相关推荐

  1. UVA11968 In The Airport【最值】

    It's a Wednesday night and Bob is sitting at the airport and waiting for an airplain to Lithuania. T ...

  2. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  3. 【英语学习】【English L06】U05 Appointments L1 Can I book a taxi to the airport?

    文章目录 Word Preparation book a taxi: 预订出租车 extra charge:额外费用 ride: (乘车或骑车的)短途旅程 confirm: 确认 pick up:从某 ...

  4. sydney airport hotel recommendations

    来源:http://www.goaround.org/travel-australia/249141.htm Q:Hi All, Need a convenient, decent place tha ...

  5. 解决Mac osx AirPort: Link Down on en1. Reason 8 (Disassociated because station leaving)

    这个问题存在好久了,在苹果官方论坛上已经存在好长时间了,但苹果至今仍未修复此问题: https://discussions.apple.com/thread/2142725 有人说在Network P ...

  6. 苹果软件更新在哪里_苹果再次为已停产的AirPort发布软件更新

    点击上方蓝色字体,关注我们    「也就苹果仍在为退役老干部推出更新了」 苹果今天发布了 AirPort Utility(AirPort 实用工具)的罕见更新,包括安全性改进和常规稳定性增强.目前苹果 ...

  7. Airport Simulation (数据结构与算法 – 队列 / Queue 的应用)

    Airport Simulation 是数据结构与算法教材中用于演示Queue的一个小程序(大多数教师似乎会跳过这个练习).主程序会通过输入总的运行时间.队列里可以等待的最多飞机数量,平均每个时间单元 ...

  8. linux能用airport吗_如何设置AppleAirPort无线路由器

    步骤1:测试您的互联网 此步骤是最重要的一步,可以为您节省大量时间和头痛.使用以太网电缆将计算机或便携式计算机直接插入调制解调器.启动设备并将其连接到互联网.一切正常,如果不能正常运行,则需要联系您的 ...

  9. 论文阅读:Preference-based evolutionary algorithm for airport surface operations

    Preference-based evolutionary algorithm for airport surface operations 前言 预计2030年航空运输的乘客数量将是2013年的两倍 ...

最新文章

  1. java 捕获数据包,缓存从pcap捕获的数据包
  2. Exchange2010配置实验(六)部署forefront到edge服务器
  3. 【译】Analyzing Token Sale Models
  4. MySQL数据库管理(二)单机环境下MySQL Cluster的安装
  5. Struts国际化步骤
  6. 对待棘手bug,新手与大牛的差距在哪里?
  7. autosys虚拟机定义
  8. 数据库的dml、ddl和dcl的概念
  9. 攻城狮危险:波士顿动力机器狗去福特当工程师了!
  10. [JavaWeb-MySQL]DDL_操作数据库,表
  11. javascript 类型及类型判断
  12. labuladong 的算法小抄_来自GitHub 68.8k star的硬核算法教程
  13. PyCherm的常用快捷键总结
  14. java 抽象类 方法_java 抽象类
  15. LQR 离散与连续问题
  16. 【转】 TechED2010与我(三) —— 初识云计算
  17. 2.Node.js快速入门
  18. C++实现均值滤波器和中值滤波器
  19. html显示空间图片,qq空间显示不出来 为什么QQ空间有些图片显示不了
  20. Tomcat部署多个Sring Boot项目时Unable To Register MBean Exception的一种解决方法

热门文章

  1. 没有任何基础的可以学python吗-对没有编程基础的人来说,直接学Python入门IT合适吗?...
  2. 怎么在电脑上使用python-开始在 Windows 上使用 Python(初学者)
  3. python真的超过java了吗-Python为什么突然就火了呢?竟然还超过了java
  4. python爬虫流程-Python爬虫程序架构和运行流程原理解析
  5. python装饰器作用-Python装饰器的通俗理解
  6. python是用c写的吗-python和c语言的区别是什么
  7. python散点图拟合曲线-python 绘制拟合曲线并加指定点标识的实现
  8. python中是干嘛的-你都用Python来做什么,它对你来说有什么作用?
  9. python语言入门pdf-Python语言及其应用 中文pdf完整版[13MB]
  10. python百度云资源-Python开发视频百度云分享