0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 17:58:48 +00:00

fix: format all cpp codes

This commit is contained in:
Baoshuo Ren 2021-11-19 17:01:13 +08:00 committed by Baoshuo Ren
parent 9f0d4bedd0
commit f0aae01668
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
170 changed files with 586 additions and 728 deletions

View File

@ -27,8 +27,8 @@ void dfs(int u) {
int main() { int main() {
cin >> n; cin >> n;
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
for(int j = 0 ; j < n ; j++) { for (int j = 0; j < n; j++) {
g[i][j] = '.'; g[i][j] = '.';
} }
} }

View File

@ -8,7 +8,8 @@ string s;
int main() { int main() {
cin >> s; cin >> s;
sort(s.begin(), s.end()); sort(s.begin(), s.end());
do ans++; do
ans++;
while (next_permutation(s.begin(), s.end())); while (next_permutation(s.begin(), s.end()));
cout << ans << endl; cout << ans << endl;
return 0; return 0;

View File

@ -45,8 +45,10 @@ void modify(int u, int x, int v) {
return; return;
} }
int mid = tr[u].l + tr[u].r >> 1; int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) modify(u << 1, x, v); if (x <= mid)
else modify(u << 1 | 1, x, v); modify(u << 1, x, v);
else
modify(u << 1 | 1, x, v);
pushup(u); pushup(u);
} }

View File

@ -1,3 +1,5 @@
#include<stdio.h> #include <stdio.h>
char s[]="#include<stdio.h>%cchar%cs[]=%c%s%c%c%cint main(){printf(s,10,32,34,s,34,59,10);}"; char s[] = "#include<stdio.h>%cchar%cs[]=%c%s%c%c%cint main(){printf(s,10,32,34,s,34,59,10);}";
int main(){printf(s,10,32,34,s,34,59,10);} int main() {
printf(s, 10, 32, 34, s, 34, 59, 10);
}

View File

@ -1,6 +1,7 @@
#include "interaction.h"
#include <bits/stdc++.h> #include <bits/stdc++.h>
#include "interaction.h"
using namespace std; using namespace std;
int n; int n;

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -10,8 +10,8 @@ int main() {
s += t; s += t;
cin >> t; cin >> t;
s += t; s += t;
for(int i = 0 ; i < 9 ; i++) { for (int i = 0; i < 9; i++) {
if(s[i] != s[8-i]) { if (s[i] != s[8 - i]) {
cout << "NO" << endl; cout << "NO" << endl;
return 0; return 0;
} }

View File

@ -1,11 +1,11 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
int t, a, b; int t, a, b;
cin >> t; cin >> t;
while(t--) { while (t--) {
cin >> a >> b; cin >> a >> b;
cout << a + b - (a & b) * 2 << endl; cout << a + b - (a & b) * 2 << endl;
} }

View File

@ -25,11 +25,9 @@ int main() {
} }
if (flag) { if (flag) {
cout << "No" << endl; cout << "No" << endl;
} } else {
else {
cout << "Yes" << endl; cout << "Yes" << endl;
} }
} }
return 0; return 0;
} }

View File

@ -9,12 +9,11 @@ int main() {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (i >= 3) { if (i >= 3) {
cin >> t; cin >> t;
} } else {
else {
t = a[i]; t = a[i];
} }
if (t % 2 != o) { if (t % 2 != o) {
cout << i+1 << endl; cout << i + 1 << endl;
return 0; return 0;
} }
} }

View File

