ABC299 CDE Solution - By LaDeX

GIAOchen 2023-07-17 11:35:08 2023-07-26 15:56:42 4


大水题。 按题意暴力即可。

LL n, m;
string str[N];
int main(){
	Fcin;
	cin >> n >> m;
	for (LL i = 1; i <= n; i ++){
		cin >> str[i];
		for (LL j = 0; j < m - 1; j ++){
			if (str[i][j] == str[i][j + 1] && str[i][j] == 'T')
				str[i][j] = 'P', str[i][j + 1] = 'C';
		}
		cout << str[i] << "\n";
	}
	return 0;
}

其实就是辗转相减法求最大公因数。 用辗转相除法加速过程。

LL GCD(LL x, LL y){
	if (x == y)
		return -1;
	if (x % y == 0){
		Ans += x / y - 1;
		return y;
	}
	Ans += x / y;
	return GCD(y, x % y);
}
 
int main(){
	Fcin;
	cin >> A >> B;
	GCD(A, B);
	cout << Ans;
	return 0;
}

很小,对每个物品用 set 处理前 大即可。

时间复杂度:

int main(){
	Fcin;
	cin >> n >> K;
	LL x;
	s.insert(0);
	for (LL i = 1; i <= n; i ++){
		cin >> x;
		auto it = s.begin();
		for (LL j = 1; j <= K; j ++){
			s.insert(*it + x);
			++ it;
		}
	}
	auto it = s.begin();
	for (LL j = 1; j <= K; j ++){
		++ it;
	}
	cout << *it << " ";
	return 0;
}

{{ vote && vote.total.up }}