该写高数了唉
最近读题有点费劲
摆摆摆
A Leyland Number
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int qmi(int a, int b)
{
int res = 1;
while(b)
{
if(b & 1)res=res* a;
a = a * a;
b >>= 1;
}
return res;
}
signed main()
{
int a = read(), b = read();
cout << qmi(a, b) + qmi(b, a);
return 0;
}
B Longest Palindrome
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int manacher(string str)
{
if(!str.length()) return 0;
int l=(int)(str.length()*2+1);
char *s=new char[l];//记录回文子串
int *p=new int[l];//记录每个位置最大回文半径
int r,c,index,mx;
r=c=-1;
index=mx=0;
for(int i=0;i<l;i++) s[i]=i&1?str[index++]:'#';
for(int i=0;i<l;i++)
{
p[i]=r>i?min(r - i, p[2 * c - i]):1;
while(i+p[i]<l&&i-p[i]>-1)
{
if(s[i+p[i]]==s[i-p[i]]) p[i]++;
else break;
}
if(i+p[i]>r)
{
r=i+p[i];
c=i;
}
mx=max(mx,p[i]);
}
delete[] s;
delete[] p;
return mx-1;
}
signed main()
{
string s;
cin >> s;
cout << manacher(s);
return 0;
}
C Slot Strategy 2 (Easy)
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
signed main()
{
int n = read();
string strs[3];
cin >> strs[0] >> strs[1] >> strs[2];
int res = 0x3f3f3f3f;
for(int i = 0; i < 3 * n; i++)
{
for(int j = 0; j < 3 * n; j++)
{
if(j != i && strs[0][i % n] == strs[1][j % n])
{
for(int k = 0; k < 3 * n; k++)
{
if(k != i && k != j && strs[2][k % n] == strs[1][j % n])
{
res = min(res,max({ i, j, k}));
}
}
}
}
}
if(res == 0x3f3f3f3f) cout << -1 << endl;
else cout << res <<endl;
return 0;
}
D Relative Position
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int N = 2e5 + 10, M = N << 1;
int h[N], e[M], ne[M], idx;
pair<int, int> w[M], ans[N];
bool st[N];
void add(int a, int b, pair<int, int> c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u, int f)
{
st[u] = true;
for(int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if(j == f || st[j]) continue;
ans[j].first = ans[u].first + w[i].first;
ans[j].second = ans[u].second + w[i].second;
dfs(j, u);
}
}
signed main()
{
int n = read(), m = read();
int x = 0, y = 0;
memset(h, -1, sizeof h);
for(int i = 0; i < m; i++)
{
int a = read(), b = read(), x = read(), y = read();
add(a, b, {x, y});
add(b, a, {-x, -y});
}
dfs(1, 0);
for(int i = 1; i <= n; i++)
{
if(st[i])
{
cout << ans[i].first << " " << ans[i].second << "\n";
}
else cout << "undecidable\n";
}
return 0;
}
E Somen Nagashi
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
signed main()
{
int n = read(), m = read();
priority_queue<int, vector<int>, greater<int>> q;
for(int i = 1; i <= n; i++)
{
q.push(i);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> heap;
vector<int> ans(n + 1);
for(int i = 0; i < m; i++)
{
int t = read(), w = read(), s = read();
while(heap.size() && t >= heap.top().first)
{
q.push(heap.top().second);
heap.pop();
}
if(q.empty()) continue;
auto ver = q.top();
q.pop();
ans[ver] += w;
//cout << t << " " << ver << " " << w << endl;
heap.push({t + s, ver});
}
for(int i = 1; i <= n; i++) cout << ans[i] << endl;
return 0;
}