vj2

https://vjudge.net/contest/651666#overview
https://www.cnblogs.com/Hamine/p/16661610.html

C - Express Mail Taking

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;   
const int maxn=2000005;
int a[maxn];
 
int main()
{
	/*更偏向于思维,只有在k柜和入口之间 且 
	离入口最近的快递对最小步行距离有帮助,因为此快递无需
	折返回k柜,取走后直接到入口,其他所有柜子都可以看成i与k之间的折返。*/
    int i,T,n,m,k,num;
    ll ans;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d%d",&n,&m,&k);
        ans=2ll*(k-1);                            //入口到k和最后的柜子所走距离
        num=k;
        for (i=1;i<=m;i++)
        {
            scanf("%d",&a[i]);
            ans+=2ll*abs(a[i]-k);
            if (a[i]<num) num=a[i];               //找到离入口最近且在入口和k柜之间的快递
        }
        if (num!=k) ans-=2ll*abs(num-k);          //总距离减去重复的距离(最后一个柜子已经计算)
        printf("%lld\n",ans);
     }
    return 0;
}

G - CCPC Training Class

题目

题目其实相当于j的前缀和i-j+1到i的后缀相等,我们考虑相同字母。
md又是思维,这谁知道是相同字母数?抽象......

#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
int main() {
    ios::sync_with_stdio(0);//实现优化cin和cout的速度 
    cin.tie(0), cout.tie(0);
    
    int T, tmp = 0;
    cin >> T;
    while (T--) {
        string s;
        cin >> s;
        int a[26] = { 0 };
        int len = s.length(), ans = 0;
        for (int i = 0; i < len; ++i) {
            ++a[s[i] - 'a'];//这里要仔细思考一下s[i]-'a'代表什么,答:数字(下标) 
            ans = max(ans, a[s[i] - 'a']);
        }
   		printf("Case #%d: %d\n",++tmp,ans);
    }
    return 0;
}

J - Reports

//判断是否存在数相邻且相等
#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

#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;
}

posted on 2024-09-08 13:24  Hoshino1  阅读(4)  评论(0编辑  收藏  举报