A Jogging
没看清楚题 a不是移速 所以卡了十分钟 语法题
int main()
{
int a, b, c, d, e, f, x;
cin >> a >> b >> c >> d >> e >> f >> x; // 速度 b 和 e
int aa1 = b * a, bb1 = e * d;
int res1 = aa1 * (x / (a + c));
int t = x % (a + c);
if(t >= a) res1 += aa1;
else res1 += b * t;
int res2 = bb1 * (x / (d + f));
t = x % (d + f);
if(t >= d) res2 += bb1;
else res2 += e * t;
if(res1 > res2)
puts("Takahashi");
else if(res2 > res1)
puts("Aoki");
else
puts("Draw");
return 0;
}
B Perfect String
语法题 略
int main()
{
map<int, int> mp;
string s;
cin >> s;
bool ok = true;
int n = s.size();
rep(i, 0, n)
mp[s[i] - 'a'] ++;
for(auto x : mp)
if(x.second > 1)
ok = false;
int da = 0, xiao = 0;
rep(i, 0, n)
{
if(s[i] <= 'Z' && s[i] >= 'A') da ++;
if(s[i] <= 'z' && s[i] >= 'a') xiao ++;
}
if(da == 0 || xiao == 0) ok = false;
if(ok) puts("Yes");
else puts("No");
}
C Just K(dfs)
任意选择的字符串 请问他们中的个数为k的字符 数量的最大值
简单搜索题 对于每一个字符串 可以选或者不选 dfs一下 注意代码实现
int n, k;
int dfs(vector<string> &a, vector<string> chosen, int idx)
{
if(idx == a.size()) //当从所有字符串里选过之后
{
map<char, int> cnt;
for(auto it : chosen) //加起来
{
rep(i, 0, (int)it.size())
cnt[it[i]] ++;
}
int res = 0;
for(auto it : cnt)
if(it.second == k) res ++;
return res;
}
//搜索 要求最大值
int a1 = dfs(a, chosen, idx + 1); //不选
chosen.pb(a[idx]);
int a2 = dfs(a, chosen, idx + 1); //选
return max(a1, a2);
}
int main()
{
cin >> n >> k;
vector<string> a(n), b;
rep(i, 0, n)
cin >> a[i];
cout << dfs(a, b, 0);
}
D Index Trio(排列组合)
给定数组A 取一个三元组**(i, j, k)** 要求满足a_i / a_j = a_k
这题被我读假了( 需要考虑到一种情况 a_i = 1 且 j = k
处理约数即可
eg 1 8 8
(1, 2, 2)
(1, 3, 3)
(1, 2, 3)
(1, 3, 2)
i的位置跟j颠倒 x2
== 8
(1, 1, 1) +1
res = 9
由此可得核心代码
rep(i, 0, n)
cnt[a[i]] ++;
LL res = 0;
rep(i, 0, n)
{
for(int j = 1; j <= a[i] / j; j ++)
{
if(a[i] % j == 0)
{
res += 1LL * cnt[j] * cnt[a[i] / j];
if(j * j != a[i])
res += 1LL * cnt[j] * cnt[a[i] / j];
}
}
}