csuoj-1722-Race
来源:互联网 发布:js继承面试题详解 编辑:程序博客网 时间:2024/06/08 00:22
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
156 4 5 1 38 9 3 4 7
Sample Output
2
HINT
不记得是poj,还是hdoj有一道差不多的题,田忌赛马吧
直接把那个题找了出来然后改动一下就ok
#include <bits/stdc++.h>using namespace std;const int maxn = 10005;int john[maxn], bob[maxn];int n; int main(){ #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T; scanf("%d", &T); while (T--){ scanf("%d", &n); for (int i=0; i<n; ++i) scanf("%d", john+i); for (int i=0; i<n; ++i) scanf("%d", bob+i); sort(john, john+n); sort(bob, bob+n); int john_high=n-1, john_low=0; int bob_high=n-1, bob_low=0; int sum = 0; while (john_low<=john_high && bob_low<=bob_high){ if (john[john_low] > bob[bob_low]){ ++sum; ++john_low; ++bob_low; } else if (john[john_low] < bob[bob_low]){ ++john_low; --bob_high; } else{ if (john[john_high] > bob[bob_high]){ ++sum; --john_high; --bob_high; } else if (john[john_high] < bob[bob_high]){ ++john_low; --bob_high; } else{ if (john[john_low] < bob[bob_high]){ ++john_low; --bob_high; } else if (john[john_low] == bob[bob_high]) break; } } } printf("%d\n", sum); } return 0;}
- csuoj-1722-Race
- CSUOJ
- CSUOJ
- Race
- csuoj--1307
- csuoj Lexicography
- csuoj X
- 1989CSUOJ
- CSU 1722: Race(田忌赛马)
- CSUOJ优先队列
- CSUOJ 1165 枚举
- CSUOJ 1063 Sequence
- CSUOJ 1258 维护序列
- Random Integers+csuoj+dp
- CSUOJ--1563: Lexicography
- csuoj 2015.3.15
- 【CSUOJ 1623】Inspectors
- CSUOJ:集训队组队计划
- android Binder 学习
- hdoj 4268 Alice and Bob 【贪心 + set】
- 【C#语法】C#中强转和as、is的区别
- c++静态链接库和动态链接库的创建和调用
- ssh整合简单总结
- csuoj-1722-Race
- 1.2.位、字节、半字、字、内存位宽
- 使用 jquery.validate.messages_cn.js 插件实现表单自动验证,出现中文乱码
- 大数据学习笔记·互联网搜索中的大数据
- B2C商城订单系统UML建模
- java与C++语法上的差别
- SpringMVC源码剖析(二)- DispatcherServlet的初始化
- java基础(23)--强引用、弱引用、软引用、虚引用
- Java平台相关的换行符