寒假18 蓝桥杯练习

时间:2024-02-24 17:59:33

#include<iostream>
using namespace std;//4430091
long long ansb = 0;//4165637
void dfs(int u, int f)
{
	if (u == 30 )
	{
		if (f == 60)
		{
			ansb++;
		}
		
	}
	else if (f >= 100)
	{
		return;
	}
	else
	{
		dfs(u + 1, 0);
		dfs(u + 1, f + 10);
	}
	
}
int main()
{
	int result = 0;
	for (int i = 1;i <= 100000000;i++)
	{
		int flag = i;
		int flag2 = 0;
		while (flag)
		{
			flag2++;
			flag /= 10;
		}
		if (flag2 % 2 == 0)
		{
			flag2 /= 2;
			int flag3 = 1;
			for (int j = 1;j <= flag2;j++)
			{
				flag3 *= 10;
			}
			int num1 = i % flag3;
			int num2 = i / flag3;
			int ans1 = 0, ans2 = 0;
			while (num1)
			{
				ans1 += (num1 % 10);
				num1 /= 10;
			}
			while (num2)
			{
				ans2 += (num2 % 10);
				num2 /= 10;
			}
			if (ans1 == ans2)result++;
		}
	}
	cout << result << endl;
	dfs(1, 0);
	cout << ansb << endl;
	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	long long a, b, q;
	cin >> a >> b >> q;
	cout << a << '^' << b << " mod " << q << '=';
	long long ans = a;
	long long flag = 1;
	while (b)
	{
		if (b % 2 != 0)
		{
			flag = flag * a % q;
			b--;
		}
		else
		{
			a = a * a % q;
			b /= 2;
		}
	}
	cout << flag << endl;
	return 0;
}

#include<iostream>
using namespace std;
int gcd(int x, int y)
{
	if (y == 0)
	{
		return x;
	}
	return gcd(y, x % y);
}
int const maxdp = 100005;
int n;
int arr[110];
bool dp[maxdp];
bool test()
{
	int g = arr[1];
	for (int i = 2;i <= n;i++)
	{
		g = gcd(g, arr[i]);
		if (g == 1)
		{
			return false;
		}
	}
	return true;
}
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> arr[i];
	}
	if (test())
	{
		cout << "INF" << endl;
		return 0;
	}
	dp[0] = 1;
	for (int i = 1;i <= n;i++)
	{
		for (int j = arr[i];j < maxdp;j++)
		{
			dp[j] = max(dp[j], dp[j - arr[i]]);
		}
	}
	int ans = 0;
	for (int i = 1;i < maxdp;i++)
	{
		if (!dp[i])
		{
			ans++;
		}
	}
	cout << ans;
	return 0;
}

#include<iostream>
using namespace std;
#include<algorithm>
int n;
int arr[110];
int main()
{
	cin >> n;
	int pos;
	for (int i = 1;i <= n;i++)
	{
		int pos1;
		cin >> pos1;
		if (i == 1)pos = pos1;
		arr[abs(pos1)] = pos1;
	}
	int ans = 1;
	int flag = 0;
	if (pos > 0)
	{
		for (int i = 100;i > pos;i--)
		{
			if (arr[i] < 0)
			{
				ans++;
				flag = 1;
			}
		}
		if (flag == 1)
		{
			for (int i = 1;i < pos;i++)
			{
				if (arr[i] > 0)
				{
					ans++;
				}
			}
		}
	}
	else
	{
		for (int i = 1;i < abs(pos);i++)
		{
			if (arr[i] > 0)
			{
				ans++;
				flag = 1;
			}
		}
		if (flag == 1)
		{
			for (int i =abs(pos)+1;i <= 100;i++)
			{
				if (arr[i] < 0)
				{
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}