@ -10,11 +10,9 @@ int main() {
// abc abd acd bcd // abc abd acd bcd
if (a + b > c && a + c > b && b + c > a || a + b > d && a + d > b && b + d > a || a + c > d && a + d > c && c + d > a || b + c > d && b + d > c && c + d > b) { if (a + b > c && a + c > b && b + c > a || a + b > d && a + d > b && b + d > a || a + c > d && a + d > c && c + d > a || b + c > d && b + d > c && c + d > b) {
cout << "TRIANGLE" << endl; cout << "TRIANGLE" << endl;
} } else if (a + b >= c && a + c >= b && b + c >= a || a + b >= d && a + d >= b && b + d >= a || a + c >= d && a + d >= c && c + d >= a || b + c >= d && b + d >= c && c + d >= b) {
else if (a + b >= c && a + c >= b && b + c >= a || a + b >= d && a + d >= b && b + d >= a || a + c >= d && a + d >= c && c + d >= a || b + c >= d && b + d >= c && c + d >= b) {
cout << "SEGMENT" << endl; cout << "SEGMENT" << endl;
} } else {
else {
cout << "IMPOSSIBLE" << endl; cout << "IMPOSSIBLE" << endl;
} }
return 0; return 0;

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -10,20 +10,18 @@ int main() {
int n; int n;
pair<int, int> p[200005]; pair<int, int> p[200005];
cin >> n; cin >> n;
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second; cin >> p[i].first >> p[i].second;
} }
sort(p, p+n, cmp); sort(p, p + n, cmp);
int tv1 = -1, tv2 = -1; int tv1 = -1, tv2 = -1;
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
if(p[i].first > tv1) { if (p[i].first > tv1) {
tv1 = p[i].second; tv1 = p[i].second;
} } else {
else { if (p[i].first > tv2) {
if(p[i].first > tv2) {
tv2 = p[i].second; tv2 = p[i].second;
} } else {
else {
cout << "NO" << endl; cout << "NO" << endl;
return 0; return 0;
} }

View File

@ -23,8 +23,7 @@ int main() {
for (int j = 2; j <= by; j++) { for (int j = 2; j <= by; j++) {
if (b[i][j]) { if (b[i][j]) {
continue; continue;
} } else {
else {
f[i][j] = max(f[i][j], f[i - 1][j] + f[i][j - 1]); f[i][j] = max(f[i][j], f[i - 1][j] + f[i][j - 1]);
} }
} }

View File

@ -18,14 +18,12 @@ string add(string b, int k) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (isdigit(a[i])) { if (isdigit(a[i])) {
numa[len - i] = a[i] - '0'; numa[len - i] = a[i] - '0';
} } else {
else {
numa[len - i] = a[i] - 'A' + 10; numa[len - i] = a[i] - 'A' + 10;
} }
if (isdigit(b[i])) { if (isdigit(b[i])) {
numb[len - i] = b[i] - '0'; numb[len - i] = b[i] - '0';
} } else {
else {
numb[len - i] = b[i] - 'A' + 10; numb[len - i] = b[i] - 'A' + 10;
} }
} }

View File

@ -5,25 +5,25 @@ using namespace std;
int n, l1, l2, a[100005], d1[100005], d2[100005]; int n, l1, l2, a[100005], d1[100005], d2[100005];
int main() { int main() {
while (cin >> a[++n]); while (cin >> a[++n])
;
n--; n--;
d1[++l1] = d2[++l2] = a[1]; d1[++l1] = d2[++l2] = a[1];
for (int i = 2; i <= n; i++) { for (int i = 2; i <= n; i++) {
if (d1[l1] >= a[i]) { if (d1[l1] >= a[i]) {
d1[++l1] = a[i]; d1[++l1] = a[i];
} } else {
else {
int* it = upper_bound(d1 + 1, d1 + 1 + l1, a[i], greater<int>()); int* it = upper_bound(d1 + 1, d1 + 1 + l1, a[i], greater<int>());
*it = a[i]; *it = a[i];
} }
if (d2[l2] < a[i]) { if (d2[l2] < a[i]) {
d2[++l2] = a[i]; d2[++l2] = a[i];
} } else {
else {
int* it = lower_bound(d2 + 1, d2 + 1 + l2, a[i], less<int>()); int* it = lower_bound(d2 + 1, d2 + 1 + l2, a[i], less<int>());
*it = a[i]; *it = a[i];
} }
} }
cout << l1 << endl << l2 << endl; cout << l1 << endl
<< l2 << endl;
return 0; return 0;
} }

View File

@ -14,8 +14,7 @@ int main() {
for (int j = 0; j <= n; j++) { for (int j = 0; j <= n; j++) {
if (j >= v[i]) { if (j >= v[i]) {
f[i][j] = max(f[i - 1][j], f[i - 1][j - v[i]] + w[i]); f[i][j] = max(f[i - 1][j], f[i - 1][j - v[i]] + w[i]);
} } else {
else {
f[i][j] = f[i - 1][j]; f[i][j] = f[i - 1][j];
} }
} }

View File

@ -21,8 +21,7 @@ int main() {
if (n == 5 && m == 3) { if (n == 5 && m == 3) {
printf("78 4\n2783 95\n9323 89\n7972 88\n2538 78"); printf("78 4\n2783 95\n9323 89\n7972 88\n2538 78");
return 0; return 0;
} } else if (n == 87 && m == 35) {
else if (n == 87 && m == 35) {
printf("77 52\n5081 100\n8736 100\n2855 99\n6347 99\n3191 96\n6090 95\n9917 95\n1832 94\n3169 92\n3404 92\n6982 92\n9494 92\n3535 91\n8569 91\n9319 90\n1896 89\n9701 89\n3321 88\n6017 88\n6158 88\n6361 88\n7353 88\n4011 87\n4967 87\n8017 87\n8944 87\n4746 86\n7313 86\n7486 86\n9250 86\n4808 85\n4982 85\n6979 85\n7327 85\n7887 85\n7651 84\n8456 84\n8850 84\n1423 83\n7889 82\n6891 81\n8779 81\n1174 80\n4116 80\n4141 80\n5473 80\n7172 79\n8562 79\n5392 78\n4301 77\n4551 77\n5498 77\n"); printf("77 52\n5081 100\n8736 100\n2855 99\n6347 99\n3191 96\n6090 95\n9917 95\n1832 94\n3169 92\n3404 92\n6982 92\n9494 92\n3535 91\n8569 91\n9319 90\n1896 89\n9701 89\n3321 88\n6017 88\n6158 88\n6361 88\n7353 88\n4011 87\n4967 87\n8017 87\n8944 87\n4746 86\n7313 86\n7486 86\n9250 86\n4808 85\n4982 85\n6979 85\n7327 85\n7887 85\n7651 84\n8456 84\n8850 84\n1423 83\n7889 82\n6891 81\n8779 81\n1174 80\n4116 80\n4141 80\n5473 80\n7172 79\n8562 79\n5392 78\n4301 77\n4551 77\n5498 77\n");
return 0; return 0;
} }

View File

@ -8,10 +8,9 @@ int main() {
cin >> k >> c; cin >> k >> c;
for (int i = 0; i < c.size(); i++) { for (int i = 0; i < c.size(); i++) {
t = (k[i % k.size()] & 31) - 1; t = (k[i % k.size()] & 31) - 1;
if((c[i] & 31) - t > 0) { if ((c[i] & 31) - t > 0) {
c[i] = c[i] - t; c[i] = c[i] - t;
} } else {
else {
c[i] = c[i] - t + 26; c[i] = c[i] - t + 26;
} }
} }

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -18,8 +18,8 @@ struct node {
}; };
bool cmp(node a, node b) { bool cmp(node a, node b) {
if(a.all == b.all) { if (a.all == b.all) {
if(a.chinese == b.chinese) { if (a.chinese == b.chinese) {
return a.id < b.id; return a.id < b.id;
} }
return a.chinese > b.chinese; return a.chinese > b.chinese;
@ -31,13 +31,13 @@ int main() {
int n; int n;
node a[305]; node a[305];
cin >> n; cin >> n;
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
cin >> a[i].chinese >> a[i].math >> a[i].english; cin >> a[i].chinese >> a[i].math >> a[i].english;
a[i].all = a[i].chinese + a[i].math + a[i].english; a[i].all = a[i].chinese + a[i].math + a[i].english;
a[i].id = i+1; a[i].id = i + 1;
} }
sort(a, a+n, cmp); sort(a, a + n, cmp);
for(int i = 0 ; i < 5 ; i++) { for (int i = 0; i < 5; i++) {
cout << a[i].id << ' ' << a[i].all << endl; cout << a[i].id << ' ' << a[i].all << endl;
} }
return 0; return 0;

View File

@ -15,8 +15,7 @@ int main() {
l++; l++;
r--; r--;
ans++; ans++;
} } else {
else {
r--; r--;
ans++; ans++;
} }

View File

@ -14,15 +14,13 @@ int main() {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (a[i] > r) { if (a[i] > r) {
p += a[i] - r; p += a[i] - r;
} } else if (a[i] < l) {
else if (a[i] < l) {
q += l - a[i]; q += l - a[i];
} }
} }
if (n * r < sum) { if (n * r < sum) {
cout << -1 << endl; cout << -1 << endl;
} } else {
else {
cout << max(p, q) << endl; cout << max(p, q) << endl;
} }
return 0; return 0;

View File

@ -1,23 +1,23 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
long long n, m, a[2005][2005], f[2005][2005]; long long n, m, a[2005][2005], f[2005][2005];
cin >> n >> m; cin >> n >> m;
for(int i = 1 ; i <= m ; i++) { for (int i = 1; i <= m; i++) {
for(int j = 1 ; j <= n ; j++) { for (int j = 1; j <= n; j++) {
cin >> a[j][i]; cin >> a[j][i];
} }
} }
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
f[i-1][0] = f[i-1][m]; f[i - 1][0] = f[i - 1][m];
for(int j = 1 ; j <= m ; j++) { for (int j = 1; j <= m; j++) {
f[i][j] = a[i][j] + min(f[i-1][j], f[i-1][j-1]); f[i][j] = a[i][j] + min(f[i - 1][j], f[i - 1][j - 1]);
} }
} }
long long ans = f[n][1]; long long ans = f[n][1];
for(int i = 2 ; i <= m ; i++) { for (int i = 2; i <= m; i++) {
ans = min(ans, f[n][i]); ans = min(ans, f[n][i]);
} }
cout << ans << endl; cout << ans << endl;

View File

@ -14,8 +14,7 @@ int main() {
n = unique(a, a + n) - a; n = unique(a, a + n) - a;
if (k >= n) { if (k >= n) {
cout << "NO RESULT" << endl; cout << "NO RESULT" << endl;
} } else {
else {
cout << a[--k]; cout << a[--k];
} }
return 0; return 0;

View File

@ -1,6 +1,6 @@
// R38820772 // R38820772
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -9,12 +9,12 @@ int n, a[1005];
int main() { int main() {
cin >> n; cin >> n;
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
cin >>a[i]; cin >> a[i];
} }
for(int i = 1 ; i < n ; i++) { for (int i = 1; i < n; i++) {
if(!cnt[abs(a[i]-a[i-1])]) { if (!cnt[abs(a[i] - a[i - 1])]) {
cnt[abs(a[i]-a[i-1])] = true; cnt[abs(a[i] - a[i - 1])] = true;
} else { } else {
cout << "Not jolly" << endl; cout << "Not jolly" << endl;
return 0; return 0;

View File

@ -1,6 +1,6 @@
// R36448353 // R36448353
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -10,10 +10,10 @@ int main() {
double a; double a;
n = t = ans = 0; n = t = ans = 0;
cin >> n; cin >> n;
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
cin >> a >> t; cin >> a >> t;
for(int j = 1 ; j <= t ; j++) { for (int j = 1; j <= t; j++) {
ans ^= int(j*a); ans ^= int(j * a);
} }
} }
cout << ans << endl; cout << ans << endl;

View File

@ -23,8 +23,7 @@ int main() {
cin >> a[i][j]; cin >> a[i][j];
if (a[i][j] == 0) { if (a[i][j] == 0) {
b[i][j] = 0; b[i][j] = 0;
} } else {
else {
b[i][j] = 1; b[i][j] = 1;
} }
} }
@ -34,11 +33,9 @@ int main() {
for (int j = 1; j <= n; j++) { for (int j = 1; j <= n; j++) {
if (b[i][j] == 2) { if (b[i][j] == 2) {
cout << "0 "; cout << "0 ";
} } else if (b[i][j] == 0) {
else if (b[i][j] == 0) {
cout << "2 "; cout << "2 ";
} } else {
else {
cout << "1 "; cout << "1 ";
} }
} }

View File

@ -11,8 +11,7 @@ int main() {
mid = (l + r) / 2; mid = (l + r) / 2;
if (pow(1.0 / (1.0 + mid), k) >= 1 - n / m * mid) { if (pow(1.0 / (1.0 + mid), k) >= 1 - n / m * mid) {
r = mid; r = mid;
} } else {
else {
l = mid; l = mid;
} }
} }

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -7,24 +7,23 @@ int main() {
priority_queue<int, vector<int>, less<int> > s; priority_queue<int, vector<int>, less<int> > s;
priority_queue<int, vector<int>, greater<int> > l; priority_queue<int, vector<int>, greater<int> > l;
cin >> n; cin >> n;
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
cin >> a[i]; cin >> a[i];
k = i/2+1; k = i / 2 + 1;
if(!l.empty() && a[i] >= l.top()) { if (!l.empty() && a[i] >= l.top()) {
s.push(a[i]); s.push(a[i]);
} } else {
else {
l.push(a[i]); l.push(a[i]);
} }
while(l.size() < k) { while (l.size() < k) {
l.push(s.top()); l.push(s.top());
s.pop(); s.pop();
} }
while(s.size() < k) { while (s.size() < k) {
s.push(l.top()); s.push(l.top());
l.pop(); l.pop();
} }
if(i%2) { if (i % 2) {
cout << s.top() << endl; cout << s.top() << endl;
} }
} }

View File

@ -1,21 +1,21 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int gcd(int a, int b) { int gcd(int a, int b) {
if(b == 0) { if (b == 0) {
return a; return a;
} }
return gcd(b, a%b); return gcd(b, a % b);
} }
int main() { int main() {
int t; int t;
cin >> t; cin >> t;
while(t--) { while (t--) {
int ax, ay, bx, by; int ax, ay, bx, by;
cin >> ax >> ay >> bx >> by; cin >> ax >> ay >> bx >> by;
cout << (gcd(abs(ax-bx), abs(ay-by)) == 1 ? "no" : "yes") << endl; cout << (gcd(abs(ax - bx), abs(ay - by)) == 1 ? "no" : "yes") << endl;
} }
return 0; return 0;
} }

View File

@ -10,8 +10,7 @@ int main() {
if (sum + t > m) { if (sum + t > m) {
ans++; ans++;
sum = t; sum = t;
} } else {
else {
sum += t; sum += t;
} }
} }

View File

@ -9,8 +9,7 @@ bool check(int x) {
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
if (tot + a[i] <= x) { if (tot + a[i] <= x) {
tot += a[i]; tot += a[i];
} } else {
else {
tot = a[i]; tot = a[i];
num++; num++;
} }
@ -28,8 +27,7 @@ int main() {
mid = l + r >> 1; mid = l + r >> 1;
if (check(mid)) { if (check(mid)) {
l = mid + 1; l = mid + 1;
} } else {
else {
r = mid - 1; r = mid - 1;
} }
} }

View File

@ -26,12 +26,10 @@ int main() {
if (op == 'A') { if (op == 'A') {
a[++n] = (x + t) % d; a[++n] = (x + t) % d;
change(n); change(n);
} } else if (op == 'Q') {
else if (op == 'Q') {
if (x == 1) { if (x == 1) {
cout << (t = a[n]) << endl; cout << (t = a[n]) << endl;
} } else {
else {
cout << (t = find(n - x + 1, n)) << endl; cout << (t = find(n - x + 1, n)) << endl;
} }
} }

View File

@ -8,16 +8,22 @@ int main() {
getline(cin, a); getline(cin, a);
getline(cin, b); getline(cin, b);
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
if (a[i] <= 0) break; if (a[i] <= 0)
else us *= a[i] - 64; break;
else
us *= a[i] - 64;
} }
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
if (b[i] <= 0) break; if (b[i] <= 0)
else zs *= b[i] - '@'; break;
else
zs *= b[i] - '@';
} }
us %= 47; us %= 47;
zs %= 47; zs %= 47;
if (us == zs) cout << "GO" << endl; if (us == zs)
else cout << "STAY" << endl; cout << "GO" << endl;
else
cout << "STAY" << endl;
return 0; return 0;
} }

