Solution
题目传送门
题意
你和田忌一起赛马,每个人一共有 匹马,你和田忌每次派出一匹马对战,求最多能赢多少次。
数据范围
。
题解
思路:可以给两个马匹速度序列排序,每次判断当前我们的马能不能赛过田忌最慢的马,如果不可以就当炮灰,如果可以就去对战增加赢的次数。
如何做?
用双指针 和 指向我们的马,如果 可以赛过 那么就将 答案变量 ,指针 也 。
AC Code
#include <bits/stdc++.h>
using namespace std;
/*====================*/
using lnt=long long;
/*====================*/
#define endl '\n'
/*====================*/
const int N=5e4+10;
/*====================*/
int u[N],v[N];
/*====================*/
int ans;
/*====================*/
void Solution(void)
{
int n;cin>>n;
for(int i=1;i<=n;i++) cin>>u[i];
for(int i=1;i<=n;i++) cin>>v[i];
sort(u+1,u+n+1);
sort(v+1,v+n+1);
for(int i=1,j=1;i<=n;i++)
{
if(u[i]>v[j])
{
j++,ans++;
}
}
cout<<ans;
}
/*====================*/
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
int T=1;//cin>>T;
while(T--) Solution();
return 0;
}