在 AtCoder,排位分前 名的选手用户名会显示一个金冠,排位分最高的选手会显示一个铂冠。
在这场比赛开始前,前 名的用户和对应的排位分为:
tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481
给你一个这之中的用户名,请输出他的排位分。
#include <bits/stdc++.h>
using namespace std;
string names[10] = {
"tourist",
"ksun48",
"Benq",
"Um_nik",
"apiad",
"Stonefeang",
"ecnerwala",
"mnbvmar",
"newbiedmy",
"semiexp"};
int rating[10] = {3858, 3679, 3658, 3648, 3638, 3630, 3613, 3555, 3516, 3481};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
for (int i = 0; i < 10; i++)
if (names[i] == s)
cout << rating[i] << "\n";
return 0;
}
给定一个正整数 ,打印一个长度为 的字符串 ,这个字符串按照如下方式生成:
对于每个 ,
- 如果 存在某个 的因子 ,并且 是 的倍数。那么 就是满足这个条件的最小的 (
1
,2
,...,9
之一)。- 否则, 为
-
。
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i <= n; i++)
{
s += "-";
for (int j = 1; j <= 9; j++)
{
if (n % j == 0 && i % (n / j) == 0)
{
s[i] = '0' + j;
break;
}
}
}
cout << s << "\n";
return 0;
}
给定一个 的网格,每个网格里有一个 的数字。第 行第 列的格子里的数字是 。
不同的格子里可能会有同样的数字。但是任意一条线(纵向、横向或斜向)上连续的三个格子里不会完全相同。也就是说下面的四种情况的任何一种都不会成立:
Taka 会随机顺序去看一遍所有格子里的数(每个格子只看一次),一旦他发现某条线(纵向、横向或斜向)的三个元素出现了下面的情况他就会很失望:
请找到他不会失望的概率。
#include <bits/stdc++.h>
using namespace std;
int a[10];
int id[10];
// line[1~3]: row 1~3
// line[4~6]: col 1~3
// line[7]: i+j == 4
// line[8]: i-j == 0
vector<int> line[10];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
for (int i = 1; i <= 9; i++)
{
cin >> a[i];
id[i] = i;
}
int all = 0;
int good = 0;
do
{
for (int i = 1; i <= 8; i++)
line[i].clear();
for (int i = 1; i <= 9; i++)
{
int now = a[id[i]];
int x = (id[i] - 1) / 3 + 1;
int y = (id[i] - 1) % 3 + 1;
line[x].push_back(now);
line[y + 3].push_back(now);
if (x + y == 4)
line[7].push_back(now);
if (x - y == 0)
line[8].push_back(now);
}
bool flag = true;
for (int i = 1; i <= 8; i++)
{
if (line[i][0] == line[i][1])
{
flag = false;
break;
}
}
good += flag;
all++;
} while (next_permutation(id + 1, id + 9 + 1));
cout << fixed << setprecision(10) << (double)good / all << "\n";
return 0;
}
Taka 想在窗口中显示一个由 个单词组成的句子。所有单词都有同样的高度,第 个单词的宽度为 。
窗口中的单词之间间隔宽度为 。当整个窗口的宽度为 时,会按下面的方式显示:
Taka 想要这个句子显示的行数小于等于 ,请问宽度 至少是多少。
一眼二分答案。
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
int a[212345];
bool check(int w)
{
int row = 1;
int now = a[1];
for (int i = 2; i <= n; i++)
{
if (now + a[i] + 1 > w)
{
row++;
now = a[i];
}
else
now += a[i] + 1;
}
return row <= m;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i];
int l = 0;
for (int i = 1; i <= n; i++)
l = max(l, a[i]);
int r = 0;
for (int i = 1; i <= n; i++)
r += a[i] + 1;
int ans = r;
while (l <= r)
{
int mid = (l + r) / 2;
if (check(mid))
{
ans = mid;
r = mid - 1;
}
else
{
l = mid + 1;
}
}
cout << ans << "\n";
return 0;
}
Taka 初始在自己的房子,并且想要去访问 Aoki 的房子。
两个房子之间有 个车站,编号从 到 。Taka 可以通过下面的方式移动:
有 次提问,第 次询问会给你一个 ,并询问如果 Taka 在 这个时间离开家,最早什么时间会到达 Aoki 的家。
合理猜一个结论:“周期为所有 的 \lcm”,然后就过了。
完整推理证明以后补。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 100000;
int n, x, y;
int p[MAXN + 5], t[MAXN + 5];
int Q, q;
int ans[1000];
int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a, int b)
{
return a / gcd(a, b) * b;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x >> y;
int pp = 1;
for (int i = 1; i <= n - 1; i++)
{
cin >> p[i] >> t[i];
pp = lcm(pp, p[i]);
}
for (int i = 0; i <= pp - 1; i++)
{
ans[i] = i + x;
for (int j = 1; j <= n - 1; j++)
{
if (ans[i] % p[j] != 0)
ans[i] += (p[j] - ans[i] % p[j]);
ans[i] += t[j];
}
ans[i] += y;
}
cin >> Q;
while (Q--)
{
cin >> q;
cout << q / pp * pp + ans[q % pp] << "\n";
}
return 0;
}