ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CCPC2020网络预选赛(vp)

2022-09-06 16:35:15  阅读:202  来源: 互联网

标签:CCPC2020 int LL 预选赛 long vp vector solve ans


比赛链接:

https://vjudge.net/contest/513012

C - Express Mail Taking

题意:

有 \(n\) 个箱子,分别在 \(a_1, a_2, ..., a_n\) 的位置,钥匙在 \(k\) 的位置,每去打开一个箱子前都要去拿一次钥匙,刚开始在 1 的位置,问最少花几步打开所有箱子后回到 1。

思路:

位置比 \(k\) 远的箱子所花的时间肯定是 \(2 * (a_i - k)\)。而在 1 到 \(k\) 之间的箱子,拿了钥匙去开最后一个箱子之后就可以直接回到起点了。
根据贪心的策略,肯定是最接近 1 的那个拿了之后直接回到起点,直接计算就行了。

代码:

#include <bits/stdc++.h>
using namespace std;
#define LL long long
void solve(){
	LL n, m, k;
	cin >> n >> m >> k;
	LL ans = k - 1, mn = 1e9;
	for (int i = 0; i < m; i ++ ){
		LL x;
		cin >> x;
		ans += 2 * abs(x - k);
		if (x < k){
			mn = min(mn, x);
		}
	}
	if (mn != 1e9){
		ans = ans - (k - mn) + mn - 1;
	}
	else{
		ans += k - 1;
	}
	cout << ans << "\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int T = 1;
	cin >> T;
	while(T -- ){
		solve();
	}
	return 0;
}

G - CCPC Training Class

题意:

给定一个字符串,判断哪个字母最多。

思路:

简单签到。

代码:

#include <bits/stdc++.h>
using namespace std;
#define LL long long
void solve(){
	string s;
	cin >> s;
	map <char, int> cnt;
	for (auto c : s)
		cnt[c] ++ ;
	int ans = 0;
	for (auto x : cnt)
		ans = max(ans, x.second);
	cout << ans << "\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int T = 1;
	cin >> T;
	for(int i = 1; i <= T; i ++ ){
		cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}

J - Reports

题意:

给定长为 \(n\) 的序列,判断有没有相邻且一样的元素。

思路:

简单签到。

代码:

#include <bits/stdc++.h>
using namespace std;
#define LL long long
void solve(){
	int n;
	cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; i ++ )
		cin >> a[i];
	for (int i = 1; i < n; i ++ ){
		if (a[i - 1] == a[i]){
			cout << "NO\n";
			return;
		}
	}
	cout << "YES\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int T = 1;
	cin >> T;
	while(T -- ){
		solve();
	}
	return 0;
}

K - 3x3 Convolution

题意:

给定一个 \(n * n\) 的矩阵 \(A\),3 * 3 的矩阵 \(K'\)。
\(K_{i, j} = \frac{K^{'}{i, j}}{\sum_{x = 1}^{3} \sum_{y = 1}^{3} K^{'}{x, y}}\)
定义 \(C(A, K)\) 为 \(C_{x, y} = \sum_{i = 1}^{min(n - x + 1, 3)} \sum_{j = 1}^{min(n - y + 1, 3} A_{x + i - 1, y + j - 1} K_{i, j}\)。
\(C^{m}(A, K) = C(C^{m - 1}(A, K), K), C^{1}(A, K) = C(A, K)\)。
求 \(\lim\limits_{t\rightarrow\infty}C^{t}(A, K)\)。

思路:

容易发现只有当 \(K'\) 矩阵为
x 0 0
0 0 0
0 0 0
时,最后才能得到 \(A\) 矩阵,否则,因为是趋向正无穷,所以矩阵最后每一个元素最后都会趋向 0。

代码:

#include <bits/stdc++.h>
using namespace std;
#define LL long long
void solve(){
	int n;
	cin >> n;
	vector < vector<int> > a(n + 1, vector<int>(n + 1));
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
			cin >> a[i][j];
	vector < vector<int> > k(4, vector<int>(4));
	int cnt1 = 0, cnt2 = 0;
	for (int i = 1; i <= 3; i ++ ){
		for (int j = 1; j <= 3; j ++ ){
			cin >> k[i][j];
			if (i == 1 && j == 1) cnt1 = k[i][j];
			else cnt2 += (k[i][j] > 0);
		}
	}
	if (cnt1 && !cnt2){
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= n; j ++ )
				cout << a[i][j] << " \n"[j == n];
	}
	else{
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= n; j ++ )
				cout << 0 << " \n"[j == n];
	}
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int T = 1;
	cin >> T;
	while(T -- ){
		solve();
	}
	return 0;
}

标签:CCPC2020,int,LL,预选赛,long,vp,vector,solve,ans
来源: https://www.cnblogs.com/Hamine/p/16661610.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有