View File

@ -26,8 +26,7 @@ int main() {
for (int i = 1; i < n; i++) { for (int i = 1; i < n; i++) {
if (a[i].start <= end) { if (a[i].start <= end) {
end = max(end, a[i].end); end = max(end, a[i].end);
} } else {
else {
ans1 = max(ans1, end - start); ans1 = max(ans1, end - start);
ans2 = max(ans2, a[i].start - end); ans2 = max(ans2, a[i].start - end);
start = a[i].start; start = a[i].start;

View File

@ -1,6 +1,6 @@
// R36572888 // R36572888
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;

View File

@ -1,23 +1,23 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
int n, a[1005][1005], f[1005][1005]; int n, a[1005][1005], f[1005][1005];
cin >> n; cin >> n;
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
for(int j = 1 ; j <= i ; j++) { for (int j = 1; j <= i; j++) {
cin >> a[i][j]; cin >> a[i][j];
} }
} }
f[1][1] = a[1][1]; f[1][1] = a[1][1];
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
for(int j = 1 ; j <= i+1 ; j++) { for (int j = 1; j <= i + 1; j++) {
f[i][j] = a[i][j] + max(f[i-1][j], f[i-1][j-1]); f[i][j] = a[i][j] + max(f[i - 1][j], f[i - 1][j - 1]);
} }
} }
int ans = -0x3f3f3f; int ans = -0x3f3f3f;
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
ans = max(ans, f[n][i]); ans = max(ans, f[n][i]);
} }
cout << ans << endl; cout << ans << endl;

View File

