贪心策略 CSU - 1722 Race(田忌赛马)
2018-04-01 00:02
274 查看
Description
Johnson and Bob are crazy motorcycle collecting enthusiasts. In order to prove their own motorcycles is the best, they issued a challenge to each other. Johnson wants to win the challenge.As a good friend of Johnson’s, you need to give advice to Johnson. Johnson and Bob each can select their best n motorcycles. And each motorcycle has a value v. There are n matches in total. Any motorcycle can be chosen optionally to participate in the match(but each motorcycle can only participate once). Each time the motorcycle with high value will win. Johnson gets the order of Bob’s motorcycles in advance. Can you help Johnson arrange the competition order of motorcycles in order to win the most of the matches?Input
First line input an integer T(mean there are T cases)In each case , first line input an integer n (mean there are n motorcycles) (0<n<=10000)
Next line input n integers (mean the value of Johnson’s n motorcycles)
Next line n integers (mean the value of Bob’s n motorcycles )
Output
Every case output an integer mean the most match can win.Sample Input
1 5 6 4 5 1 3 8 9 3 4 7
Sample Output
2代码:
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int T,n,J[10000],B[10000];
cin>>T;
while(T--){
cin>>n;
for(int j=0;j<n;j++){
cin>>J[j];
}
sort(J,J+n);
for(int b=0;b<n;b++){
cin>>B[b];
}
sort(B,B+n);
int loc=0;
for(int j=0;j<n;j++){
if(J[j]>B[loc]){
loc++;
}
}
cout<<loc<<endl;
}
return 0;
}
相关文章推荐
- CSU 1722: Race(田忌赛马)
- 贪心策略 CSU - 1065: Scientific Conference
- 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)
- Uva 11134 问题分解,贪心策略区间选点问题
- 编程之美----高效率地安排见面会----贪心策略
- 贪心策略 HDU - 1338 Game Prediction
- <C/C++算法>贪心策略练习与总结
- Color the fence(南阳oj791)(贪心+策略)
- 田忌赛马(贪心)
- hdu 1051 wooden sticks (贪心策略)
- HDOJ-----1502贪心-----田忌赛马
- 文章标题 CSU 1859: Gone Fishing(贪心)
- 【杭电OJ】--1052-田忌赛马(贪心,双端队列)
- codeforces Variable Shadowing 2014 NEERC Southern Subregional M 贪心策略
- CSU 1065 Scientific Conference 贪心(基本的调度问题)
- csu 1749: Soldiers ' Training(贪心)
- Uva11054 等价转换 贪心策略:供需分配问题
- hdu4562(贪心策略+DP)
- ZOJ1012-Mainframe 贪心策略
- [csu1603]贪心