Good Bye 2020 虚拟参赛及补题

aiaiiaiaiaiiai
自己为什么这么菜。
五五五五五五
五五五五五五呜呜呜呜呜
只做出了一道题,要是参赛正式的话,还不血掉分。哎
A题

#include<bits/stdc++.h>
 
using namespace std;
 
const int N = 55;
 
typedef long long ll;
int a[N];
 
void solve()
{
    
    
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
    
    
		cin>>a[i];
	}
	set<int> s;
	sort(a+1,a+1+n);
	for(int i=n;i>1;i--)
	{
    
    
		for(int j=i-1;j>=1;j--)
		{
    
    
			int x=a[i]-a[j];
			s.insert(x);
		}
	}
	cout<<s.size()<<endl;
}
 
int main()
{
    
    
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
    
    
		solve();
	}
}

B题,很简单的一道题,卡到了
这个题给你一个数组,要么不变,要么加一,问最后操作后,最多能有几种数字。
简单楼,排序漏。

  • 错误代码。
#include<bits/stdc++.h>

using namespace std;

const int N = 1e5+10;

typedef long long ll;
int a[N];

void solve()
{
    
    
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
    
    
		cin>>a[i];
	}
	set<int> s;
	sort(a+1,a+1+n);
	for(int i=n;i>=1;i--)
	{
    
    
		s.insert(a[i]);
	}
	for(int i=2;i<=n;i++)
	{
    
    
		if(a[i]==a[i-1])
		{
    
    
			a[i]+=1;
			s.insert(a[i]);
		}
	}
	cout<<s.size()<<endl;
}

int main()
{
    
    
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
    
    
		solve();
	}
}

呜呜呜呜呜呜呜呜啎。

  • 正确的欸
#include<bits/stdc++.h>

using namespace std;

const int N = 1e5+10;

typedef long long ll;
int a[N];

void solve()
{
    
    
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
    
    
		cin>>a[i];
	}
	set<int> s;
	sort(a+1,a+1+n);
	for(int i=n;i>=1;i--)
	{
    
    
		s.insert(a[i]);
	}
	for(int i=2;i<=n;i++)
	{
    
    
		if(a[i]==a[i-1])
		{
    
    
			a[i]+=1;
			s.insert(a[i]);
		}
	}
	cout<<s.size()<<endl;
}

int main()
{
    
    
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
    
    
		solve();
	}
}

C题
题目链接

奇怪的出题人不愿意让大于一的回文串出现,问你最少改几个?
思路直接看代码,能看懂的。呜呜,不用特判耶。尴尬。

#include<bits/stdc++.h>

using namespace std;

const int N = 102;

typedef long long ll;

const int maxn = 1e5 + 7;

int t;
void solve()
{
    
    

	string b;
	cin >> b;

	int len = b.length();
	int res = 0;
	string c = b;
	sort(c.begin(), c.end());
	if (len == 1)
	{
    
    
		cout << 0 << endl;
		return;
	}
	//cout<<len<<endl;
	// if (c[0] == c[len - 1])
	// {
    
    
	// 	if (len %2== 1)
	// 		cout << len / 2 + 1 << endl;
	// 	else
	// 		cout << len /2<< endl;
	// 	return;
	// }
	bool vis[maxn]={
    
    false};

	for (int i = 1; i < len; i++)
	{
    
    
		if (b[i] == b[i - 1]&&b[i-1]!='0')
		{
    
    
			res++;
			
			b[i] = '0';
		}
		if (i != 1 && b[i] == b[i - 2]&&b[i-2]!='0')
		{
    
    
			res++;

			b[i] = '0';
		}
	}
	
	//cout <<b<< endl;
	cout << res << endl;
}


int main()
{
    
    
	
	cin >> t;
	while (t--)
	{
    
    
		solve();
	}
}
  • 错误代码
#include<bits/stdc++.h>

using namespace std;

const int N = 102;

typedef long long ll;

const int maxn = 1e5 + 7;

using namespace std;

void solve()
{
    
    
	string b;
	cin >> b;
	int len = b.length();
	int res = 0;
	string c = b;
	sort(c.begin(), c.end());
	if (len == 1)
	{
    
    
		cout << 0 << endl;
		return;
	}
	if (c[0] == c[len - 1])
	{
    
    
		if (len %2== 1)
			cout << len / 2 + 1 << endl;
		else
			cout << len << endl;
		return;
	}
	for (int i = 1; i < len; i++)
	{
    
    
		if (b[i] == b[i - 1])
		{
    
    
			res++;
			b[i] = '0'+res;
		}
		if (i != 1 && b[i] == b[i - 2])
		{
    
    
			res++;
			b[i] = '0'+res;
		}
	}
	//cout<<b<<endl;
	cout << res << endl;
}


int main()
{
    
    
	int t;
	cin >> t;
	while (t--)
	{
    
    
		solve();
	}
}

猜你喜欢

转载自blog.csdn.net/qq_46264636/article/details/112989139