Educational Codeforces Round 109

蒟蒻只做出了两道签到题…剩下的题待补。


比赛链接

A.Potion Making

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int k; cin >> k;
		int d = gcd(k, 100);
		cout << 100 / d << '\n';
	}
}

B.Permutation Sort

一开始没啥思路,就拿着本草稿纸自己造数据玩,慢慢地发现一共也就分几种情况

  1. 完全符合题意的
  2. 只有一对位置不一样的,这里又分两种情况
    (1)首尾分别是最大数和最小数
    (2)不满足(1)的
  3. 开头是最小数或者末尾是最大数
  4. 首尾分别是最大数和最小数
  5. 不满足上述四条的

第一种情况显然是0

第二种情况:(1)这里要把最小的运到前面,把最大的运到后面,然后中间再整理一次,所以一共三次(2)因为只有一对不一样,所以整理一次就够了

第三种情况:直接重排(n-1)长度的子串,一次就够了

第四种情况:与第二种情况的(1)一样的

第五种情况:重排两次(n-1)长度的子串就够了,想不出来的自己整一些例子看看就懂了

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
using namespace std;
int a[55];
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int ck = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (a[i] != i)ck++;
		}
		if (ck == 0) {
			cout << 0 << '\n'; continue;
		}
		if (ck == 2) {
			if (a[1] == n && a[n] == 1)cout << 3 << '\n';
			else cout << 1 << '\n';
			continue;
		}
		if (a[1] == 1 || a[n] == n) {
			cout << 1 << '\n'; continue;
		}
		if (a[1] == n && a[n] == 1) {
			cout << 3 << '\n'; continue;
		}
		cout << 2 << '\n';
	}
}

C.还没看题

D.Armchairs

一直在想怎么贪心,结果正解是DP
有空再补


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值