题目
题目大意叙述如下:
现有
设
设
主人公小明有权设立三分线位置,他想让
分析
此题要求
程序实现
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int getCount(vector<int> &Bd, int m, int d)
{
int count = 0;
for (int i = 0; i < m; i++)
{
if (Bd[i] < d)
count++;
}
return count;
}
int maxScore(vector<int> &Ad, int n, vector<int> &Bd, int m)
{
//将AB两队的,投篮点排序
sort(Ad.begin(), Ad.end());
sort(Bd.begin(), Bd.end());
int max = 0 , dis = 0;
for (int i = 0; i < n; i++)
{
//将三分点设置为当前
int d = Ad[i];
//求A队得分
int scoreA = 3 * (n - i) + 2 * i;
//求B队得分
int num = getCount(Bd, m, d);
int scoreB = 2 * num + 3 * (m - num);
//求临时分差
int tmp = scoreA - scoreB;
if (tmp > max)
{
max = tmp;
dis = d;
}//if
}
return max;
}
int main()
{
int n, m,tmp;
vector<int> Ad, Bd;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> tmp;
Ad.push_back(tmp);
}
cin >> m;
for (int i = 0; i < m; i++)
{
cin >> tmp;
Bd.push_back(tmp);
}
cout << maxScore(Ad, n, Bd, m) << endl;
system("pause");
return 0;
}