UVa11968 - In The Airport

简介: UVa11968 - In The Airport
importjava.io.IOException;
importjava.io.FileInputStream;
importjava.io.InputStreamReader;
importjava.io.BufferedReader;
importjava.io.PrintWriter;
importjava.io.OutputStreamWriter;
importjava.io.StreamTokenizer;
publicclassMain{
publicstaticbooleanDEBUG=false;
publicBufferedReadercin;
publicPrintWritercout;
publicStreamTokenizertokenizer;
publicintn, m, k;
publiclongtotal;
publiclong[] mArr, nArr, kArr;
publicvoidinit()
    {
try {
if (DEBUG) {
cin=newBufferedReader(newInputStreamReader(
newFileInputStream("d:\\OJ\\uva_in.txt")));
            } else {
cin=newBufferedReader(newInputStreamReader(System.in));
            }
        } catch (IOExceptione) {
e.printStackTrace();
        }
cout=newPrintWriter(newOutputStreamWriter(System.out));
tokenizer=newStreamTokenizer(cin);
    }
publicStringnext()
    {
try {
tokenizer.nextToken();
if (tokenizer.ttype==StreamTokenizer.TT_EOF)
returnnull;
elseif (tokenizer.ttype==StreamTokenizer.TT_WORD)
returntokenizer.sval;
elseif (tokenizer.ttype==StreamTokenizer.TT_NUMBER) 
returnString.valueOf((int)tokenizer.nval);
        } catch (IOExceptione) {
e.printStackTrace();
        }
returnnull;
    }
publicvoidinput()
    {
try {
n=Integer.parseInt(next());
m=Integer.parseInt(next());
k=Integer.parseInt(next());
total=0;
mArr=newlong[m];
kArr=newlong[k];
nArr=newlong[n-m-k];
for (inti=0; i<m; i++) {
mArr[i] =Long.parseLong(next());
total+=mArr[i];
            }
for (inti=0; i<k; i++) {
kArr[i] =Long.parseLong(next());
total+=kArr[i];
            }
inttmpn=n-m-k;
for (inti=0; i<tmpn; i++) {
nArr[i] =Long.parseLong(next());
total+=nArr[i];
            }
        } catch (Exceptione) {
e.printStackTrace();
        }
    }
publicvoidsolve(intt)
    {
cout.printf("Case #%d: ", t);
intans1=0, ans2=0;
for (inti=0; i<m; i++) {
longtmp1=n*mArr[i] -total;
longtmp2=n*mArr[ans1] -total;
if (Math.abs(tmp1) <Math.abs(tmp2)) ans1=i;
elseif (Math.abs(tmp1) ==Math.abs(tmp2) &&mArr[i] <mArr[ans1]) ans1=i;
        }
for (inti=0; i<k; i++) {
longtmp1=n*kArr[i] -total;
longtmp2=n*kArr[ans2] -total;
if (Math.abs(tmp1) <Math.abs(tmp2)) ans2=i;
elseif (Math.abs(tmp1) ==Math.abs(tmp2) &&kArr[i] <kArr[ans2]) ans2=i;
        }
cout.printf("%d %d", mArr[ans1], kArr[ans2]);
cout.println();
cout.flush();
    }
publicstaticvoidmain(String[] args)
    {
try {
Mainsolver=newMain();
solver.init();
intt=Integer.parseInt(solver.next());
for (inti=1; i<=t; i++) {
solver.input();
solver.solve(i);
            }
        } catch (Exceptione) {
e.printStackTrace();
        }
    }
}
目录
相关文章
uva10038 Jolly Jumpers
uva10038 Jolly Jumpers
29 0
Uva10001 Garden of Eden
Uva10001 Garden of Eden
41 0
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
46 0
UVa 10082 WERTYU
Problem Description A common typing error is to place the hands on the keyboard one row to the right of the correct position.
880 0
概率dp - UVA 11021 Tribles
Tribles  Problem's Link:  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33059   Mean:  有k个细菌,每个细菌只能存活一天,在死去之前可能会分裂出0,1,2....n-1个细菌,对应的概率为p0,p1,p2....pn-1。
817 0
|
机器学习/深度学习
|
机器学习/深度学习
uva 12470 Tribonacci
点击打开uva12470  思路: 矩阵快速幂 分析: 1 裸题 代码: /************************************************ * By: chenguolin ...
983 0
|
人工智能
uva 305 Joseph
点击打开链接uva 305 思路: 数学+打表 分析: 1 传统的约瑟夫问题是给定n个人和m,每次数m次把当前这个人踢出局,问最后留下的一个人的编号 2 这一题是前k个人是好人,后面k个是坏人。
1040 0
uva 10273 Eat or Not to Eat?
点击打开链接uva 10273 思路: 暴力求解 分析: 1 题目要求没有吃掉的奶牛的个数已经最后一次吃掉奶牛的天数 2 没有其它的方法只能暴力,对于n头牛的n个周期求最小公倍数,然后在2个公倍数之内暴力求解 代码: #inclu...
804 0