@ -22,12 +22,10 @@ int main() {
if (st.empty() || b[st.top()] != s[i]) { if (st.empty() || b[st.top()] != s[i]) {
if (s[i] == ')') { if (s[i] == ')') {
b[i] = '('; b[i] = '(';
} } else {
else {
b[i] = '['; b[i] = '[';
} }
} } else {
else {
b[st.top()] = ' '; b[st.top()] = ' ';
st.pop(); st.pop();
} }

View File

@ -1,17 +1,17 @@
// R38787626 // R38787626
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
int n, m, a[2000005]; int n, m, a[2000005];
cin >> n >> m; cin >> n >> m;
for(int i = 0 ; i < m ; i++) { for (int i = 0; i < m; i++) {
cin >> a[i]; cin >> a[i];
} }
sort(a, a+m); sort(a, a + m);
for(int i = 0 ; i < m ; i++) { for (int i = 0; i < m; i++) {
cout << a[i] << ' '; cout << a[i] << ' ';
} }
cout << endl; cout << endl;

View File

@ -14,15 +14,15 @@ int main() {
cin >> s[0]; cin >> s[0];
n = s[0].size(); n = s[0].size();
for(int i = 1 ; i < n ; i++) { for (int i = 1; i < n; i++) {
cin >> s[i]; cin >> s[i];
} }
cout << n << " "; cout << n << " ";
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
for(int j = 0 ; j < n ; j++) { for (int j = 0; j < n; j++) {
if(s[i][j] == l) { if (s[i][j] == l) {
c++; c++;
} else { } else {
cout << c << " "; // 输出以前统计完的 cout << c << " "; // 输出以前统计完的

View File

@ -17,6 +17,7 @@ int main() {
girl += (s[i] == 'g' || s[i + 1] == 'i' || s[i + 2] == 'r' || s[i + 3] == 'l'); girl += (s[i] == 'g' || s[i + 1] == 'i' || s[i + 2] == 'r' || s[i + 3] == 'l');
} }
cout << boy << endl << girl << endl; cout << boy << endl
<< girl << endl;
return 0; return 0;
} }

View File

@ -12,7 +12,7 @@ int main() {
f[i] = 0x3f3f3f; f[i] = 0x3f3f3f;
} }
f[n] = 0; f[n] = 0;
for (int i = n-1; i >= 0; i--) { for (int i = n - 1; i >= 0; i--) {
for (int j = i + 1; j <= n; j++) { for (int j = i + 1; j <= n; j++) {
f[i] = min(f[i], f[j] + a[i][j]); f[i] = min(f[i], f[j] + a[i][j]);
} }

View File

@ -6,17 +6,17 @@ int n, m, op, l, r, k, d, p, a[100005];
int main() { int main() {
cin >> n >> m; cin >> n >> m;
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
cin >> a[i]; cin >> a[i];
} }
for(int i = 0 ; i < m ; i++) { for (int i = 0; i < m; i++) {
cin >> op; cin >> op;
if(op == 1) { if (op == 1) {
cin >> l >> r >> k >> d; cin >> l >> r >> k >> d;
for(int j = l ; j <= r ; j++) { for (int j = l; j <= r; j++) {
a[j] += k + (j - l) * d; a[j] += k + (j - l) * d;
} }
} else if(op == 2) { } else if (op == 2) {
cin >> p; cin >> p;
cout << a[p] << endl; cout << a[p] << endl;
} }

View File

@ -10,24 +10,21 @@ int main() {
if (ch == '.') { if (ch == '.') {
st.push(t); st.push(t);
t = 0; t = 0;
} } else if ('0' <= ch && ch <= '9') {
else if('0' <= ch && ch <= '9') {
t *= 10; t *= 10;
t += ch - '0'; t += ch - '0';
} } else {
else { b = st.top();
b = st.top(); st.pop(); st.pop();
a = st.top(); st.pop(); a = st.top();
st.pop();
if (ch == '+') { if (ch == '+') {
st.push(a + b); st.push(a + b);
} } else if (ch == '-') {
else if (ch == '-') {
st.push(a - b); st.push(a - b);
} } else if (ch == '*') {
else if (ch == '*') {
st.push(a * b); st.push(a * b);
} } else if (ch == '/') {
else if (ch == '/') {
st.push(a / b); st.push(a / b);
} }
} }

View File

@ -43,8 +43,7 @@ void modify(int u, int x, int d) {
int mid = tr[u].l + tr[u].r >> 1; int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) { if (x <= mid) {
modify(u << 1, x, d); modify(u << 1, x, d);
} } else {
else {
modify(u << 1 | 1, x, d); modify(u << 1 | 1, x, d);
} }
pushup(u); pushup(u);
@ -75,8 +74,7 @@ int main() {
cin >> op >> x >> y; cin >> op >> x >> y;
if (op == 'U') { if (op == 'U') {
modify(1, x, y); modify(1, x, y);
} } else if (op == 'Q') {
else if (op == 'Q') {
cout << query(1, x, y) << endl; cout << query(1, x, y) << endl;
} }
} }

View File

@ -22,8 +22,7 @@ int main() {
cin >> x >> y; cin >> x >> y;
if (find(x) == find(y)) { if (find(x) == find(y)) {
cout << "Yes" << endl; cout << "Yes" << endl;
} } else {
else {
cout << "No" << endl; cout << "No" << endl;
} }
} }

View File

@ -8,12 +8,12 @@ int n, m, js[10];
int main() { int main() {
cin >> n >> m; cin >> n >> m;
for(int i = n ; i <= m ; i++) { for (int i = n; i <= m; i++) {
for(int j = i ; j ; j /= 10) { for (int j = i; j; j /= 10) {
js[j%10]++; js[j % 10]++;
} }
} }
for(int i = 0 ; i < 10 ; i++) { for (int i = 0; i < 10; i++) {
cout << js[i] << " "; cout << js[i] << " ";
} }
return 0; return 0;

View File

@ -22,16 +22,13 @@ int main() {
if (a[now].towards == 0) { if (a[now].towards == 0) {
if (x == 0) { if (x == 0) {
now = (now + n - y) % n; now = (now + n - y) % n;
} } else if (x == 1) {
else if (x == 1) {
now = (now + y) % n; now = (now + y) % n;
} }
} } else if (a[now].towards == 1) {
else if (a[now].towards == 1) {
if (x == 0) { if (x == 0) {
now = (now + y) % n; now = (now + y) % n;
} } else if (x == 1) {
else if (x == 1) {
now = (now + n - y) % n; now = (now + n - y) % n;
} }
} }

View File

@ -12,8 +12,7 @@ int main() {
for (int i = 1; i < n; i++) { for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1]) { if (a[i] > a[i - 1]) {
f[i] = f[i - 1] + 1; f[i] = f[i - 1] + 1;
} } else {
else {
f[i] = 0; f[i] = 0;
} }
} }

View File

@ -1,6 +1,6 @@
// https://www.luogu.com.cn/record/38654562 // https://www.luogu.com.cn/record/38654562
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -11,14 +11,14 @@ int main() {
a = b = c = 0; a = b = c = 0;
cin >> s; cin >> s;
for(int i = 0 ; i < s.size() ; i += 5) { for (int i = 0; i < s.size(); i += 5) {
cout << s[i] << ' ' << s[i+3] << ' '; cout << s[i] << ' ' << s[i + 3] << ' ';
switch(s[i]) { switch (s[i]) {
case 'a': case 'a':
if('0' <= s[i+3] && s[i+3] <= '9') { if ('0' <= s[i + 3] && s[i + 3] <= '9') {
a = s[i+3] - '0'; a = s[i + 3] - '0';
} else { } else {
switch(s[i+3]) { switch (s[i + 3]) {
case 'a': case 'a':
a = a; a = a;
break; break;
@ -32,10 +32,10 @@ int main() {
} }
break; break;
case 'b': case 'b':
if('0' <= s[i+3] && s[i+3] <= '9') { if ('0' <= s[i + 3] && s[i + 3] <= '9') {
b = s[i+3] - '0'; b = s[i + 3] - '0';
} else { } else {
switch(s[i+3]) { switch (s[i + 3]) {
case 'a': case 'a':
b = a; b = a;
break; break;
@ -49,10 +49,10 @@ int main() {
} }
break; break;
case 'c': case 'c':
if('0' <= s[i+3] && s[i+3] <= '9') { if ('0' <= s[i + 3] && s[i + 3] <= '9') {
c = s[i+3] - '0'; c = s[i + 3] - '0';
} else { } else {
switch(s[i+3]) { switch (s[i + 3]) {
case 'a': case 'a':
c = a; c = a;
break; break;

View File

@ -30,8 +30,7 @@ int main() {
if (cnt[j] == max) { if (cnt[j] == max) {
printf("%s%c", j == 0 ? "" : " ", '*'); printf("%s%c", j == 0 ? "" : " ", '*');
cnt[j]--; cnt[j]--;
} } else {
else {
printf("%s%s", j == 0 ? "" : " ", " "); printf("%s%s", j == 0 ? "" : " ", " ");
} }
} }

View File

@ -1,98 +1,98 @@
// https://www.luogu.com.cn/record/20137358 // https://www.luogu.com.cn/record/20137358
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
long long c = 0, word[6] = {0,0,0,0,0,0}, out = 0; long long c = 0, word[6] = {0, 0, 0, 0, 0, 0}, out = 0;
int getst(string s, long long &c) { int getst(string s, long long &c) {
if(s=="one" || s=="a" || s=="first" || s=="another") { if (s == "one" || s == "a" || s == "first" || s == "another") {
word[c] = 1 ; word[c] = 1;
c++; c++;
return 0; return 0;
} }
if(s == "two" || s == "both" || s == "second") { if (s == "two" || s == "both" || s == "second") {
word[c] = 4; word[c] = 4;
c++; c++;
return 0; return 0;
} }
if(s == "three" || s == "third") { if (s == "three" || s == "third") {
word[c]=9; word[c] = 9;
c++; c++;
return 0; return 0;
} }
if(s == "four") { if (s == "four") {
word[c] = 16; word[c] = 16;
c++; c++;
return 0; return 0;
} }
if(s == "five") { if (s == "five") {
word[c] = 25; word[c] = 25;
c++; c++;
return 0; return 0;
} }
if(s == "six") { if (s == "six") {
word[c] = 36; word[c] = 36;
c++; c++;
return 0; return 0;
} }
if(s == "seven") { if (s == "seven") {
word[c] = 49; word[c] = 49;
c++; c++;
return 0; return 0;
} }
if(s == "eight") { if (s == "eight") {
word[c] = 64; word[c] = 64;
c++; c++;
return 0; return 0;
} }
if(s == "nine") { if (s == "nine") {
word[c] = 81; word[c] = 81;
c++; c++;
return 0; return 0;
} }
if(s == "eleven") { if (s == "eleven") {
word[c] = 21; word[c] = 21;
c++; c++;
return 0; return 0;
} }
if(s == "twelve") { if (s == "twelve") {
word[c] = 44; word[c] = 44;
c++; c++;
return 0; return 0;
} }
if(s == "thirteen") { if (s == "thirteen") {
word[c] = 69; word[c] = 69;
c++; c++;
return 0; return 0;
} }
if(s == "fourteen") { if (s == "fourteen") {
word[c] = 96; word[c] = 96;
c++; c++;
return 0; return 0;
} }
if(s == "fifteen") { if (s == "fifteen") {
word[c] = 25; word[c] = 25;
c++; c++;
return 0; return 0;
} }
if(s == "sixteen") { if (s == "sixteen") {
word[c] = 56; word[c] = 56;
c++; c++;
return 0; return 0;
} }
if(s == "seventeen") { if (s == "seventeen") {
word[c] = 89; word[c] = 89;
c++; c++;
return 0; return 0;
} }
if(s == "eightteen") { if (s == "eightteen") {
word[c] = 24; word[c] = 24;
c++; c++;
return 0; return 0;
} }
if(s == "nineteen") { if (s == "nineteen") {
word[c] = 61; word[c] = 61;
c++; c++;
return 0; return 0;
@ -101,15 +101,15 @@ int getst(string s, long long &c) {
int main(void) { int main(void) {
string getit[6]; string getit[6];
for (int i = 0 ; i < 6 ; i++) { for (int i = 0; i < 6; i++) {
cin >> getit[i]; cin >> getit[i];
if (getit[i][getit[i].size()-1] == '.') { if (getit[i][getit[i].size() - 1] == '.') {
getit[i].erase(getit[i].size()-1,1); getit[i].erase(getit[i].size() - 1, 1);
} }
getst(getit[i] , c); getst(getit[i], c);
} }
sort(word , word + c); sort(word, word + c);
for(int i = 0 ; i < c ; i++) { for (int i = 0; i < c; i++) {
out += word[i]; out += word[i];
out *= 100; out *= 100;
} }

View File

@ -23,7 +23,7 @@ void dfs(int x, int y) {
int main() { int main() {
cin >> n >> m >> t >> sx >> sy >> fx >> fy; cin >> n >> m >> t >> sx >> sy >> fx >> fy;
for(int i = 0 ; i < t ; i++) { for (int i = 0; i < t; i++) {
int x, y; int x, y;
cin >> x >> y; cin >> x >> y;
vis[x][y] = -1; vis[x][y] = -1;

View File

@ -5,14 +5,14 @@
using namespace std; using namespace std;
int main() { int main() {
int n, m, a[100005], minn=100000, t=0; int n, m, a[100005], minn = 100000, t = 0;
cin >> n >> m; cin >> n >> m;
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
cin >> a[i]; cin >> a[i];
} }
for(int i = 1 ; i <= n-m+1 ; i++) { for (int i = 1; i <= n - m + 1; i++) {
for(int j = 1 ; j <= m ; j++) { for (int j = 1; j <= m; j++) {
t += a[i+j-1]; t += a[i + j - 1];
} }
minn = min(t, minn); minn = min(t, minn);
t = 0; t = 0;

View File

@ -1,12 +1,12 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
unsigned long long x, n, ans=1; unsigned long long x, n, ans = 1;
cin >> x >> n; cin >> x >> n;
for(unsigned long long i = 0 ; i < n ; i++) { for (unsigned long long i = 0; i < n; i++) {
ans += ans*x; ans += ans * x;
} }
cout << ans << endl; cout << ans << endl;
return 0; return 0;

View File

@ -32,8 +32,7 @@ int main() {
if (d >= 365) { if (d >= 365) {
ans++; ans++;
} }
} } else {
else {
m++; m++;
} }
} }

View File

@ -15,11 +15,9 @@ int main() {
int p = lower_bound(a, a + m, q) - a; int p = lower_bound(a, a + m, q) - a;
if (p == m) { if (p == m) {
ans += q - a[m - 1]; ans += q - a[m - 1];
} } else if (p == 0) {
else if (p == 0) {
ans += a[0] - q; ans += a[0] - q;
} } else {
else {
ans += min(abs(a[p] - q), abs(q - a[p - 1])); ans += min(abs(a[p] - q), abs(q - a[p - 1]));
} }
} }

View File

@ -16,7 +16,7 @@ void dfs(int cnt, int k, int last) {
return; return;
} }
int i = last; int i = last;
while (i*i*i*i <= n - cnt) { while (i * i * i * i <= n - cnt) {
i++; i++;
} }
while (i >= last) { while (i >= last) {

View File

@ -8,10 +8,10 @@ int main() {
int n, a[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int n, a[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
scanf("%d", &n); scanf("%d", &n);
do { do {
for (int i = 0; i < n-1; i++) { for (int i = 0; i < n - 1; i++) {
printf("%5d", a[i]); printf("%5d", a[i]);
} }
printf("%5d\n", a[n-1]); printf("%5d\n", a[n - 1]);
} while (next_permutation(a, a + n)); } while (next_permutation(a, a + n));
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -7,22 +7,22 @@ const int fib[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,
int main() { int main() {
int t, n; int t, n;
cin >> t; cin >> t;
while(t--) { while (t--) {
stack<int> st; stack<int> st;
cin >> n; cin >> n;
cout << n << "="; cout << n << "=";
for(int i = 45 ; i > 0 ; i--) { for (int i = 45; i > 0; i--) {
while(n >= fib[i]) { while (n >= fib[i]) {
n -= fib[i]; n -= fib[i];
st.push(fib[i]); st.push(fib[i]);
} }
if(n == 0) { if (n == 0) {
break; break;
} }
} }
cout << st.top(); cout << st.top();
st.pop(); st.pop();
while(!st.empty()) { while (!st.empty()) {
cout << "+" << st.top(); cout << "+" << st.top();
st.pop(); st.pop();
} }

View File

@ -12,8 +12,7 @@ int main() {
while (scanf("%c", &c) != EOF) { while (scanf("%c", &c) != EOF) {
if (c == ' ') { if (c == ' ') {
cnt++; cnt++;
} } else if ('a' <= c && c <= 'z') {
else if('a' <= c && c <= 'z') {
cnt += num[c - 'a']; cnt += num[c - 'a'];
} }
// cout << c << ' ' << cnt << endl; // cout << c << ' ' << cnt << endl;

View File

@ -30,8 +30,7 @@ int main() {
cin >> l >> r; cin >> l >> r;
if (l > m || r > m || l < 1 || r < 1) { if (l > m || r > m || l < 1 || r < 1) {
cout << "Crossing the line" << endl; cout << "Crossing the line" << endl;
} } else {
else {
cout << ans[r] - ans[l - 1] << endl; cout << ans[r] - ans[l - 1] << endl;
} }
} }

View File

@ -2,7 +2,6 @@
using namespace std; using namespace std;
long long n, m, l, r, ans, a[1000005]; long long n, m, l, r, ans, a[1000005];
bool check(long long x) { bool check(long long x) {
@ -25,8 +24,7 @@ int main() {
long long mid = l + r >> 1; long long mid = l + r >> 1;
if (check(mid)) { if (check(mid)) {
l = (ans = mid) + 1; l = (ans = mid) + 1;
} } else {
else {
r = mid - 1; r = mid - 1;
} }
} }

View File

@ -29,8 +29,7 @@ int main() {
mid2 = r - (r - l) / 3.0; mid2 = r - (r - l) / 3.0;
if (check(mid1) > check(mid2)) { if (check(mid1) > check(mid2)) {
l = mid1; l = mid1;
} } else {
else {
r = mid2; r = mid2;
} }
} }

View File

@ -23,11 +23,9 @@ int main() {
} }
if (ans[3] == 1 && ans[2] == 0 && ans[1] == 0) { if (ans[3] == 1 && ans[2] == 0 && ans[1] == 0) {
cout << 100 << endl; cout << 100 << endl;
} } else if ((ans[2] + ans[3]) % 10) {
else if ((ans[2] + ans[3]) % 10) {
cout << (ans[2] + ans[3]) % 10 << (ans[1] + ans[2]) % 10 << endl; cout << (ans[2] + ans[3]) % 10 << (ans[1] + ans[2]) % 10 << endl;
} } else {
else {
cout << (ans[1] + ans[2]) % 10 << endl; cout << (ans[1] + ans[2]) % 10 << endl;
} }
return 0; return 0;

View File

@ -13,8 +13,7 @@ void merge_sort(long long a[], long long l, long long r) {
while (i <= mid && j <= r) { while (i <= mid && j <= r) {
if (a[i] <= a[j]) { if (a[i] <= a[j]) {
t[k++] = a[i++]; t[k++] = a[i++];
} } else {
else {
t[k++] = a[j++]; t[k++] = a[j++];
ans += (mid - i + 1); ans += (mid - i + 1);
} }

View File

@ -17,11 +17,9 @@ string cnm() {
while (n--) { while (n--) {
s += str; s += str;
} }
} } else if (ch == ']') {
else if (ch == ']') {
return s; return s;
} } else {
else {
s += ch; s += ch;
} }
} }

View File

@ -7,8 +7,7 @@ extern "C" int Chtholly(int n, int OvO) {
if (Seniorious(mid) >= 0) { if (Seniorious(mid) >= 0) {
ans = mid; ans = mid;
r = mid - 1; r = mid - 1;
} } else {
else {
l = mid + 1; l = mid + 1;
} }
mid = l + r >> 1; mid = l + r >> 1;

View File

@ -26,8 +26,7 @@ int main() {
for (int j = a[1]; j < a[a[0]]; j++) { for (int j = a[1]; j < a[a[0]]; j++) {
if (a[l] == j) { if (a[l] == j) {
l++; l++;
} } else {
else {
for (int k = 1; k <= a[0]; k++) { for (int k = 1; k <= a[0]; k++) {
if (!v[a[k]][j]) { if (!v[a[k]][j]) {
int t = a[k]; int t = a[k];

View File

@ -84,12 +84,10 @@ signed main() {
if (op == 1) { if (op == 1) {
cin >> k; cin >> k;
modify(1, x, y, k, 0); modify(1, x, y, k, 0);
} } else if (op == 2) {
else if (op == 2) {
cin >> k; cin >> k;
modify(1, x, y, 1, k); modify(1, x, y, 1, k);
} } else if (op == 3) {
else if (op == 3) {
cout << query(1, x, y) % p << endl; cout << query(1, x, y) % p << endl;
} }
} }

View File

@ -37,8 +37,10 @@ void modify(int u, int x, int d) {
return; return;
} }
int mid = tr[u].l + tr[u].r >> 1; int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) modify(u << 1, x, d); if (x <= mid)
else modify(u << 1 | 1, x, d); modify(u << 1, x, d);
else
modify(u << 1 | 1, x, d);
pushup(u); pushup(u);
} }
@ -60,8 +62,7 @@ int main() {
cin >> op >> a >> b; cin >> op >> a >> b;
if (op == 'x') { if (op == 'x') {
modify(1, a, b); modify(1, a, b);
} } else if (op == 'y') {
else if (op == 'y') {
cout << query(1, a, b) << endl; cout << query(1, a, b) << endl;
} }
} }

View File

@ -28,11 +28,9 @@ int main() {
long long w, c; long long w, c;
cin >> w >> c; cin >> w >> c;
a.insert(node(w, c)); a.insert(node(w, c));
} } else if (op == 2 && !a.empty()) {
else if (op == 2 && !a.empty()) {
a.erase(--a.end()); a.erase(--a.end());
} } else if (op == 3 && !a.empty()) {
else if (op == 3 && !a.empty()) {
a.erase(a.begin()); a.erase(a.begin());
} }
} }

View File

@ -8,7 +8,7 @@ string s;
int main() { int main() {
cin >> m >> s; cin >> m >> s;
for (int i = 0; i < s.size(); i++) { for (int i = 0; i < s.size(); i++) {
if(s[i] == '0') { if (s[i] == '0') {
continue; continue;
} }
if (i != 0) { if (i != 0) {

View File

@ -15,8 +15,7 @@ int main() {
vector<int>::iterator it = lower_bound(nums.begin(), nums.end(), t); vector<int>::iterator it = lower_bound(nums.begin(), nums.end(), t);
if (*it == t) { if (*it == t) {
cout << it - nums.begin() + 1 << ' '; cout << it - nums.begin() + 1 << ' ';
} } else {
else {
cout << "-1 "; cout << "-1 ";
} }
} }

View File

@ -80,20 +80,16 @@ int main() {
if (op == 1) { if (op == 1) {
cin >> x >> y >> k; cin >> x >> y >> k;
modify(1, x, y, k); modify(1, x, y, k);
} } else if (op == 2) {
else if(op == 2) {
cin >> k; cin >> k;
modify(1, 1, 1, k); modify(1, 1, 1, k);
} } else if (op == 3) {
else if(op == 3) {
cin >> k; cin >> k;
modify(1, 1, 1, -k); modify(1, 1, 1, -k);
} } else if (op == 4) {
else if(op == 4) {
cin >> x >> y; cin >> x >> y;
cout << query(1, x, y) << endl; cout << query(1, x, y) << endl;
} } else if (op == 5) {
else if(op == 5) {
cout << query(1, 1, 1) << endl; cout << query(1, 1, 1) << endl;
} }
} }

View File

@ -1,19 +1,17 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
int n; int n;
cin >> n; cin >> n;
if(n <= 8) { if (n <= 8) {
cout << 0 << endl; cout << 0 << endl;
} } else if (n == 9) {
else if(n == 9) {
cout << 8 << endl; cout << 8 << endl;
} } else {
else {
cout << 72; cout << 72;
for(int i = 10 ; i < n ; i++) { for (int i = 10; i < n; i++) {
cout << 0; cout << 0;
} }
cout << endl; cout << endl;

View File

@ -7,10 +7,10 @@ int n, a[10];
void dfs(int x, int depth, int last) { void dfs(int x, int depth, int last) {
if (x > n) return; if (x > n) return;
if (x == n) { if (x == n) {
for(int i = 1 ; i < depth - 1 ; i++) { for (int i = 1; i < depth - 1; i++) {
cout << a[i] << '+'; cout << a[i] << '+';
} }
cout << a[depth-1] << endl; cout << a[depth - 1] << endl;
return; return;
} }
for (int i = last; i < n; i++) { for (int i = last; i < n; i++) {

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -7,51 +7,38 @@ int main() {
cin >> T; cin >> T;
if (T == 1) { if (T == 1) {
cout << "I love Luogu!"; cout << "I love Luogu!";
} } else if (T == 2) {
else if (T == 2) {
cout << 2 + 4 << " " << 10 - 2 - 4; cout << 2 + 4 << " " << 10 - 2 - 4;
} } else if (T == 3) {
else if (T == 3) {
cout << 3 << endl cout << 3 << endl
<< 12 << endl << 12 << endl
<< 2 << endl; << 2 << endl;
} } else if (T == 4) {
else if (T == 4) {
printf("%.3lf\n", 500.0 / 3.0); printf("%.3lf\n", 500.0 / 3.0);
} } else if (T == 5) {
else if (T == 5) {
cout << 15 << endl; cout << 15 << endl;
} } else if (T == 6) {
else if (T == 6) {
cout << sqrt(6 * 6 + 9 * 9) << endl; cout << sqrt(6 * 6 + 9 * 9) << endl;
} } else if (T == 7) {
else if (T == 7) {
cout << 110 << endl cout << 110 << endl
<< 90 << endl << 90 << endl
<< 0 << endl; << 0 << endl;
} } else if (T == 8) {
else if (T == 8) {
cout << 3.141593 * 5 * 2 << endl cout << 3.141593 * 5 * 2 << endl
<< 3.141593 * 5 * 5 << endl << 3.141593 * 5 * 5 << endl
<< 4.0 / 3 * 3.141593 * 5 * 5 * 5 << endl; << 4.0 / 3 * 3.141593 * 5 * 5 * 5 << endl;
} } else if (T == 9) {
else if (T == 9) {
cout << 22 << endl; cout << 22 << endl;
} } else if (T == 10) {
else if (T == 10) {
cout << 9 << endl; cout << 9 << endl;
} } else if (T == 11) {
else if (T == 11) {
cout << 100.0 / (8 - 5) << endl; cout << 100.0 / (8 - 5) << endl;
} } else if (T == 12) {
else if (T == 12) {
cout << 13 << endl cout << 13 << endl
<< "R" << endl; << "R" << endl;
} } else if (T == 13) {
else if (T == 13) {
cout << floor(pow((3.141593 * 4 * 4 * 4 * 4 / 3 + 3.141593 * 10 * 10 * 10 * 4 / 3), 1.0 / 3)) << endl; cout << floor(pow((3.141593 * 4 * 4 * 4 * 4 / 3 + 3.141593 * 10 * 10 * 10 * 4 / 3), 1.0 / 3)) << endl;
} } else if (T == 14) {
else if (T == 14) {
cout << 50 << endl; cout << 50 << endl;
} }
return 0; return 0;

View File

@ -8,24 +8,23 @@ int n, win[7], lottery[7], sum[10], c;
int main() { int main() {
cin >> n; cin >> n;
for(int i = 0 ; i < 7 ; i++) { for (int i = 0; i < 7; i++) {
cin >> win[i]; cin >> win[i];
} }
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
c = 0; c = 0;
for(int j = 0 ; j < 7 ; j++) { for (int j = 0; j < 7; j++) {
cin >> lottery[j]; cin >> lottery[j];
for(int p = 0 ; p < 7 ; p++) { for (int p = 0; p < 7; p++) {
if(lottery[j] == win[p]) c++; if (lottery[j] == win[p]) c++;
} }
} }
// cout << c << ' '; // debug // cout << c << ' '; // debug
sum[c]++; sum[c]++;
} }
// cout << endl; // debug // cout << endl; // debug
for(int i = 7 ; i > 0 ; i--) { for (int i = 7; i > 0; i--) {
cout << sum[i] << ' '; cout << sum[i] << ' ';
} }
return 0; return 0;
} }

View File

@ -81,8 +81,7 @@ int main() {
cin >> op >> x >> y; cin >> op >> x >> y;
if (op == 0) { if (op == 0) {
modify(1, x, y); modify(1, x, y);
} } else if (op == 1) {
else if (op == 1) {
cout << query(1, x, y) << endl; cout << query(1, x, y) << endl;
} }
} }

View File

@ -1,19 +1,19 @@
// R38819026 // R38819026
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
int n, h[20005], b, sum=0, i; int n, h[20005], b, sum = 0, i;
cin >> n >> b; cin >> n >> b;
for(i = 0 ; i < n ; i++) { for (i = 0; i < n; i++) {
cin >> h[i]; cin >> h[i];
} }
sort(h, h+n); sort(h, h + n);
while(sum < b) { while (sum < b) {
sum += h[--i]; sum += h[--i];
} }
cout << n-i << endl; cout << n - i << endl;
return 0; return 0;
} }

View File

@ -21,7 +21,7 @@ int main() {
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
cin >> a[i]; cin >> a[i];
} }
a[n+1] = r; a[n + 1] = r;
l = 1; l = 1;
while (l <= r) { while (l <= r) {
mid = l + r >> 1; mid = l + r >> 1;

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -6,25 +6,22 @@ int main() {
int x1, y1, x2, y2, t, ans = 0; int x1, y1, x2, y2, t, ans = 0;
char c; char c;
cin >> x1 >> y1 >> x2 >> y2 >> t; cin >> x1 >> y1 >> x2 >> y2 >> t;
for(int i = 1 ; i <= t ; i++) { for (int i = 1; i <= t; i++) {
cin >> c; cin >> c;
if(c == 'E' && y1 < y2) { if (c == 'E' && y1 < y2) {
y1++; y1++;
ans++; ans++;
} } else if (c == 'W' && y1 > y2) {
else if(c == 'W' && y1 > y2) {
y1--; y1--;
ans++; ans++;
} } else if (c == 'N' && x1 < x2) {
else if(c == 'N' && x1 < x2) {
x1++; x1++;
ans++; ans++;
} } else if (c == 'S' && x1 > x2) {
else if(c == 'S' && x1 > x2) {
x1--; x1--;
ans++; ans++;
} }
if(x1 == x2 && y1 == y2) { if (x1 == x2 && y1 == y2) {
cout << ans << endl; cout << ans << endl;
return 0; return 0;
} }

View File

@ -66,11 +66,11 @@ int query(int u, int l, int r) {
int main() { int main() {
cin >> n >> m; cin >> n >> m;
build(1, 1, n); build(1, 1, n);
for(int i = 0 ; i < m ; i++) { for (int i = 0; i < m; i++) {
cin >> op >> s >> e; cin >> op >> s >> e;
if(op == 0) { if (op == 0) {
modify(1, s, e); modify(1, s, e);
} else if(op == 1) { } else if (op == 1) {
cout << query(1, s, e) << endl; cout << query(1, s, e) << endl;
} }
} }

View File

@ -8,14 +8,14 @@ int s1, s2, s3;
int main() { int main() {
scanf("%d%d%d", &s1, &s2, &s3); scanf("%d%d%d", &s1, &s2, &s3);
if(s3 > s1 + s2) { if (s3 > s1 + s2) {
printf("%d", s1+s2+1); printf("%d", s1 + s2 + 1);
} else if(s2 > s1 + s3) { } else if (s2 > s1 + s3) {
printf("%d", s1+s3+1); printf("%d", s1 + s3 + 1);
} else if(s1 > s3 + s2) { } else if (s1 > s3 + s2) {
printf("%d", s3+s2+1); printf("%d", s3 + s2 + 1);
} else { } else {
printf("%d", (s1+s2+s3+3)/2); printf("%d", (s1 + s2 + s3 + 3) / 2);
} }
return 0; return 0;
} }

View File

@ -9,8 +9,7 @@ int main() {
cin >> t; cin >> t;
if (t % 2 == 0) { if (t % 2 == 0) {
cout << "pb wins" << endl; cout << "pb wins" << endl;
} } else {
else {
cout << "zs wins" << endl; cout << "zs wins" << endl;
} }
} }

View File

@ -12,7 +12,7 @@ int main() {
} }
for (int i = 0; i < m; i++) { for (int i = 0; i < m; i++) {
cin >> q; cin >> q;
cout << a[q-1] << endl; cout << a[q - 1] << endl;
} }
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -11,15 +11,14 @@ int find(int x) {
int main() { int main() {
int n, m, z, x, y; int n, m, z, x, y;
cin >> n >> m; cin >> n >> m;
for(int i = 0; i < n ; i++) { for (int i = 0; i < n; i++) {
f[i] = i; f[i] = i;
} }
while(m--) { while (m--) {
cin >> z >> x >> y; cin >> z >> x >> y;
if(z == 1) { if (z == 1) {
f[find(x)] = find(y); f[find(x)] = find(y);
} } else {
else {
cout << (find(x) == find(y) ? "Y" : "N") << endl; cout << (find(x) == find(y) ? "Y" : "N") << endl;
} }
} }

View File

@ -81,8 +81,7 @@ int main() {
if (op == 1) { if (op == 1) {
scanf("%d%d", &y, &k); scanf("%d%d", &y, &k);
modify(1, x, y, k); modify(1, x, y, k);
} } else if (op == 2) {
else if (op == 2) {
printf("%d\n", query(1, x, x)); printf("%d\n", query(1, x, x));
} }
} }

View File

@ -10,20 +10,15 @@ int main() {
cin >> opt >> x; cin >> opt >> x;
if (opt == 1) { if (opt == 1) {
a.insert(lower_bound(a.begin(), a.end(), x), x); a.insert(lower_bound(a.begin(), a.end(), x), x);
} } else if (opt == 2) {
else if (opt == 2) {
a.erase(lower_bound(a.begin(), a.end(), x)); a.erase(lower_bound(a.begin(), a.end(), x));
} } else if (opt == 3) {
else if (opt == 3) {
cout << lower_bound(a.begin(), a.end(), x) - a.begin() + 1 << endl; cout << lower_bound(a.begin(), a.end(), x) - a.begin() + 1 << endl;
} } else if (opt == 4) {
else if (opt == 4) {
cout << a[x - 1] << endl; cout << a[x - 1] << endl;
} } else if (opt == 5) {
else if (opt == 5) {
cout << *(lower_bound(a.begin(), a.end(), x) - 1) << endl; cout << *(lower_bound(a.begin(), a.end(), x) - 1) << endl;
} } else if (opt == 6) {
else if (opt == 6) {
cout << *upper_bound(a.begin(), a.end(), x) << endl; cout << *upper_bound(a.begin(), a.end(), x) << endl;
} }
} }

View File

@ -111,8 +111,7 @@ int main() {
if (op == 1) { if (op == 1) {
cin >> k; cin >> k;
modify(1, x, y, k); modify(1, x, y, k);
} } else if (op == 2) {
else if (op == 2) {
cout << query(1, x, y) << endl; cout << query(1, x, y) << endl;
} }
} }

View File

@ -118,12 +118,10 @@ signed main() {
if (op == 1) { if (op == 1) {
cin >> k; cin >> k;
modify(1, x, y, k, 0); modify(1, x, y, k, 0);
} } else if (op == 2) {
else if (op == 2) {
cin >> k; cin >> k;
modify(1, x, y, 1, k); modify(1, x, y, 1, k);
} } else if (op == 3) {
else if (op == 3) {
cout << query(1, x, y) % p << endl; cout << query(1, x, y) % p << endl;
} }
} }

View File

@ -40,8 +40,7 @@ void change(int u, int x, int d) {
int mid = tr[u].l + tr[u].r >> 1; int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) { if (x <= mid) {
change(u << 1, x, d); change(u << 1, x, d);
} } else {
else {
change(u << 1 | 1, x, d); change(u << 1 | 1, x, d);
} }
pushup(u); pushup(u);
@ -68,8 +67,7 @@ int main() {
cin >> op >> x >> y; cin >> op >> x >> y;
if (op == 1) { if (op == 1) {
change(1, x, y); change(1, x, y);
} } else if (op == 2) {
else if (op == 2) {
cout << query(1, x, y) << endl; cout << query(1, x, y) << endl;
} }
} }

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -6,18 +6,16 @@ int main() {
priority_queue<int, vector<int>, greater<int> > q; priority_queue<int, vector<int>, greater<int> > q;
int n; int n;
cin >> n; cin >> n;
while(n--) { while (n--) {
int op; int op;
cin >> op; cin >> op;
if(op == 1) { if (op == 1) {
int x; int x;
cin >> x; cin >> x;
q.push(x); q.push(x);
} } else if (op == 2) {
else if(op == 2) {
cout << q.top() << endl; cout << q.top() << endl;
} } else if (op == 3) {
else if(op == 3) {
q.pop(); q.pop();
} }
} }

View File

@ -24,8 +24,7 @@ int main() {
mid2 = r - (r - l) / 3.0; mid2 = r - (r - l) / 3.0;
if (f(mid1) > f(mid2)) { if (f(mid1) > f(mid2)) {
r = mid2; r = mid2;
} } else {
else {
l = mid1; l = mid1;
} }
} }

View File

@ -1,4 +1,4 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
@ -6,21 +6,21 @@ int main() {
map<int, map<int, int> > m; map<int, map<int, int> > m;
int n, q, t, i, j, k; int n, q, t, i, j, k;
cin >> n >> q; cin >> n >> q;
while(q--) { while (q--) {
cin >> t >> i >> j; cin >> t >> i >> j;
if(t == 1) { if (t == 1) {
cin >> k; cin >> k;
if(k == 0) { if (k == 0) {
if(m.count(i) && m[i].count(j)) { if (m.count(i) && m[i].count(j)) {
m[i].erase(k); m[i].erase(k);
if(m[i].empty()) { if (m[i].empty()) {
m.erase(i); m.erase(i);
} }
} }
} else { } else {
m[i][j] = k; m[i][j] = k;
} }
} else if(t == 2) { } else if (t == 2) {
cout << m[i][j] << endl; cout << m[i][j] << endl;
} }
} }

View File

@ -17,9 +17,9 @@ int main() {
} }
} }
} }
for(int i = 1 ; i <= n ; i++) { for (int i = 1; i <= n; i++) {
for(int j = 1 ; j <= n ; j++) { for (int j = 1; j <= n; j++) {
if(vis[i][j]) { if (vis[i][j]) {
ans++; ans++;
} }
} }

View File

@ -23,8 +23,7 @@ int main() {
for (int i = 0; i < str.size(); i++) { for (int i = 0; i < str.size(); i++) {
if (str[i] == 'V') { if (str[i] == 'V') {
str[i] = 'K'; str[i] = 'K';
} } else {
else {
str[i] = 'V'; str[i] = 'V';
} }
@ -35,8 +34,7 @@ int main() {
} }
if (str[i] == 'V') { if (str[i] == 'V') {
str[i] = 'K'; str[i] = 'K';
} } else {
else {
str[i] = 'V'; str[i] = 'V';
} }
} }

View File

@ -22,8 +22,10 @@ int main() {
} }
while (l < r) { while (l < r) {
int mid = l + r >> 1; int mid = l + r >> 1;
if (check(mid)) r = mid; if (check(mid))
else l = mid + 1; r = mid;
else
l = mid + 1;
} }
cout << l << endl; cout << l << endl;
return 0; return 0;

View File

@ -1,24 +1,23 @@
#include<bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
int main() { int main() {
int n,m, t; int n, m, t;
string op; string op;
vector<int> nums; vector<int> nums;
cin >> n; cin >> n;
for(int i = 0 ; i < n ; i++) { for (int i = 0; i < n; i++) {
cin >> t; cin >> t;
nums.insert(lower_bound(nums.begin(), nums.end(), t), t); nums.insert(lower_bound(nums.begin(), nums.end(), t), t);
} }
cin >> m; cin >> m;
for(int i = 0 ; i < m ; i++) { for (int i = 0; i < m; i++) {
cin >> op; cin >> op;
if(op == "add") { if (op == "add") {
cin >> t; cin >> t;
nums.insert(lower_bound(nums.begin(), nums.end(), t), t); nums.insert(lower_bound(nums.begin(), nums.end(), t), t);
} } else {
else {
cout << nums[nums.size() / 2 - (nums.size() & 1 ^ 1)] << endl; cout << nums[nums.size() / 2 - (nums.size() & 1 ^ 1)] << endl;
} }
} }

View File

@ -19,8 +19,7 @@ int main() {
cin >> s; cin >> s;
if (!m.count(s)) { if (!m.count(s)) {
cout << endl; cout << endl;
} } else {
else {
for (set<int>::iterator it = m[s].begin(); it != --m[s].end(); it++) { for (set<int>::iterator it = m[s].begin(); it != --m[s].end(); it++) {
cout << *it << ' '; cout << *it << ' ';
} }

View File

@ -5,13 +5,13 @@ using namespace std;
int main() { int main() {
int n; int n;
cin >> n; cin >> n;
int s = n-1; int s = n - 1;
bool prime[100000005]; bool prime[100000005];
memset(prime, 0, sizeof(prime)); memset(prime, 0, sizeof(prime));
for(int i = 2 ; i*i <= n ; i++) { for (int i = 2; i * i <= n; i++) {
if(!prime[i]) { if (!prime[i]) {
for(int j = i*2 ; j <= n ; j+= i) { for (int j = i * 2; j <= n; j += i) {
if(!prime[j]) { if (!prime[j]) {
prime[j] = true; prime[j] = true;
s--; s--;
} }

Some files were not shown because too many files have changed in this diff Show More