跳到正文

个人记录

USACO 2024 December Contest, Bronze

Eclatara约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年8月11日
篇幅
约 4 分钟

版本

  1. v1当前

T1:

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int js(int n){
	int sum=0,f=4,e=4;
	while(f<=n){
		f=f*10+5;
		e=e*10+9;
		if(f>n) break;
		sum+=(min(e,n)-f+1);
		f-=1;
	}
	return sum;
}
signed main(){
	ios::sync_with_stdio();
	cin.tie(),cout.tie();
	int q;
	cin>>q;
	while(q--){
		int x;
		cin>>x;
		cout<<js(x)<<"\n";
	}
	
}

T2:

C++
#include<bits/stdc++.h>
using namespace std;
const int N=1100;
int f[N][N],l[N][N],up[N][N];
int n,q,sum;
int main(){
	ios::sync_with_stdio();
	cin.tie(),cout.tie();
	cin>>n>>q;
	while(q--){
		int x,y,z;
		cin>>x>>y>>z;
		up[x][y]++,l[y][z]++,f[x][z]++;
		if(up[x][y]>=n) sum++;
		if(l[y][z]>=n) sum++;
		if(f[x][z]>=n) sum++;
		if(up[x][y]>n) up[x][y]=0;
		if(l[y][z]>n) l[y][z]=0;
		if(f[x][z]>n) f[x][z]=0;
		cout<<sum<<"\n";
	}
}

T3暴力:

C++
#include<bits/stdc++.h>
using namespace std;
set<string> final;
int n, f;
string st;
inline bool pd(string s) {
	return s[0]!= s[1] && s[1] == s[2];
}
inline set<string> find(string s, int f) {
	map<string, int> count; 
	int n = s.length();
	for (int i = 0; i < n - 2; ++i) {
		string sub = s.substr(i, 3);
		if (pd(sub)) 	count[sub]++;
	}
	set<string> v;
	for (auto p : count) 
		if (p.second >= f) 	v.insert(p.first);
	return v;
}
inline void fun(string s, int f) {
	set<string> all = find(s, f);
	int n = s.length();
	set<string> result = all;
	for (int i = 0; i < n; ++i) {
		string o = s;
		for (char ch = 'a'; ch <= 'z'; ch++) 
			if (ch!= s[i]) {
				o[i] = ch;
				set<string> newm = find(o, f);
				for (auto moo : newm) {
					bool exist = false;
					for (auto r : result) 
						if (r == moo) {
							exist = true;
							break;
						}
					if (!exist) 	result.insert(moo);	
				}
			}
	}
	final = result;
}
int main() {
	ios::sync_with_stdio();
	cin.tie(),cout.tie();
	cin >> n >> f >> st;
	fun(st, f);
	cout << final.size() << "\n";
	for (auto moo : final) 
		cout << moo << "\n";
}
原文