0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +00:00

第三届“图灵杯”趣味网络邀请赛 (中级)

This commit is contained in:
Baoshuo Ren 2021-08-08 16:35:00 +08:00 committed by Baoshuo Ren
parent 66dedd2b6f
commit 8ba6ad7ebc
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
3 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;
int n, p;
string s;
stack<pair<char, int>> st;
int main() {
cin >> n >> p >> s;
s = ' ' + s;
for (int i = 1; i < s.size(); i++) {
if (s[i] == '{') {
st.push(make_pair(s[i], i));
} else if (st.top().second == p) {
cout << i << endl;
exit(0);
} else if (i == p) {
cout << st.top().second << endl;
exit(0);
} else {
st.pop();
}
}
return 0;
}

View File

@ -0,0 +1,52 @@
#include <bits/stdc++.h>
using namespace std;
int t, a, cnt, prime[100005];
bool flag, is_prime[1000005];
int eratosthenes(int n) {
int p = 0;
for (int i = 0; i <= n; i++) is_prime[i] = 1;
is_prime[0] = is_prime[1] = 0;
for (int i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = i;
if (1ll * i * i <= n) {
for (int j = i * i; j <= n; j += i) {
is_prime[j] = 0;
}
}
}
}
return p;
}
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int main() {
cin >> t;
cnt = eratosthenes(1000000);
while (t--) {
flag = false;
cin >> a;
for (int i = 0; i < cnt; i++) {
if (binpow(a, prime[i], 10) % 10 == binpow(prime[i], a, 10) % 10) {
cout << prime[i] << endl;
flag = true;
break;
}
}
if (!flag) cout << -1 << endl;
}
return 0;
}

View File

@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans, cnt, x;
pair<long long, long long> q[300005];
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
return (a.first - b.first) * (a.second + b.second) > (a.first + b.first) * (a.second - b.second);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> q[i].first >> q[i].second;
}
sort(q, q + n, cmp);
for (int i = 0; i < n; i++) {
cnt += abs(2 * q[i].second * x + q[i].second * q[i].first);
x += q[i].first;
}
ans = max(ans, cnt);
x = 0;
cnt = 0;
for (int i = n - 1; i >= 0; i--) {
cnt += abs(2 * q[i].second * x + q[i].second * q[i].first);
x += q[i].first;
}
ans = max(ans, cnt);
cout << ans << endl;
return 0;
}