Codeforces Round #748 (Div. 3)

A. Elections

一道大水题,直接上代码

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		
		printf("%d %d %d\n", max(max(b, c) - a + 1, 0), max(max(a, c) - b + 1, 0), max(max(a, b) - c + 1, 0));
		
	}
	return 0;
} 

B. Make it Divisible by 25

这道题其实不难,就是一道思维的题,
我们不难想到,25能整除的数的最后2位数一定是00, 25, 50, 75,4种情况,所以我们只要枚举符合情况的,然后删掉不需要的,取最小值即可
那么我们怎么枚举判断呢? 我们可以开2层循环,第一层循环第一位,第二层循环第二位,然后判断是否能被25整除,
在进行取最小值

#include <iostream>
using namespace std;

int main()
{
	int T;
	cin >> T;
	
	while(T--)
	{
		string s;
		cin >> s;
		
		int ans = 100;
		for(int i = 0; i < s.size(); i++)
		{
			for(int j = i + 1; j < s.size(); j++)
			{
				int t = (s[i] - '0') * 10 + s[j] - '0';
				if(t % 25 == 0)
				{
					int m = j - i - 1 + s.size() - j - 1;
					ans = min(ans, m);
				}
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

C. Save More Mice

这道题呀, 哎,在做的时候心态都被搞炸了,把他做难了,然后还调不出来,啊,不会用map呀,一直语法错误
这题是一道贪心题,要问怎么得知,靠猜,我们只要把老鼠排个序,然后根据离洞口最近的依次先走,这样贪心一定是最优解

#include <iostream>
#include <algorithm>
using namespace std;

const int N = 4e5 + 10;

int a[N];

int main()
{
	int T;
	cin >> T;
	
	while(T--)
	{
		int n, m;
		cin >> n >> m;
		for(int i = 0; i < m; i++) cin >> a[i];
		
		sort(a, a + m, greater<int>());
		
//		for(int i = 0; i < m; i++) cout << a[i] << ' ';
		
		int t = 0, ans = 0;
		for(int i = 0; i < m; i++)
		{
			if(t < a[i]) ans++;
			else break;
			t += n - a[i];
		}
		cout << ans << endl;
	}
	return 0;
} 

D1. All are Same

这是一道数学题,首先我们可以知道,他们最后变成的数一定是所有数里面的最小的数minn,并且只能用一个数k去使所有的数变成minn,并且要使k最大,那么显然可以令k等于所有数的最大公约数
参考代码:

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 50;

int a[N];

int main()
{
	int T;
	cin >> T;
	
	while(T--)
	{
		int n;
		cin >> n;
		
		int minn = 2e9;
		for(int i = 0; i < n; i++)
		{
			cin >> a[i];
			minn = min(minn, a[i]);
		}
		
		int ans = 0;
		for(int i = 0; i < n; i++)
		{
			ans = __gcd(ans, a[i] - minn);
		}
		
		if(ans == 0) puts("-1");
		else cout << ans << endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值