A. 早餐
print("39.20")
B. 水論文
signed main()
{
int n,k;
cin >> n >> k;
set<int> st;
int ans = 0;
st.insert(n);
for(int i = 0, t = n; i <= k; i ++, t = sqrt(t))
{
st.insert(t);
if(st.count(t * t)) ans += 1;
else ans += k - i + 1;
if(t == 1) break;
}
cout << ans;
return 0;
}
C. nim遊戲?
import sys
input = lambda:sys.stdin.readline()
n = int(input())
for i in range(n):
print('lose')
D. 校驗和
#define int long long
void solve()
{
int n, k;
cin >> n >> k;
string s;
cin >> s;
bitset<N> a(s);
set<int> st;
unsigned int ans;
bool ok = 0;
int cnt = a.count();
for (int i = 0; i <= k; i++)
{
if (__builtin_popcount(i + cnt) == i)
st.insert(cnt + i);
}
if (st.size())
{
ans = *st.begin();
vector<int> res;
while(ans)
{
res.push_back(ans & 1);
ans >>= 1;
}
while (res.size() < k)
res.push_back(0);
if (res.size() > k)
cout << "None";
else
for (int i = res.size() - 1; i >= 0; i--)
cout << res[i];
cout << "\n";
}
else
cout << "None\n";
}
E. 數房子
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
// #define int long long
#define endl '\n'
#define all(_x) _x.begin(), _x.end()
#define range(_x, _st, _ed) (_x.begin() + _st), (_x.begin() + _ed)
#define rep(_x, _y, _z) for (int _x = _y; _x < _z; _x++)
#define matrix(_x, _y, _z) vector<vector<int>>(_x, vector<int>(_y, _z))
#define debug(_x) cout << #_x << '=' << _x << endl
typedef long long i64;
typedef pair<int, int> pii;
typedef vector<vector<int>> mat;
constexpr int N = 2e5 + 10;
// dont use umap!!!
const double eps = 1e-12;
const double pi = acos(-1);
int cmp(double x, double y)
{
if (fabs(x - y) < eps)
return 0;
return x > y ? 1 : -1;
}
int sgn(double x)
{
if (fabs(x) < eps)
return 0;
return x > 0 ? 1 : -1;
}
template <typename T>
struct Point
{
T x, y;
T cross(Point p1, Point p2)
{
return p1.x * p2.y - p2.x * p1.y;
}
Point operator-(Point p)
{
return {x - p.x, y - p.y};
}
Point operator+(Point p)
{
return {x + p.x, y + p.y};
}
Point operator*(double p)
{
return {x * p, y * p};
}
T operator*(Point p)
{
return cross(*this, p);
}
Point operator/(double p)
{
return {x / p, y / p};
}
bool operator==(Point p)
{
return (!cmp(x, p.x)) && (!cmp(y, p.y));
}
bool operator!=(Point p)
{
return !(*this == p);
}
Point rotate(double p)
{
return {x * cos(p) - y * sin(p), x * sin(p) + y * cos(p)};
}
};
typedef Point<double> point;
struct line
{
point p, v;
};
double dot(point p, point v)
{
return p.x * v.x + p.y * v.y;
}
double area(point p, line l)
{
return (p - l.p) * (l.v - l.p);
}
double dist(point p1, point p2)
{
return hypot(p1.x - p2.x, p1.y - p2.y);
}
point cross_point(line l1, line l2)
{
auto p = l1.p, v = l1.v, q = l2.p, w = l2.v;
auto u = p - q;
double t = w * u / (v * w);
return p + v * t;
}
signed main()
{
IOS;
int n;
cin >> n;
vector<point> ps(n);
for (int i = 0; i < n; i++)
{
cin >> ps[i].x >> ps[i].y;
}
// e
// a /\ d
// | |
// b -- c
int cnt = 0;
for (int a = 0; a < n; a++) // 列舉a
for (int b = 0; b < n; b++) // 列舉b
{
for (int c = 0; c < n; c++) // 列舉c
{
if (area(ps[c], {ps[a], ps[b]}) < 0 && sgn(dot(ps[c] - ps[b], ps[a] - ps[b])) == 0) // 如果c在ab直線的右邊且ab和bc垂直
{
for (int d = 0; d < n; d++) // 列舉d
{
if (sgn((ps[d] - ps[c]) * (ps[a] - ps[b])) == 0 &&
sgn((ps[d] - ps[a]) * (ps[c] - ps[b])) == 0) // 如果dc和ab平行而且ad和bc平行
{
for (int e = 0; e < n; e++) // 列舉e
{
// e在直線ab右邊,直線dc左邊且在ad上方
if (sgn(dot(ps[e] - ps[a], ps[b] - ps[a])) < 0 && sgn(dot(ps[e] - ps[d], ps[c] - ps[d])) < 0 && sgn(area(ps[e], {ps[d], ps[c]})) > 0 && sgn(area(ps[e], {ps[a], ps[b]})) < 0 && sgn(dist(ps[e], ps[a]) - dist(ps[e], ps[d])) == 0)
{
// cout << a << " " << b << " " << c << " " << d << " " << e << '\n';
cnt++;
}
}
}
}
}
}
}
cout << cnt;
return 0;
}
F. 相遇
vector<vector<int>> edge(N);
int fa[N][21], dep[N], L[N], R[N];
int now = 0;
void dfs(int x, int f)
{
dep[x] = dep[f] + 1;
fa[x][0] = f;
L[x] = ++now; // 記錄當前子樹dfs序的左端點
for (int i = 1; i < 20; i++)
{
fa[x][i] = fa[fa[x][i - 1]][i - 1];
}
for (auto v : edge[x])
{
if (v == f)
continue;
dfs(v, x);
}
R[x] = now; // 記錄當前子樹dfs序的右端點
}
int lca(int x, int y)
{
if (dep[x] < dep[y])
swap(x, y);
for (int i = 19; i >= 0; i--)
{
if (dep[x] - (1 << i) >= dep[y])
{
x = fa[x][i];
}
}
if (x == y)
return x;
for (int i = 19; i >= 0; i--)
{
if (fa[x][i] != fa[y][i])
{
x = fa[x][i];
y = fa[y][i];
}
}
return fa[x][0];
}
int dis(int x, int y)
{
return dep[x] + dep[y] - 2 * dep[lca(x, y)];
}
int getfa(int x, int k) // 求x節點向上k級的祖先節點
{
for (int i = 19; i >= 0; i--)
{
if ((1 << i) <= k)
{
k -= (1 << i);
x = fa[x][i];
}
}
return x;
}
int n, m;
int a[N][2]; // 記錄點對
int c[N]; // 差分陣列
signed main()
{
IOS;
cin >> n >> m;
for (int i = 1; i < n; i++)
{
int x, y;
cin >> x >> y;
edge[x].push_back(y);
edge[y].push_back(x);
}
for (int i = 1; i <= m; i++)
cin >> a[i][0] >> a[i][1];
dfs(1, 0);
auto check = [&](int mid)
{
for (int i = 1; i <= m; i++)
{
if (dis(a[i][0], a[i][1]) <= mid)
{
c[1] += 2; // 這兩個點都可以滿足,在差分陣列整體+2
continue;
}
int anc = lca(a[i][0], a[i][1]);
for (int j = 0; j < 2; j++) // 分別處理兩個點
{
int len = dis(anc, a[i][j]); // 得到其中一點到點對lca的距離
if (len > mid) // 如果大於答案
{
// 說明首都在當前節點mid級祖先節點的子樹
int p = getfa(a[i][j], mid);
c[L[p]] += 1; // 對應的答案區間+1
c[R[p] + 1] -= 1;
}
else // 如果小於等於答案
{
// 說明首都在另外一點的 兩點距離-mid-1 級祖先的子樹上
int p = getfa(a[i][j ^ 1], dis(a[i][0], a[i][1]) - mid - 1);
// 對應的答案區間+1
c[1] += 1;
c[L[p]] -= 1;
c[R[p] + 1] += 1;
}
}
}
int now = 0;
int mx = 0;
for (int i = 1; i <= n; i++)
{
now += c[i]; // 列舉每個節點的答案區間交集
mx = max(mx, now);
c[i] = 0; // 初始化差分陣列
}
return mx >= 2 * m; // 如果存在一個滿足所有點條件的首都,則說明mid可行
};
int l = 0, r = n;
while (l < r)
{
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l;
}
G. 生成括號序列
typedef long long i64;
const int mod = 998244353;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
string s;
cin >> s;
int k = 0;
vector<int> v;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == ')')
{
if (s[i - 1] == '(') // 如果是小括號
k++;
else // 如果是大括號
v.push_back(k);
}
}
i64 ans = 1;
for (int i = v.size() - 1, j = 0; i >= 0; i--)
{
ans = ans * (k - v[i] + 1 + j) % mod;
j++;
}
cout << ans << endl;
return 0;
}