[补题] 2021华中师范大学程序设计新生赛

比赛链接:“菜鸟杯”华中师范大学程序设计新生赛(同步赛)_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ

I.宝藏欲しい

思路:

存储词典时,用map实现从古语言到现代语言的映射。

因为输出时,若无法实现翻译应输出“-1”,所以可以将已经完成翻译的古语言存入队列,若中途出现词典以外的古语言就做一个标志,若能成功翻译就逐一输出队首。

代码实现:

//#define LOCAL
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dd double
#define PII pair<int,int>
const dd eps = 1e-6;
const int mod = 19260817;
const int maxn = 110;

int n;
map<string,string> m;

signed main()
{
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	cin >> n;
	while(n--)
	{
		string a, b;
		cin >> a >> b;
		m[b] = a;
	}
	string s;
	queue<string> q;
	bool flag = 0;
	while(cin >> s)
	{
		if(m.count(s)) q.push(m[s]);
		else flag = 1;
	}
	if(flag) puts("-1");
	else
	{
		while(q.size())
		{
			printf("%s ", q.front().c_str());
			q.pop();
		}
	}

	return 0;
}

F.加入光荣的进化吧!

思路:

暴力枚举在小范围打表可以发现规律,若设X<=Y<=Z,则当且仅当X:Y:Z == 1:2:3时,满足题意。

于是可以很容易地写出代码。

代码实现:

//#define LOCAL
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dd double
#define PII pair<int,int>
const dd eps = 1e-6;
const int mod = 19260817;
const int maxn = 110;

int t, x, y, z, ans;

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

/* 打表 --> yyds */
// void yyds()
// {
// 	for(int i = 1; i <= 100; i++)
// 	{
// 		for(int j = 1; j <= 100; j++)
// 		{
// 			for(int k = 1; k <= 100; k++)
// 			{
// 				int d = gcd(gcd(i, j), k);
// 				if(i + j + k == i * j * k / d / d) 
// 					printf("%lld %lld %lld\n", i, j, k);
// 			}
// 		}
// 	}
// }

signed main()
{
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	//yyds();	
	cin >> t;
	while(t--)
	{
		scanf("%lld %lld %lld", &x, &y, &z);
		ans = min(x, min(y/2, z/3));
		ans += min(x, min(z/2, y/3));
		ans += min(y, min(x/2, z/3));
		ans += min(y, min(z/2, x/3));
		ans += min(z, min(x/2, y/3));
		ans += min(z, min(y/2, x/3));
		printf("%lld\n", ans);
	}
	
	return 0;
}

上一篇:[CQOI2007]余数求和(除法分块)


下一篇:[模板] 类欧几里得算法