求助!我为什么错了?
  • 板块题目总版
  • 楼主I_AM_ACer
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/6/11 13:38
  • 上次更新2024/6/11 18:03:34
查看原帖
求助!我为什么错了?
1368992
I_AM_ACer楼主2024/6/11 13:38

题目是:k-Multiple Free Set

编号是:CF274A

这道题我先试着用了map,因为WA了又试着用了bool,但是却又RE了(可能因为数组炸了)。我实在改不了了。

我用bool的代码

#include<bits/stdc++.h>
using namespace std;
map <long long,bool> m;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];	
	}
	sort(a+1,a+n+1);
	bool e[a[n]*k];
	memset(e,0,sizeof(e));
	for(int i=1;i<=n;i++)
	{
		if(e[a[i]]==false)
		{
			e[a[i]*k]=true;
			sum++;
		}
	}
	cout<<sum;
	return 0;
}

我用map的代码

#include<bits/stdc++.h>
using namespace std;
map <long long,bool> m;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];	
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		if(m[a[i]]==false)
		{
			m[a[i]*k]=true;
			sum++;
		}
	}
	cout<<sum;
	return 0;
}

我的思路基本上就是先从小到大排序,再看看a[i]位上有没有人,没有就设他k倍的位上有人,有人就接着往下循环,最后输出结果。

两次都是样例过了但测试没过(难受啊!)

恳请各位大佬与神犇们为小弟指正错误!!!

2024/6/11 13:38
加载中...