当日总结
链接:https://ac.nowcoder.com/acm/contest/19850/N
来源:牛客网
题目描述
Curling is a sport in which players slide stones on a sheet of ice toward a target area. The team with the nearest stone to the center of the target area wins the game.
Two teams, Red and Blue, are competing on the number axis. After the game there are
(
𝑛
+
𝑚
)
(n+m) stones remaining on the axis,
𝑛
n of them for the Red team and the other
𝑚
m of them for the Blue. The
𝑖
i-th stone of the Red team is positioned at
𝑎
𝑖
a
i
and the
𝑖
i-th stone of the Blue team is positioned at
𝑏
𝑖
b
i
.
Let
𝑐
c be the position of the center of the target area. From the description above we know that if there exists some
𝑖
i such that
1
≤
𝑖
≤
𝑛
1≤i≤n and for all
1
≤
𝑗
≤
𝑚
1≤j≤m we have
∣
𝑐
−
𝑎
𝑖
∣
<
∣
𝑐
−
𝑏
𝑗
∣
∣c−a
i
∣<∣c−b
j
∣ then Red wins the game. What's more, Red is declared to win
𝑝
p points if the number of
𝑖
i satisfying the constraint is exactly
𝑝
p.
Given the positions of the stones for team Red and Blue, your task is to determine the position
𝑐
c of the center of the target area so that Red wins the game and scores as much as possible. Note that
𝑐
c can be any real number, not necessarily an integer.
输入描述:
There are multiple test cases. The first line of the input contains an integer
𝑇
T indicating the number of test cases. For each test case:
The first line contains two integers
𝑛
n and
𝑚
m (
1
≤
𝑛
,
𝑚
≤
1
0
5
1≤n,m≤10
5
) indicating the number of stones for Red and the number of stones for Blue.
The second line contains
𝑛
n integers
𝑎
1
,
𝑎
2
,
⋯
,
𝑎
𝑛
a
1
,a
2
,⋯,a
n
(
1
≤
𝑎
𝑖
≤
1
0
9
1≤a
i
≤10
9
) indicating the positions of the stones for Red.
The third line contains
𝑚
m integers
𝑏
1
,
𝑏
2
,
⋯
,
𝑏
𝑚
b
1
,b
2
,⋯,b
m
(
1
≤
𝑏
𝑖
≤
1
0
9
1≤b
i
≤10
9
) indicating the positions of the stones for Blue.
It's guaranteed that neither the sum of
𝑛
n nor the sum of
𝑚
m will exceed
5
×
1
0
5
5×10
5
.
include
include
include
include
using namespace std;
using ld= long double;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
vector
vector
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<m;i++)cin>>b[i];
sort(b.begin(),b.end());
vector<pair<double,int>>events;
for(ld ai:a)
{
if(binary_search(b.begin(), b.end(), ai))continue;
int pos=upper_bound(b.begin(),b.end(),ai)-b.begin();
double lower=pos>0?(ai+b[pos-1])/2.0:-1e18;
int pos_greater=lower_bound(b.begin(),b.end(),ai)-b.begin();
double upper=pos_greater<m?(ai+b[pos_greater])/2.0:1e18;
if(lower<upper)
{
events.emplace_back(lower,1);
events.emplace_back(upper,-1);
}
}
sort(events.begin(),events.end(),[](const pair<double,int>& x,const pair<double,int>& y){
if(x.first!=y.first)
{
return x.first<y.first;
}else {
return x.second<y.second;
}
});
int max_p=0;int current=0;
for(auto e:events)
{
current+=e.second;
if(current>max_p)
{
max_p=current;
}
}
if(max_p>=1)cout<<max_p<<endl;
else cout<<"Impossible"<<endl;
}
return 0;
}

浙公网安备 33010602011771号