The 15th Jilin Provincial Collegiate Programming Contest
A. Random Number Checker
签到
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 1; i <= n; i ++ ) {
int a;
cin >> a;
if (a & 1) odd ++ ;
else even ++;
}
if (abs(even - odd) <= 1) cout << "Good" << endl;
else cout << "Not Good" << endl;
return 0;
}
B. Arithmetic Exercise
签到,模拟除法
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, k;
cin >> a >> b >> k;
if (a == b) {
cout << 1 << '.';
for (int i = 1; i <= k; i ++ )
cout << 0 << endl;
} else {
cout << 0 << '.';
int cnt = 1;
while (cnt != k) {
if (a < b) a *= 10;
cout << a / b;
a %= b;
cnt ++;
}
if (a < b) a *= 10;
int ans = a / b;
a %= b;
if (a < b) a *= 10;
int tmp = a / b;
if (tmp >= 5 && tmp <= 9) ans ++;
cout << ans << endl;
}
}
C. Random Number Generator
E. Great Detective TJC
签到
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int main() {
int t;
scanf("%d", &t);
while (t -- ) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) scanf("%d", a + i);
sort(a + 1, a + n + 1);
bool ok = 0;
for (int i = 1; i < n; i ++ ) {
if (a[i] + 1 == a[i + 1]) {
if ((a[i] ^ a[i + 1]) == 1) {
ok = 1;
break;
}
}
}
if (ok) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
G. Matrix Repair
思路
H. Visit the Park
思路
#include <bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
typedef pair<int, int> PII;
typedef vector<int> VI;
const int mod = 998244853;
const int N = 3e5 + 10;
map<PII, VI> mp;
map<PII, PII> edg;
int a[N];
LL qi(LL a) {
LL ans = 1;
int p = mod - 2;
while (p ) {
if (p & 1) ans = ans * a % mod;
a = a * a % mod;
p >>= 1;
}
return ans;
}
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= m; i ++ ) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
if (u < v) mp[MP(u, v)].PB(w);
else mp[MP(v, u)].PB(w);
}
LL ans = 0;
LL pos = 1;
LL t = qi(10);
bool ok = 1;
for (int i = 1; i < k - 1; i ++ ) pos = pos * 10 % mod;
for (int i = 1; i <= k; i ++ ) scanf("%d", a + i);
for (int i = 1; i < k; i ++ ) {
int u = min(a[i], a[i + 1]), v = max(a[i], a[i + 1]);
VI tmp = mp[MP(u, v)];
int len = tmp.size();
if (len == 0) {
ok = 0;
break;
}
LL key = qi(len);
for (int j = 0; j < len; j ++ ) {
ans = (ans + ((pos * tmp[j]) % mod * key) % mod) % mod;
}
pos = pos * t % mod;
}
if (ok) cout << ans << endl;
else cout << "Stupid Msacywy!" << endl;
return 0;
}
K. Bracket Sequence
思路
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
LL base[N], inv[N];
LL qi(LL a) {
LL ans = 1;
int p = mod - 2;
while (p) {
if (p & 1) ans = ans * a % mod;
a = a * a % mod;
p >>= 1;
}
return ans;
}
int main() {
int n, k;
cin >> n >> k;
LL b = 1;
for (int i = 1; i <= n; i ++ ) b = b * k % mod;
base[0] = 1;
for (int i = 1; i <= 2 * n; i ++ ) {
base[i] = base[i - 1] * i % mod;
if (i == n) inv[i] = qi(base[i]);
}
LL x = qi(n + 1);
cout << (((base[2 * n] * inv[n] % mod) * inv[n] % mod) * x % mod)* b % mod << endl;
return 0;
}
L. Suzuran Loves String
思路
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char str[N];
int main(){
int t;
scanf("%d", &t);
while (t -- ) {
int ans = 0;
scanf("%s", str);
int len = strlen(str);
bool ok = 1;
for (int i = 1; i < len; i ++ )
if (str[i] != str[i - 1]) {
ok = 0;
break;
}
if (ok) {
cout << len - 1 << endl;
continue;
}
int pos;
for (pos = 1; pos < len; pos ++ ) {
if (str[pos] != str[0]) {
break;
}
}
cout << 2 * len - pos << endl;
}
return 0;
}
M. Sequence
签到
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int mx = -1e9, mn = 1e9;
for (int i = 1; i <= n; i ++ ) {
int a;
cin >> a;
mn = min(mn, a), mx = max(mx, a);
}
cout << 1ll * n * (mx - mn) << endl;
return 0;
}