/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 4ms 8.301 MiB
#2 Accepted 2ms 4.199 MiB
#3 Accepted 3ms 6.297 MiB
#4 Accepted 4ms 8.297 MiB
#5 Accepted 38ms 8.301 MiB
#6 Accepted 36ms 4.688 MiB
#7 Accepted 284ms 8.695 MiB
#8 Accepted 252ms 7.426 MiB
#9 Accepted 259ms 9.051 MiB
#10 Accepted 283ms 8.426 MiB

代码

#include<bits/stdc++.h>
using namespace std;
int a[400005],b[400005],c[800010],fa[400005],fb[400005];
int ans=1e9;
int main()
{
//	freopen("card.in","r",stdin);
//	freopen("card.out","w",stdout);
	int n;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		c[2*i-1]=a[i];
		c[2*i]=b[i];
	}
	sort(c+1,c+2*n+1);
	int len=unique(c+1,c+2*n+1)-c-1;
	for(int i=1;i<=n;i++)
	{
    	a[i]=lower_bound(c+1,c+1+len,a[i])-c;
    	b[i]=lower_bound(c+1,c+1+len,b[i])-c;
	}
	for (int i=1;i<=n;i++)
	{
		fa[a[i]]++;
		if (a[i]!=b[i]) fb[b[i]]++;
	}
	int m=(n+1)/2;
	for (int i=1;i<=len;i++)
	{
		if (fa[i]+fb[i]>=m) 
		{
			ans=min(m-fa[i],ans);
		}
	}
	if (ans!=1e9) cout<<max(ans,0);
	else puts("Impossible");
}

信息

递交者
类型
递交
题目
纸牌
题目数据
下载
语言
C++
递交时间
2019-12-13 14:47:32
评测时间
2019-12-13 14:47:32
评测机
分数
100
总耗时
1171ms
峰值内存
9.051 MiB