如果这篇博客帮助到你,可以请我喝一杯咖啡~
CC BY 4.0 (除特别声明或转载文章外)
Angle Beats
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2047;
struct Coord
{
int X, Y;
friend bool operator<(const Coord &p1, const Coord &p2)
{
if (p1.X < 0 || p1.X == 0 && p1.Y < 0)
return Coord{-p1.X, -p1.Y} < p2;
if (p2.X < 0 || p2.X == 0 && p2.Y < 0)
return p1 < Coord{-p2.X, -p2.Y};
return ll(p1.X) * p2.Y < ll(p1.Y) * p2.X;
}
} p[N], q[N], mp[N];
int main()
{
for (int n, qq; ~scanf("%d%d", &n, &qq);)
{
vector<int> ans(n);
for (int i = 0; i < n; ++i)
scanf("%d%d", &p[i].X, &p[i].Y);
for (int i = 0; i < qq; ++i)
{
scanf("%d%d", &q[i].X, &q[i].Y);
for (int j = 0; j < n; ++j)
mp[j] = {p[j].X - q[i].X, p[j].Y - q[i].Y};
sort(mp, mp + n);
for (int j = 0; j < n; ++j)
{
auto r = equal_range(mp, mp + n, Coord{q[i].Y - p[j].Y, p[j].X - q[i].X});
ans[i] += r.second - r.first;
}
ans[i] >>= 1;
}
for (int j = 0; j < n; ++j)
{
for (int i = 0; i < n; ++i)
mp[i] = {p[j].X - p[i].X, p[j].Y - p[i].Y};
swap(mp[j], mp[n - 1]);
sort(mp, mp + n - 1);
for (int i = 0; i < qq; ++i)
{
auto r = equal_range(mp, mp + n - 1, Coord{q[i].Y - p[j].Y, p[j].X - q[i].X});
ans[i] += r.second - r.first;
}
}
for (int i = 0; i < qq; ++i)
printf("%d\n", ans[i]);
}
}
Decimal
#include <bits/stdc++.h>
using namespace std;
int t, n;
int main(void)
{
cin >> t;
while (t--)
{
cin >> n;
while (n % 2 == 0)
n /= 2;
while (n % 5 == 0)
n /= 5;
if (n == 1)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
Forest Program
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5 + 10, maxm = 5e5 + 10;
const LL mod = 998244353ll;
int n, m, cur, tot, num, col;
int head[maxn], dfn[maxn], top[maxn], tak[maxm], vis[maxn], fa[maxn][25];
vector<int> res, v[maxn];
struct adj
{
int obj, val, next;
} e[2 * maxm];
void addedge(int x, int y, int val)
{
cur++;
e[cur].obj = y;
e[cur].val = val;
e[cur].next = head[x];
head[x] = cur;
}
void dfs(int k, int dad, int col)
{
fa[k][0] = dad;
vis[k] = 1;
dfn[k] = ++num;
v[col].push_back(k);
for (int i = head[k]; i != -1; i = e[i].next)
{
int to = e[i].obj, val = e[i].val;
if (!vis[to])
{
tak[val] = 1;
dfs(to, k, col);
}
}
}
void ready(int k)
{
for (int i = 1; i <= 20; i++)
for (int j = 0; j < v[k].size(); j++)
fa[j][i] = fa[fa[j][i - 1]][i - 1];
}
int lca(int x, int y)
{
int ans = 0;
if (dfn[x] > dfn[y])
swap(x, y);
for (int i = 20; i >= 0; i--)
if (dfn[fa[y][i]] > dfn[x])
{
ans += (1 << i);
y = fa[y][i];
}
ans++;
y = fa[y][0];
if (x == y)
return ans;
for (int i = 20; i >= 0; i--)
if (dfn[fa[x][i]] > dfn[y])
{
ans += (1 << i);
x = fa[x][i];
}
ans++;
return ans;
}
void dfs2(int k, int dad)
{
vis[k] = 1;
for (int i = head[k]; i != -1; i = e[i].next)
{
int to = e[i].obj, val = e[i].val;
if (!tak[val])
{
int x = lca(k, to);
res.push_back(x + 1);
tak[val] = 1;
}
if (!vis[to])
dfs2(to, k);
}
}
LL mul(LL a, int k)
{
if (k == 0)
return 1ll;
LL now = mul(a, k / 2);
now = now * now % mod;
if (k % 2 == 1)
now = now * a % mod;
return now;
}
int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
cur = 0;
col = 0;
num = 0;
res.clear();
for (int i = 1; i <= n; i++)
head[i] = -1, vis[i] = 0, dfn[i] = 0, v[i].clear();
for (int i = 1; i <= m; i++)
tak[i] = 0;
for (int i = 1; i <= m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
addedge(x, y, i);
addedge(y, x, i);
}
for (int i = 1; i <= n; i++)
if (!vis[i])
{
top[++col] = i;
dfs(i, i, col);
}
for (int i = 1; i <= col; i++)
ready(top[i]);
for (int i = 1; i <= n; i++)
vis[i] = 0;
for (int i = 1; i <= col; i++)
dfs2(top[i], top[i]);
LL ans = 1ll;
int tot = 0;
for (int i = 0; i < res.size(); i++)
{
ans = ans * (mul(2ll, res[i]) - 1 + mod) % mod;
tot += res[i];
}
ans = ans * mul(2ll, m - tot) % mod;
printf("%lld\n", ans);
}
return 0;
}
Invoker
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int main()
{
for (char s[N]; ~scanf("%s", s);)
{
int ans, f[2][3][3][3];
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 3; ++k)
for (int l = 0; l < 3; ++l)
f[1][j][k][l] = 3;
for (int i = 0, cur = 0, val, a[3] = {0, 1, 10}; s[i]; ++i, cur ^= 1)
{
if (s[i] == 'Y')
val = 3; //QQQ
else if (s[i] == 'V')
val = 12; //QQW
else if (s[i] == 'G')
val = 2; //QQE
else if (s[i] == 'C')
val = 30; //WWW
else if (s[i] == 'X')
val = 21; //QWW
else if (s[i] == 'Z')
val = 20; //WWE
else if (s[i] == 'T')
val = 0; //EEE
else if (s[i] == 'F')
val = 1; //QEE
else if (s[i] == 'D')
val = 10; //WEE
else if (s[i] == 'B')
val = 11; //QWE
ans = (i + 1) * 3;
for (int j = 0, t; j < 3; ++j)
for (int k = 0; k < 3; ++k)
for (int l = 0; l < 3; ++l)
{
f[cur][j][k][l] = 1e9;
if (val == a[j] + a[k] + a[l])
for (int j1 = 0; j1 < 3; ++j1)
for (int k1 = 0; k1 < 3; ++k1)
for (int l1 = 0; l1 < 3; ++l1)
{
if (j == j1 && k == k1 && l == l1)
t = 0;
else if (j == k1 && k == l1)
t = 1;
else if (j == l1)
t = 2;
else
t = 3;
f[cur][j][k][l] = min(f[cur][j][k][l], f[cur ^ 1][j1][k1][l1] + t);
}
ans = min(ans, f[cur][j][k][l]);
}
ans += i + 1;
}
printf("%d\n", ans);
}
}
MUV LUV EXTRA
#include <bits/stdc++.h>
#define maxn 10000004
#define ll long long
using namespace std;
char s[maxn], s2[maxn];
int p[maxn];
ll a, b, ans;
int main(void)
{
while (~scanf("%lld%lld%s", &a, &b, s + 1))
{
int l = strlen(s + 1), len2;
for (int i = l; s[i] != '.'; i--)
{
s2[l - i + 1] = s[i];
len2 = l - i + 1;
}
int j = 0;
ans = a - b;
for (int i = 1; i <= len2; i++)
p[i] = 0;
for (int i = 1; i < len2; i++)
{
while (j && s2[i + 1] != s2[j + 1])
j = p[j];
if (s2[i + 1] == s2[j + 1])
j++;
p[i + 1] = j;
ans = max(a * i - b * (i - p[i]), ans);
}
ans = max(a * len2 - b * (len2 - p[len2]), ans);
cout << ans << endl;
}
}