蓝桥杯 付账问题,交换次数,密码脱落

#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
long double arr[500010];
int n;
long double k;
int main()
{
	cin >> n >> k;
	for (int i = 1;i <= n;i++)
	{
		cin >> arr[i];
	}
	long double ave = k / n;
	sort(arr + 1, arr + 1 + n);
	long double ans = 0;
	for (int i = 1;i <= n;i++)
	{
		long double t = k / (n + 1 - i);
		if (arr[i] < t)t = arr[i];
		ans += ((t - ave) * (t - ave))/n;
		k -= t;
	}
	
	printf("%.4Lf", sqrt(ans));
	return 0;
}

 

 

 

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
string str;
int ans = 1000000;
int a = 0;
int b = 0;
int t = 0;
void function1(char c1, char c2, char c3, int n1, int n2, int n3)
{
	int c12 = 0;
	int c13 = 0;
	int c21 = 0;
	int c23 = 0;
	int c31 = 0;
	int c32 = 0;
	for (int i = 0;i < n1;i++)
	{
		if (str[i] == c2)
		{
			c12++;
		}
		else if (str[i] == c3)
		{
			c13++;
		}
	}
	for (int i = n1;i < n1 + n2;i++)
	{
		if (str[i] == c1)
		{
			c21++;
		}
		else if (str[i] == c3)
		{
			c23++;
		}
	}
	for (int i = n1 + n2;i < n1 + n2 + n3;i++)
	{
		if (str[i] == c1)
		{
			c31++;
		}
		else if (str[i] == c2)
		{
			c32++;
		}
	}
	int res = 0;
	res += min(c31, c13);
	res += min(c12, c21);
	res += min(c23, c32);
	res += (abs(c31 - c13))*2;
	ans = min(ans, res);
	//cout << c1 << c2 << c3 << res << endl;
}
int main()
{
	cin >> str;
	
	for (int i = 0;i < str.size();i++)
	{
		if (str[i] == 'A')
		{
			a++;
		}
		else if (str[i] == 'B')
		{
			b++;
		}
		else
		{
			t++;
		}
	}
	//tab
	function1('T', 'A', 'B', t, a, b);
	//tba
	function1('T', 'B', 'A', t, b, a);
	//abt
	function1('A', 'B', 'T', a, b, t);
	//atb
	function1('A', 'T', 'B', a, t, b);
	//bat
	function1('B', 'A', 'T', b, a, t);
	//bta
	function1('B', 'T', 'A', b, t, a);
	cout << ans << endl;
	return 0;
}

 

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int f[1010][1010];
int main()
{
	string str1;
	cin >> str1;
	string str2;
	str2.resize(str1.size());
	for (int i = 0;i < str1.size();i++)
	{
		str2[i] = str1[str1.size() - 1 - i];
	}
	//cout << str1 << endl << str2 << endl;
	int res = 0;
	for (int i = 1;i <= str1.size();i++)
	{
		for (int j = 1;j <= str2.size();j++)
		{

			if (str1[i-1] != str2[j-1])
			{
				f[i][j] = max(f[i - 1][j], f[i][j - 1]);
			}
			else
			{
				f[i][j] = f[i - 1][j - 1]+1;
			}
		}
	}
	cout << str1.size() - f[str1.size()][str1.size()] << endl;
	return 0;
}

 

 

相关推荐

  1. 付账问题

    2024-06-06 23:52:02       17 阅读
  2. [ 2018 省 A] 付账问题

    2024-06-06 23:52:02       17 阅读
  3. 洛谷 P8664 [ 2018 省 A] 付账问题

    2024-06-06 23:52:02       40 阅读
  4. 座次问题

    2024-06-06 23:52:02       16 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-06 23:52:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-06 23:52:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-06 23:52:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-06 23:52:02       20 阅读

热门阅读

  1. 认识邮件系统

    2024-06-06 23:52:02       7 阅读
  2. 关于Spring单例bean在高并发场景下的注意事项

    2024-06-06 23:52:02       7 阅读
  3. 特征工程,减小过拟合

    2024-06-06 23:52:02       9 阅读
  4. Python怎么输出逆序数

    2024-06-06 23:52:02       10 阅读
  5. ######## redis各章节终篇索引 ############

    2024-06-06 23:52:02       11 阅读