题目链接:点击打开链接
A. Andryusha and Socks
time limit per test
memory limit per test
input
output
Andryusha is an orderly boy and likes to keep things in their place.
n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
Input
n (1 ≤ n ≤ 105) — the number of sock pairs.
2n integers x1, x2, ..., x2n (1 ≤ xi ≤ n), which describe the order in which Andryusha took the socks from the bag. More precisely, xi means that the i-th sock Andryusha took out was from pair xi.
It is guaranteed that Andryusha took exactly two socks of each pair.
Output
Print single integer — the maximum number of socks that were on the table at the same time.
Examples
input
1 1 1
output
1
input
3 2 1 1 3 2 3
output
2
Note
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- 2
- (2) was on the table. Andryusha took out a sock from pair 1
- (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe.
- (2) was on the table. Andryusha took out a sock from pair 3
- (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe.
- (3) was on the table. Andryusha took out a sock from pair 3
大意:往桌子上放袜子,当出现桌子上出现两只一样的袜子时把这一对袜子放入床头柜,求桌子上最多能放多少只袜子。
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
bool vis[100010];
int main()
{
while(~scanf("%d",&n))
{
memset(vis,0,sizeof(vis));
n<<=1;
int cnt=0,last=0,ans;
while(n--)
{
int x;
scanf("%d",&x);
if(!vis[x])
{
cnt++;
ans=max(last,cnt);
last=ans;
vis[x]=1;
}
else
{
cnt--;
vis[x]=0;
}
// printf("%d--%d\n",cnt,ans);
}
printf("%d\n",ans);
}
return 0;
}
题目链接:
点击打开链接
B. The Meeting Place Cannot Be Changed
time limit per test
memory limit per test
input
output
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi
n
Input
n (2 ≤ n ≤ 60 000) — the number of friends.
n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters.
n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters per second.
Output
n
10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if
holds.
Examples
input
37 1 3 1 2 1
output
2.000000000000
input
45 10 3 2 2 3 2 4
output
1.400000000000
Note
5 within 2
大意:有 n 个人在一条线上,给出每个人的坐标位置和每个人行走的速度。问要使所有人聚在一起所需的最优时间。
#include<cstdio>
#include<algorithm>
#include<cstring>
#define eps 1e-7
using namespace std;
int n;
double x[60010],v[60010];
bool judge(double o)
{
double xl,xr,ansl,ansr;
ansl=x[1]-v[1]*o;
ansr=x[1]+v[1]*o;
for(int i=2;i<=n;i++)
{
xl=x[i]-v[i]*o;
xr=x[i]+v[i]*o;
if(ansl>xr||ansr<xl)
return 0;
if(xl<ansl)
{
if(xr<=ansr)
ansr=xr;
}
else
{
ansl=xl;
if(xr<=ansr)
ansr=xr;
}
}
return 1;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
scanf("%lf",x+i);
for(int i=1;i<=n;i++)
scanf("%lf",v+i);
double mid,l=0.0,r=1e9+10.0;
while(l+eps<=r) // 这里的 eps=1e-8 就会死循环
{
mid=(l+r)/2.0;
if(judge(mid))
r=mid;
else
l=mid;
}
printf("%.8lf\n",l);
}
return 0;
}