【NOJ1047】【算法实验四】田忌赛马(tian ji racing)
1047.田忌賽馬(tian ji racing)
時限:1000ms 內(nèi)存限制:10000K 總時限:3000ms
描述
田忌與齊王賽馬,雙方各有n匹馬參賽(n<=100),每場比賽賭注為1兩黃金,現(xiàn)已知齊王與田忌的每匹馬的速度,并且齊王肯定是按馬的速度從快到慢出場,現(xiàn)要你寫一個程序幫助田忌計算他最好的結(jié)果是贏多少兩黃金(輸用負數(shù)表示)。
Tian Ji and the king play horse racing, both sides have n horse (n is no more the 100), every game a bet of 1 gold, now known king and Tian Ji each horse’s speed, and the king is definitely on the horse speed from fast to slow, we want you to write a program to help Tian Ji his best result is win the number gold (lost express with the negative number).
輸入
多個測例。
每個測例三行:第一行一個整數(shù)n,表示雙方各有n匹馬;第二行n個整數(shù)分別表示田忌的n匹馬的速度;第三行n個整數(shù)分別表示齊王的n匹馬的速度。
n=0表示輸入結(jié)束。
A plurality of test cases.
Each test case of three lines: the first line contains an integer n, said the two sides each have n horse; second lines of N integers n Tian Ji horse speed; third lines of N integers King n horse speed.
N = 0 indicates the end of input.
輸出
每行一個整數(shù),田忌最多能贏多少兩黃金。
how many gold the tian ji win
輸入樣例
3
92 83 71
95 87 74
2
20 20
20 20
2
20 19
22 18
3
20 20 10
20 20 10
0
輸出樣例
1
0
0
0
總結(jié)
以上是生活随笔為你收集整理的【NOJ1047】【算法实验四】田忌赛马(tian ji racing)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Winform 连接打印机
- 下一篇: 苹果cms v10用户搜索什么就入库添加