mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-06-05 10:40:26 +08:00
Compare commits
38 Commits
Author | SHA1 | Date | |
---|---|---|---|
e9ecfb44ec | |||
19949bb372 | |||
ec47a91f0c | |||
618c4b1bd4 | |||
4ae5e9419c | |||
eef078270d | |||
647ff46929 | |||
60c1caf0b7 | |||
85845ef8b3 | |||
b6243b7378 | |||
20088c4a66 | |||
cd79a24351 | |||
a9d83e539e | |||
377cd93809 | |||
95420a17a8 | |||
911327fd1c | |||
338303f753 | |||
8a2b918e22 | |||
cbe7c15dfe | |||
ddf7e5801e | |||
5233639a89 | |||
c8863a5850 | |||
394e431a4a | |||
b64d31db74 | |||
543ccf0fe0 | |||
b80791cfad | |||
|
8f564ca60e | ||
|
2fe17ab3fd | ||
|
4b8c0c58eb | ||
4d5ff00243 | |||
43596d2ef8 | |||
8c2fd1fb2d | |||
|
aeed7c1c01 | ||
3074714bb5 | |||
8b377fac9d | |||
88455d5102 | |||
620b625f59 | |||
48bd405e02 |
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@ -1,3 +0,0 @@
|
||||
patreon: FrederickAsYou
|
||||
polar: FrederickAsYou
|
||||
custom: ["https://afdian.net/a/se7entin"]
|
20
.github/ISSUE_TEMPLATE/代码修正.md
vendored
20
.github/ISSUE_TEMPLATE/代码修正.md
vendored
@ -1,20 +0,0 @@
|
||||
---
|
||||
name: 代码修正
|
||||
about: 尽可能详细的描述代码出的问题
|
||||
title: "“OJ名称/题目名称” 问题反馈"
|
||||
labels: bug, enhancement
|
||||
assignees: FrederickAsYou
|
||||
|
||||
---
|
||||
|
||||
# 题目
|
||||
|
||||
使用 `OJ名称/题目名称` 的格式
|
||||
|
||||
# 修正内容
|
||||
|
||||
描述需要修正的内容,必要时附上截图
|
||||
|
||||
# 其他
|
||||
|
||||
若有其他说明,请附上
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -50,3 +50,8 @@ modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# config
|
||||
fame.cpp
|
||||
.cph/
|
||||
.vscode/
|
BIN
AtCoder/.DS_Store
vendored
Normal file
BIN
AtCoder/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
AtCoder/ABC_400/A
Executable file
BIN
AtCoder/ABC_400/A
Executable file
Binary file not shown.
21
AtCoder/ABC_400/A.cpp
Normal file
21
AtCoder/ABC_400/A.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int a;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> a;
|
||||
if (400 % a == 0) cout << 400 / a;
|
||||
else cout << -1;
|
||||
return 0;
|
||||
}
|
BIN
AtCoder/ABC_400/B
Executable file
BIN
AtCoder/ABC_400/B
Executable file
Binary file not shown.
55
AtCoder/ABC_400/B.cpp
Normal file
55
AtCoder/ABC_400/B.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
signed main() {
|
||||
int N, M;
|
||||
cin >> N >> M;
|
||||
|
||||
if (N == 1) {
|
||||
lo total = M + 1LL;
|
||||
if (total > 1e9) {
|
||||
cout << "inf" << endl;
|
||||
} else {
|
||||
cout << total << endl;
|
||||
}
|
||||
} else {
|
||||
lo sum = 0;
|
||||
lo cur = 1;
|
||||
bool f = false;
|
||||
for (int i = 0; i <= M; ++i) {
|
||||
sum += cur;
|
||||
if (sum > 1e9) {
|
||||
f = true;
|
||||
break;
|
||||
}
|
||||
if (i == M) {
|
||||
break;
|
||||
}
|
||||
if (cur > 1e9 / N) {
|
||||
f = true;
|
||||
break;
|
||||
}
|
||||
lo next = cur * N;
|
||||
if (next > (1e9 - sum)) {
|
||||
f = true;
|
||||
break;
|
||||
}
|
||||
cur = next;
|
||||
}
|
||||
if (f) {
|
||||
cout << "inf" << endl;
|
||||
} else {
|
||||
cout << sum << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
BIN
AtCoder/ABC_400/C
Executable file
BIN
AtCoder/ABC_400/C
Executable file
Binary file not shown.
41
AtCoder/ABC_400/C.cpp
Normal file
41
AtCoder/ABC_400/C.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
|
||||
signed main() {
|
||||
int N;
|
||||
cin >> N;
|
||||
|
||||
int cnt = 0;
|
||||
int mx = 0;
|
||||
int current = 1;
|
||||
|
||||
while (current <= N) {
|
||||
current *= 2;
|
||||
mx++;
|
||||
}
|
||||
mx--;
|
||||
|
||||
for (int e = 1; e <= mx; ++e) {
|
||||
int m = N / (1 << e);
|
||||
if (m < 1) {
|
||||
continue;
|
||||
}
|
||||
int mx2 = sqrt(m);
|
||||
int cnt = (mx2 + 1) / 2;
|
||||
cnt += cnt;
|
||||
}
|
||||
|
||||
cout << cnt << endl;
|
||||
|
||||
return 0;
|
||||
}
|
20
AtCoder/ABC_400/C.py
Normal file
20
AtCoder/ABC_400/C.py
Normal file
@ -0,0 +1,20 @@
|
||||
import math
|
||||
|
||||
N = int(input())
|
||||
|
||||
count = 0
|
||||
e = 1
|
||||
|
||||
while True:
|
||||
t = 1 << e
|
||||
if t > N:
|
||||
break
|
||||
Q = N // t
|
||||
if Q == 0:
|
||||
e += 1
|
||||
continue
|
||||
m = math.isqrt(Q)
|
||||
cnt += (m + 1) // 2
|
||||
e += 1
|
||||
|
||||
print(cnt)
|
67
AtCoder/ABC_400/D.cpp
Normal file
67
AtCoder/ABC_400/D.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
const lo INF = 1e9;
|
||||
const lo dx[] = {1, 0, -1, 0};
|
||||
const lo dy[] = {0, 1, 0, -1};
|
||||
|
||||
signed main() {
|
||||
lo H, W;
|
||||
cin >> H >> W;
|
||||
vector<string> g(H);
|
||||
for (lo i = 0; i < H; ++i) {
|
||||
cin >> g[i];
|
||||
}
|
||||
|
||||
lo A, B, C, D;
|
||||
cin >> A >> B >> C >> D;
|
||||
--A, --B, --C, --D;
|
||||
|
||||
vector<vector<lo>> dist(H, vector<lo>(W, INF));
|
||||
deque<pair<lo, lo>> q;
|
||||
dist[A][B] = 0;
|
||||
q.epb(A, B);
|
||||
|
||||
while (!q.empty()) {
|
||||
auto [x, y] = q.front();
|
||||
q.pop_front();
|
||||
if (x == C && y == D) {
|
||||
cout << dist[x][y] << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (lo i = 0; i < 4; ++i) {
|
||||
lo nx = x + dx[i];
|
||||
lo ny = y + dy[i];
|
||||
if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
|
||||
if (g[nx][ny] == '.') {
|
||||
if (dist[nx][ny] > dist[x][y]) {
|
||||
dist[nx][ny] = dist[x][y];
|
||||
q.epf(nx, ny);
|
||||
}
|
||||
} else {
|
||||
for (lo j = 1; j <= 2; ++j) {
|
||||
lo tx = x + j * dx[i];
|
||||
lo ty = y + j * dy[i];
|
||||
if (tx < 0 || tx >= H || ty < 0 || ty >= W) break;
|
||||
if (g[tx][ty] == '.') break;
|
||||
if (dist[tx][ty] > dist[x][y] + 1) {
|
||||
dist[tx][ty] = dist[x][y] + 1;
|
||||
q.epb(tx, ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << -1 << '\n';
|
||||
return 0;
|
||||
}
|
BIN
AtCoder/ABC_400/__pycache__/C.cpython-313.pyc
Normal file
BIN
AtCoder/ABC_400/__pycache__/C.cpython-313.pyc
Normal file
Binary file not shown.
34
AtCoder/abc390/A_12435.cpp
Normal file
34
AtCoder/abc390/A_12435.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int a[N], b[N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
cin >> a[i];
|
||||
b[i] = a[i];
|
||||
}
|
||||
if (a[1] == 1 && a[2] == 2 && a[3] == 3 && a[4] == 4 && a[5] == 5) {
|
||||
puts("No");
|
||||
return 0;
|
||||
}
|
||||
sort(b + 1, b + 6);
|
||||
int cnt = 0, r = 0;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
if (a[i] != b[i]) cnt++;
|
||||
if (a[i] != b[i] && i != 1 && a[i - 1] != b[i - 1]) r = 1;
|
||||
}
|
||||
if (cnt == 2 && r == 1) puts("Yes");
|
||||
else puts("No");
|
||||
return 0;
|
||||
}
|
33
AtCoder/abc390/B_Geometric_Sequence.cpp
Normal file
33
AtCoder/abc390/B_Geometric_Sequence.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const lo N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
lo n;
|
||||
lo a[N], b;
|
||||
bool flag = 0;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
for (int i = 3; i <= n; i++)
|
||||
{
|
||||
if (a[i] * a[1] != a[i - 1] * a[2])
|
||||
{
|
||||
puts("No");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
puts("Yes");
|
||||
return 0;
|
||||
}
|
60
AtCoder/abc390/C_Paint_to_make_a_rectangle.cpp
Normal file
60
AtCoder/abc390/C_Paint_to_make_a_rectangle.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
bool f(int h, int w, vector<string>& g)
|
||||
{
|
||||
int top = h, b = -1, l = w, r = -1;
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
if (g[i][j] == '#') {
|
||||
top = min(top, i);
|
||||
b = max(b, i);
|
||||
l = min(l, j);
|
||||
r = max(r, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b == -1) return true;
|
||||
for (int i = top; i <= b; i++) {
|
||||
for (int j = l; j <= r; j++) {
|
||||
if (g[i][j] == '.') return false;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int j = 0; j < w; j++) {
|
||||
if (i < top || i > b || j < l || j > r) {
|
||||
if (g[i][j] == '#') return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int h, w;
|
||||
cin >> h >> w;
|
||||
if (h == 1 && w == 1) {
|
||||
puts("Yes");
|
||||
return 0;
|
||||
}
|
||||
vector<string> g(h);
|
||||
for (int i = 0; i < h; i++) {
|
||||
cin >> g[i];
|
||||
}
|
||||
if (f(h, w, g)) {
|
||||
cout << "Yes" << endl;
|
||||
} else {
|
||||
cout << "No" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
30
AtCoder/abc391/A_Lucky_Direction.cpp
Normal file
30
AtCoder/abc391/A_Lucky_Direction.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
map<string, string> mp;
|
||||
|
||||
string n;
|
||||
|
||||
signed main()
|
||||
{
|
||||
mp["N"] = "S";
|
||||
mp["E"] = "W";
|
||||
mp["W"] = "E";
|
||||
mp["S"] = "N";
|
||||
mp["NE"] = "SW";
|
||||
mp["NW"] = "SE";
|
||||
mp["SE"] = "NW";
|
||||
mp["SW"] = "NE";
|
||||
cin >> n;
|
||||
cout << mp[n];
|
||||
return 0;
|
||||
}
|
48
AtCoder/abc391/B_Seek_Grid.cpp
Normal file
48
AtCoder/abc391/B_Seek_Grid.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
signed main() {
|
||||
int N, M;
|
||||
cin >> N >> M;
|
||||
|
||||
vector<vector<char> > S(N, vector<char>(N));
|
||||
vector<vector<char> > T(M, vector<char>(M));
|
||||
for (int i = 0; i < N; ++i) {
|
||||
for (int j = 0; j < N; ++j) {
|
||||
cin >> S[i][j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < M; ++i) {
|
||||
for (int j = 0; j < M; ++j) {
|
||||
cin >> T[i][j];
|
||||
}
|
||||
}
|
||||
for (int a = 0; a <= N - M; ++a) {
|
||||
for (int b = 0; b <= N - M; ++b) {
|
||||
bool match = true;
|
||||
for (int i = 0; i < M; ++i) {
|
||||
for (int j = 0; j < M; ++j) {
|
||||
if (S[a + i][b + j] != T[i][j]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) break;
|
||||
}
|
||||
if (match) {
|
||||
cout << a + 1 << " " << b + 1 << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
32
AtCoder/abc391/C_Pigeonhole_Query.cpp
Normal file
32
AtCoder/abc391/C_Pigeonhole_Query.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
int n, q, mp[10005], g[10005], cnt = 0, a, b, c;
|
||||
|
||||
int main()
|
||||
{
|
||||
cin >> n >> q;
|
||||
for (int i = 0; i <= n; i++)
|
||||
{
|
||||
mp[i] = 1;
|
||||
g[i] = i;
|
||||
}
|
||||
while (q--)
|
||||
{
|
||||
cin >> a;
|
||||
if (a == 1)
|
||||
{
|
||||
cin >> b >> c;
|
||||
if (mp[g[b]] == 2)
|
||||
cnt--;
|
||||
if (mp[c] == 1)
|
||||
cnt++;
|
||||
mp[g[b]]--;
|
||||
mp[c]++;
|
||||
g[b] = c;
|
||||
}
|
||||
else if (a == 2)
|
||||
cout << cnt << endl;
|
||||
return 0;
|
||||
}
|
37
AtCoder/abc395/A_Strictly_Increasing.cpp
Normal file
37
AtCoder/abc395/A_Strictly_Increasing.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int n, a[1000005], b[1000005];
|
||||
bool f[100000005];
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
b[i] = a[i];
|
||||
if (!f[a[i]]) f[a[i]] = 1;
|
||||
else {
|
||||
cout << "No";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sort(a + 1, a + 1 + n);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
cout << "No";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
cout << "Yes";
|
||||
return 0;
|
||||
}
|
42
AtCoder/abc395/B_Make_Target.cpp
Normal file
42
AtCoder/abc395/B_Make_Target.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define InF InT_MAX
|
||||
#define LLM LOnG_LOnG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int n;
|
||||
|
||||
void wczffl_503()
|
||||
{
|
||||
vector<vector<char>> grid(n, vector<char>(n, '.'));
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
int j = n + 1 - i;
|
||||
if (i > j) continue;
|
||||
|
||||
char fillChar = (i % 2 == 1) ? '#' : '.';
|
||||
|
||||
for (int k = i - 1; k < j; ++k) {
|
||||
for (int l = i - 1; l < j; ++l) {
|
||||
grid[k][l] = fillChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; ++i) {
|
||||
for (int j = 0; j < n; ++j) {
|
||||
cout << grid[i][j];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
signed main() {
|
||||
cin >> n;
|
||||
wczffl_503();
|
||||
return 0;
|
||||
}
|
49
AtCoder/abc395/C_Shortest_Duplicate_Subarray.cpp
Normal file
49
AtCoder/abc395/C_Shortest_Duplicate_Subarray.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int wczffl_503(int N, vector<int>& A) {
|
||||
for (int i = 0; i < N - 1; ++i) {
|
||||
if (A[i] == A[i + 1]) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
unordered_map<int, vector<int>> pos;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
pos[A[i]].push_back(i);
|
||||
}
|
||||
int mn = INT_MAX;
|
||||
for (const auto& entry : pos) {
|
||||
const vector<int>& vt = entry.second;
|
||||
if (vt.size() < 2) continue;
|
||||
|
||||
for (size_t i = 0; i < vt.size() - 1; ++i) {
|
||||
int now = vt[i + 1] - vt[i] + 1;
|
||||
if (now < mn) {
|
||||
mn = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (mn != INT_MAX) ? mn : -1;
|
||||
}
|
||||
|
||||
int N;
|
||||
|
||||
signed main() {
|
||||
cin >> N;
|
||||
vector<int> A(N);
|
||||
for (int i = 0; i < N; ++i) {
|
||||
cin >> A[i];
|
||||
}
|
||||
int res = wczffl_503(N, A);
|
||||
cout << res;
|
||||
return 0;
|
||||
}
|
55
AtCoder/abc395/D_Pigeon_Swap(WA).cpp
Normal file
55
AtCoder/abc395/D_Pigeon_Swap(WA).cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// 这个代码尚未正确,仅作参考价值
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int main() {
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
int N, Q;
|
||||
cin >> N >> Q;
|
||||
vector<int> pigeon_to_nest(N + 1);
|
||||
vector<unordered_set<int>> nest_to_pigeons(N + 1);
|
||||
for (int i = 1; i <= N; ++i) {
|
||||
pigeon_to_nest[i] = i;
|
||||
nest_to_pigeons[i].insert(i);
|
||||
}
|
||||
for (int q = 0; q < Q; ++q) {
|
||||
int type;
|
||||
cin >> type;
|
||||
|
||||
if (type == 1) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
int current_nest = pigeon_to_nest[a];
|
||||
nest_to_pigeons[current_nest].erase(a);
|
||||
pigeon_to_nest[a] = b;
|
||||
nest_to_pigeons[b].insert(a);
|
||||
} else if (type == 2) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
swap(nest_to_pigeons[a], nest_to_pigeons[b]);
|
||||
for (int pigeon : nest_to_pigeons[a]) {
|
||||
pigeon_to_nest[pigeon] = a;
|
||||
}
|
||||
for (int pigeon : nest_to_pigeons[b]) {
|
||||
pigeon_to_nest[pigeon] = b;
|
||||
}
|
||||
} else if (type == 3) {
|
||||
int a;
|
||||
cin >> a;
|
||||
cout << pigeon_to_nest[a] << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
51
CodeForces/Chat Screenshots.cpp
Normal file
51
CodeForces/Chat Screenshots.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
const int N = 200005;
|
||||
struct Edge{
|
||||
int to, nxt;
|
||||
}g[N];
|
||||
int h[N], d[N], idx;
|
||||
int a[N], q[N];
|
||||
void add(int a,int b)
|
||||
{
|
||||
g[++idx].to = b, g[idx].nxt = h[a], h[a] = idx;
|
||||
d[b] ++;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n, k;
|
||||
scanf("%d%d", &n, &k);
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
h[i] = d[i] = 0;
|
||||
idx = 0;
|
||||
for (int i = 1;i <= k; i ++ )
|
||||
{
|
||||
for (int j = 1; j <= n; j ++ )
|
||||
scanf("%d", &a[j]);
|
||||
for (int j = 2; j < n; j ++ )
|
||||
add(a[j], a[j + 1]);
|
||||
}
|
||||
int hh = 0, tt = -1;
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
if (d[i] == 0)
|
||||
q[ ++ tt] = i;
|
||||
while (hh <= tt)
|
||||
{
|
||||
int t = q[hh ++];
|
||||
for (int i = h[t]; i; i = g[i].nxt)
|
||||
{
|
||||
int j = g[i].to;
|
||||
if ( -- d[j] == 0)
|
||||
q[ ++ tt] = j;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
if (d[i] > 0)
|
||||
{
|
||||
cout << "NO";
|
||||
return 0;
|
||||
}
|
||||
cout << "YES";
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int t, k;
|
||||
|
||||
bool wczffl_503(int k) {
|
||||
return (k % 3 == 1);
|
||||
}
|
||||
|
||||
signed main() {
|
||||
cin >> t;
|
||||
while (t--){
|
||||
cin >> k;
|
||||
if (wczffl_503(k)) cout << "YES" << endl;
|
||||
else cout << "NO" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
76
CodeForces/Codeforces Round 1007 (Div. 2)/B_Perfecto.cpp
Normal file
76
CodeForces/Codeforces Round 1007 (Div. 2)/B_Perfecto.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
bool f(lo x) {
|
||||
if (x < 0) return false;
|
||||
lo root = sqrtl(x);
|
||||
return root * root == x;
|
||||
}
|
||||
|
||||
void wczffl_503() {
|
||||
int n;
|
||||
cin >> n;
|
||||
lo total = 1LL * n * (n + 1) / 2;
|
||||
if (f(total)) {
|
||||
cout << "-1\n";
|
||||
return;
|
||||
}
|
||||
vector<lo> s(n + 1);
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
s[i] = (2LL * n - i + 1) * i / 2;
|
||||
}
|
||||
vector<bool> jhd(n + 1, false);
|
||||
for (int i = 1; i <= n - 1; ++i) {
|
||||
if (f(s[i])) {
|
||||
jhd[i] = true;
|
||||
}
|
||||
}
|
||||
bool bad = false;
|
||||
for (int i = 1; i <= n; ++i) {
|
||||
lo now = s[i];
|
||||
if (i <= n - 1 && jhd[i]) {
|
||||
now--;
|
||||
}
|
||||
if (f(now)) {
|
||||
bad = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bad) {
|
||||
cout << "-1\n";
|
||||
return;
|
||||
}
|
||||
vector<int> p(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
p[i] = n - i;
|
||||
}
|
||||
for (int i = 1; i <= n - 1; ++i) {
|
||||
if (jhd[i]) {
|
||||
swap(p[i - 1], p[i]);
|
||||
}
|
||||
}
|
||||
for (int x : p) {
|
||||
cout << x << ' ';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
wczffl_503();
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
#define endl "\n"
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
vector<int> f(int root, const vector<vector<int>>& adj) {
|
||||
vector<int> post_order;
|
||||
stack<tuple<int, int, bool>> s;
|
||||
s.push({root, -1, false});
|
||||
|
||||
while (!s.empty()) {
|
||||
auto [node, parent, visited] = s.top();
|
||||
s.pop();
|
||||
if (visited) {
|
||||
post_order.push_back(node);
|
||||
} else {
|
||||
s.push({node, parent, true});
|
||||
for (int neighbor : adj[node]) {
|
||||
if (neighbor != parent) {
|
||||
s.push({neighbor, node, false});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return post_order;
|
||||
}
|
||||
|
||||
void wczffl_503() {
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n, st, en;
|
||||
cin >> n >> st >> en;
|
||||
vector<vector<int>> adj(n + 1);
|
||||
for (int i = 0; i < n - 1; ++i) {
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
adj[u].push_back(v);
|
||||
adj[v].push_back(u);
|
||||
}
|
||||
|
||||
vector<int> p = f(en, adj);
|
||||
if (p.back() != en) {
|
||||
p.push_back(en);
|
||||
}
|
||||
for (int x : p) {
|
||||
cout << x << ' ';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
wczffl_503();
|
||||
return 0;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
CF题不多,后面会做的!!!!!
|
||||
|
||||
There are not many CodeForces problems, and I'll do later!!!!!
|
53
FZOI/#1074. 「NOIP2005」过河.cpp
Normal file
53
FZOI/#1074. 「NOIP2005」过河.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int f[N], far[N], a[N], flag[N], p, s, t, n;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> p;
|
||||
cin >> s >> t >> n;
|
||||
if (s == t) {
|
||||
int cont = 0, q;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> q;
|
||||
cont += ((q % s) == 0);
|
||||
}
|
||||
cout << cont;
|
||||
return 0;
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
sort(a + 1, a + 1 + n);
|
||||
a[0] = 0;
|
||||
f[0] = 0;
|
||||
far[n + 1] = min(int(p - a[n]), 100);
|
||||
p = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
far[i] = min(a[i] - a[i - 1], 90);
|
||||
p += far[i], flag[p] = 1;
|
||||
}
|
||||
p += far[n + 1];
|
||||
for (int i = 1; i <= p + 9; i++) {
|
||||
f[i] = IMX - 1;
|
||||
for (int j = s; j <= t; j++) {
|
||||
if(i >= j) f[i] = min(f[i], f[i - j] + flag[i]);
|
||||
}
|
||||
}
|
||||
int mn = INT_MAX - 1;
|
||||
for (int i = p; i <= p + 9; i++) mn = min(mn, f[i]);
|
||||
cout << mn;
|
||||
return 0;
|
||||
}
|
62
FZOI/#1203. 「ZJOI2008」树的统计.cpp
Normal file
62
FZOI/#1203. 「ZJOI2008」树的统计.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int fa[N], dep[N], size[N], son[N], top[N], id[N], rev[N];
|
||||
int fir[N];
|
||||
|
||||
struct edge {
|
||||
int to, nex;
|
||||
} arr[N];
|
||||
|
||||
void dfs1(int u, int dad)
|
||||
{
|
||||
size[u] - 1;
|
||||
fa[u] = dad;
|
||||
dep[u] = dep[dad] + 1;
|
||||
for (int i = fir[u]; i != -1; i = arr[i].nex) {
|
||||
int v = arr[i].to;
|
||||
if (v == dad) continue;
|
||||
dfs1(v, u);
|
||||
size[u] += size[v];
|
||||
if (size[v] > size[son[u]]) son[u] = v;
|
||||
}
|
||||
}
|
||||
|
||||
void dfs2(int u) {
|
||||
if (son[u]) {
|
||||
int v = son[u];
|
||||
id[v]++;
|
||||
top[v] = top[u];
|
||||
rev[t] = v;
|
||||
dfs2(v);
|
||||
}
|
||||
for (int i = fir[u]; i != -1; i = arr[i].nex);
|
||||
{
|
||||
int v = arr[i].to;
|
||||
if (!top[v]) {
|
||||
id[v] = ++t;
|
||||
top[v] = v;
|
||||
rev[t] = v;
|
||||
dfs2(v, u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
return 0;
|
||||
}
|
78
FZOI/Fibonacci 前n项和.cpp
Normal file
78
FZOI/Fibonacci 前n项和.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int n, m;
|
||||
int sum = 0;
|
||||
|
||||
struct node
|
||||
{
|
||||
int mat[4][4];
|
||||
};
|
||||
|
||||
node z;
|
||||
|
||||
node matrix_nul(node x, node y)
|
||||
{
|
||||
memset(z.mat, 0, sizeof(z.mat));
|
||||
for(int i = 1; i <= 3; i ++ )
|
||||
{
|
||||
for(int j = 1; j <= 3; j ++ )
|
||||
{
|
||||
for(int k = 1; k <= 3; k ++ )
|
||||
{
|
||||
z.mat[i][j] += (x.mat[i][k]) % m * (y.mat[k][j]) % m;
|
||||
z.mat[i][j] %= m;
|
||||
}
|
||||
}
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
node matrix_pow(int k)
|
||||
{
|
||||
node t, a;
|
||||
t.mat[1][1] = 1;
|
||||
t.mat[1][2] = 1;
|
||||
t.mat[1][3] = 1;
|
||||
a.mat[1][1]=1;
|
||||
a.mat[1][2]=0;
|
||||
a.mat[1][3]=0;
|
||||
a.mat[2][1]=1;
|
||||
a.mat[2][2]=1;
|
||||
a.mat[2][3]=1;
|
||||
a.mat[3][1]=0;
|
||||
a.mat[3][2]=1;
|
||||
a.mat[3][3]=0;
|
||||
while(k)
|
||||
{
|
||||
if(k % 2 == 1) t = matrix_nul(t, a);
|
||||
k /= 2;
|
||||
a = matrix_nul(a, a);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
cin >> n >> m ;
|
||||
node temp;
|
||||
temp = matrix_pow(n - 1);
|
||||
int ans = temp.mat[1][1] * 1 + temp.mat[2][1] * 0;
|
||||
ans %= m;
|
||||
cout << ans % m ;
|
||||
return 0;
|
||||
}
|
36
FZOI/ISBN号码.cpp
Normal file
36
FZOI/ISBN号码.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
char s[13];
|
||||
int main()
|
||||
{
|
||||
int sum;
|
||||
for (int i = 0; i < 13; i++)
|
||||
{
|
||||
cin >> s[i];
|
||||
}
|
||||
|
||||
sum = (s[0] - '0') * 1 + (s[2] - '0') * 2 + (s[3] - '0') * 3 + (s[4] - '0') * 4 + (s[6] - '0') * 5 + (s[7] - '0') * 6 + (s[8] - '0') * 7 + (s[9] - '0') * 8 + (s[10] - '0') * 9;//求和
|
||||
|
||||
if (sum % 11 == s[12] - '0' || (sum % 11 == 10 && s[12] == 'X'))
|
||||
{
|
||||
cout << "Right";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
cout << s[i];
|
||||
}
|
||||
if (sum % 11 == 10)
|
||||
{
|
||||
cout << 'X';
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << sum % 11;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
18
FZOI/NOIP-CSP.cpp
Normal file
18
FZOI/NOIP-CSP.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
string s;
|
||||
cin >> s;
|
||||
int len = s.length();
|
||||
for(int i = 0; i < len; i ++ ){
|
||||
if((s[i] == 'n' || s[i] == 'N') && (s[i+1] == 'o' || s[i + 1] == 'O') && (s[i + 2] == 'i' || s[i + 2] == 'I') && (s[i + 3] == 'P' || s[i + 3] == 'p'))
|
||||
{
|
||||
cout << "CSP";
|
||||
i += 3;
|
||||
|
||||
}
|
||||
else
|
||||
cout << s[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
61
FZOI/Tad 蛋糕.cpp
Normal file
61
FZOI/Tad 蛋糕.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int n, m;
|
||||
int a[1000000];
|
||||
int qzh[1000000];
|
||||
int st[1000000][25];
|
||||
int lg[1000000];
|
||||
|
||||
void init()
|
||||
{
|
||||
lg[1] = 0;
|
||||
for (int i = 2; i <= n; i++)
|
||||
{
|
||||
lg[i] = lg[i / 2] + 1;
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
st[i][0] = qzh[i];
|
||||
}
|
||||
for (int k = 1; k <= lg[m]; k++)
|
||||
{
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
st[i][k] = max(st[i][k - 1], st[min(i + (1 << (k - 1)), n)][k - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
int quary(int l, int r)
|
||||
{
|
||||
int k = lg[r - l + 1];
|
||||
return max(st[l][k], st[r - (1 << k) + 1][k]);
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
qzh[i] = qzh[i - 1] + a[i];
|
||||
}
|
||||
int maxl = -INT_MIN;
|
||||
init();
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
int r = min(i + m - 1, n);
|
||||
int s = quary(i, r) - qzh[i - 1];
|
||||
maxl = max(maxl, s);
|
||||
}
|
||||
cout << maxl;
|
||||
return 0;
|
||||
}
|
61
FZOI/Tad的小蛋糕.cpp
Normal file
61
FZOI/Tad的小蛋糕.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int n, m;
|
||||
int a[1000000];
|
||||
int qzh[1000000];
|
||||
int st[1000000][25];
|
||||
int lg[1000000];
|
||||
|
||||
void init()
|
||||
{
|
||||
lg[1] = 0;
|
||||
for (int i = 2; i <= n; i++)
|
||||
{
|
||||
lg[i] = lg[i / 2] + 1;
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
st[i][0] = qzh[i];
|
||||
}
|
||||
for (int k = 1; k <= lg[m]; k++)
|
||||
{
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
st[i][k] = max(st[i][k - 1], st[min(i + (1 << (k - 1)), n)][k - 1]);
|
||||
}
|
||||
}
|
||||
} // ST表模板 -> 初始化
|
||||
int quary(int l, int r)
|
||||
{
|
||||
int k = lg[r - l + 1];
|
||||
return max(st[l][k], st[r - (1 << k) + 1][k]);
|
||||
} // ST表模板 -> 求最大
|
||||
signed main()
|
||||
{
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
qzh[i] = qzh[i - 1] + a[i];
|
||||
}
|
||||
int maxl = -INT_MIN;
|
||||
init();
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
int r = min(i + m - 1, n);
|
||||
int s = quary(i, r) - qzh[i - 1];
|
||||
maxl = max(maxl, s);
|
||||
}
|
||||
cout << maxl;
|
||||
return 0;
|
||||
}
|
34
FZOI/The kth great number(对顶堆).cpp
Normal file
34
FZOI/The kth great number(对顶堆).cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
signed main()
|
||||
{
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vector<int> nums;
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
char op;
|
||||
cin >> op;
|
||||
|
||||
if (op == 'I')
|
||||
{
|
||||
int num;
|
||||
cin >> num;
|
||||
nums.push_back(num);
|
||||
}
|
||||
else if (op == 'Q')
|
||||
{
|
||||
if (nums.size() >= k)
|
||||
{
|
||||
sort(nums.begin(), nums.end(), greater<int>());
|
||||
cout << nums[k - 1] << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
23
FZOI/Where is Snuke? .cpp
Normal file
23
FZOI/Where is Snuke? .cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
char letter[10005] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
cin >> n >> m ;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
for(int j = 1; j <= m; ++ j)
|
||||
{
|
||||
string a;
|
||||
cin >> a ;
|
||||
if(a == "snuke")
|
||||
{
|
||||
cout << letter[j - 1] << i ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
10
FZOI/[CSP-J 2021] 分糖果.cpp
Normal file
10
FZOI/[CSP-J 2021] 分糖果.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int n, L, R;
|
||||
cin >> n >> L >> R;
|
||||
if(R / n > L / n) cout << n - 1 << endl;
|
||||
else cout << R % n << endl;
|
||||
return 0;
|
||||
}
|
35
FZOI/[CSP-S 2024] 决斗.cpp
Normal file
35
FZOI/[CSP-S 2024] 决斗.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int n;
|
||||
int a[N], cnt[N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
cnt[a[i]]++;
|
||||
}
|
||||
int hui = 0, ans = 0;
|
||||
for (int i = N - 1; i >= 1; i--) {
|
||||
ans += min(cnt[i], hui);
|
||||
hui = max(hui, cnt[i]);
|
||||
}
|
||||
cout << n - ans;
|
||||
return 0;
|
||||
}
|
46
FZOI/[NOIP2015 普及组] 扫雷游戏.cpp
Normal file
46
FZOI/[NOIP2015 普及组] 扫雷游戏.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include<stdio.h>
|
||||
char a[101][101];
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
int n, m;
|
||||
scanf("%d%d", &n,&m);
|
||||
getchar();
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
for(int j = 1; j <= m; j ++ )
|
||||
{
|
||||
scanf("%c", &a[i][j]);
|
||||
}
|
||||
getchar();
|
||||
|
||||
}
|
||||
for (int i = 1; i <= n; i ++ )
|
||||
{
|
||||
for (int j = 1; j <= m; j ++ )
|
||||
{
|
||||
|
||||
if (a[i][j] == '*')
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = 0;
|
||||
if (a[i][j - 1] == '*') count ++ ;
|
||||
if (a[i][j + 1] == '*') count ++ ;
|
||||
if (a[i + 1][j - 1] == '*') count ++ ;
|
||||
if (a[i - 1][j + 1] == '*') count ++ ;
|
||||
if (a[i + 1][j] == '*') count ++ ;
|
||||
if (a[i - 1][j] == '*') count ++ ;
|
||||
if (a[i + 1][j + 1] == '*') count ++ ;
|
||||
if (a[i - 1][j - 1] == '*') count ++ ;
|
||||
printf("%c", count+'0');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
45
FZOI/[USACO08OPEN] Word Power S 0 天 08-20-24.cpp
Normal file
45
FZOI/[USACO08OPEN] Word Power S 0 天 08-20-24.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int n, m, tot[1001];
|
||||
string nx[1001], en[101];
|
||||
|
||||
int f(string nn,string ee)
|
||||
{
|
||||
int now = -1;
|
||||
string::size_type po = 0;
|
||||
for(int i = 0; i < ee.size(); i++)
|
||||
{
|
||||
po = nn.find(ee[i], now+1);
|
||||
if(po == nn.npos)return 0;
|
||||
now = po;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
cin >> nx[i];
|
||||
for(int j = 0; j < nx[i].size(); j ++ )
|
||||
{
|
||||
if(nx[i][j] > 96) nx[i][j] -= 32;
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= m; i ++ )
|
||||
{
|
||||
cin >> en[i];
|
||||
for(int j = 0; j < en[i].size(); j ++ )
|
||||
{
|
||||
if(en[i][j] > 96) en[i][j] -= 32;
|
||||
}
|
||||
|
||||
for(int j = 1; j <= n; j ++ )
|
||||
{
|
||||
if(f(nx[j], en[i])) tot[j] ++ ;
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; i ++ ) cout << tot[i] << endl;
|
||||
}
|
40
FZOI/grouping.cpp
Normal file
40
FZOI/grouping.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int n, mn = IMX;
|
||||
int a[N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i ++ )
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
sort(a, a + n);
|
||||
int cnt = 1;
|
||||
for (int i = 1; i < n; i ++ )
|
||||
{
|
||||
if (a[i] == a[i - 1] + 1)
|
||||
{
|
||||
cnt ++ ;
|
||||
}
|
||||
else
|
||||
{
|
||||
mn = min(mn, cnt);
|
||||
cnt = 1;
|
||||
}
|
||||
}
|
||||
mn = min(mn, cnt);
|
||||
cout << mn << endl;
|
||||
return 0;
|
||||
}
|
37
FZOI/「201912bronze」三值排序.cpp
Normal file
37
FZOI/「201912bronze」三值排序.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#define maxn 1000+5
|
||||
int a[maxn];
|
||||
int main()
|
||||
{
|
||||
int N,num1,num2,num3,sum1,sum2,sum3;
|
||||
cin>>N;
|
||||
num1=num2=num3=sum1=sum2=sum3=0;
|
||||
for(int i=0;i<N;i++)
|
||||
{
|
||||
cin>>a[i];
|
||||
if(a[i]==1)
|
||||
num1++;
|
||||
else if(a[i]==2)
|
||||
num2++;
|
||||
else num3++;
|
||||
}
|
||||
for(int i=0;i<num1;i++)
|
||||
{
|
||||
if(a[i]!=1)
|
||||
sum1++;
|
||||
}
|
||||
for(int i=num1;i<num1+num2;i++)
|
||||
{
|
||||
if(a[i]==3)
|
||||
sum2++;
|
||||
}
|
||||
for(int i=num1+num2;i<N;i++)
|
||||
{
|
||||
|
||||
if(a[i]==2)
|
||||
sum3++;
|
||||
}
|
||||
cout<<sum1+max(sum2,sum3)<<endl;
|
||||
return 0;
|
||||
}
|
133
FZOI/「COCI2006:2007」slikar.cpp
Normal file
133
FZOI/「COCI2006:2007」slikar.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
int n, m;
|
||||
char a[55][55];
|
||||
int fx[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
|
||||
struct node
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int cnt;
|
||||
};
|
||||
int water[55][55];
|
||||
bool h_used[55][55];
|
||||
queue<node> Water;
|
||||
node startt, endd;
|
||||
queue<node> Q;
|
||||
node X[2505];
|
||||
int xid;
|
||||
void Water_Bfs()
|
||||
{
|
||||
while (!Water.empty())
|
||||
{
|
||||
node noww = Water.front();
|
||||
Water.pop();
|
||||
noww.cnt++;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
node _next = noww;
|
||||
_next.x += fx[i][0], _next.y += fx[i][1];
|
||||
if (_next.x < 1 || _next.y < 1 || _next.x > n || _next.y > m)
|
||||
continue;
|
||||
if (h_used[_next.x][_next.y])
|
||||
continue;
|
||||
water[_next.x][_next.y] = min(water[_next.x][_next.y], _next.cnt);
|
||||
Water.push(_next);
|
||||
h_used[_next.x][_next.y] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
void Ans_Bfs()
|
||||
{
|
||||
Q.push(startt);
|
||||
while (!Q.empty())
|
||||
{
|
||||
node noww = Q.front();
|
||||
Q.pop();
|
||||
if (water[noww.x][noww.y] <= noww.cnt)
|
||||
continue;
|
||||
if (noww.x == endd.x && noww.y == endd.y)
|
||||
{
|
||||
cout << noww.cnt;
|
||||
return;
|
||||
}
|
||||
noww.cnt++;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
node _next = noww;
|
||||
_next.x += fx[i][0], _next.y += fx[i][1];
|
||||
if (_next.x < 1 || _next.y < 1 || _next.x > n || _next.y > m)
|
||||
continue;
|
||||
if (h_used[_next.x][_next.y])
|
||||
continue;
|
||||
if (a[_next.x][_next.y] == 'X')
|
||||
continue;
|
||||
Q.push(_next);
|
||||
h_used[_next.x][_next.y] = 1;
|
||||
}
|
||||
}
|
||||
cout << "KAKTUS";
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
memset(water, 127, sizeof(water));
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; ++i)
|
||||
{
|
||||
for (int j = 1; j <= m; ++j)
|
||||
{
|
||||
cin >> a[i][j];
|
||||
if (a[i][j] == 'S')
|
||||
{
|
||||
startt.x = i;
|
||||
startt.y = j;
|
||||
startt.cnt = 0;
|
||||
}
|
||||
if (a[i][j] == 'D')
|
||||
{
|
||||
endd.x = i;
|
||||
endd.y = j;
|
||||
}
|
||||
if (a[i][j] == 'X')
|
||||
{
|
||||
X[xid].x = i;
|
||||
X[xid++].y = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
for (int j = 1; j <= m; j++)
|
||||
{
|
||||
if (a[i][j] == '*')
|
||||
{
|
||||
node w;
|
||||
w.x = i;
|
||||
w.y = j;
|
||||
w.cnt = 0;
|
||||
Water.push(w);
|
||||
water[i][j] = 0;
|
||||
memset(h_used, 0, sizeof(h_used));
|
||||
h_used[endd.x][endd.y] = 1;
|
||||
for (int k = 0; k < xid; k++)
|
||||
{
|
||||
h_used[X[k].x][X[k].y] = 1;
|
||||
}
|
||||
Water_Bfs();
|
||||
}
|
||||
}
|
||||
}
|
||||
water[endd.x][endd.y] = 1e8;
|
||||
memset(h_used, 0, sizeof(h_used));
|
||||
h_used[startt.x][startt.y] = 1;
|
||||
Ans_Bfs();
|
||||
}
|
55
FZOI/「CSP-J2020」优秀的拆分 copy.cpp
Normal file
55
FZOI/「CSP-J2020」优秀的拆分 copy.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int n;
|
||||
|
||||
long long now = 1;
|
||||
|
||||
bool a[N];
|
||||
|
||||
signed main()
|
||||
{
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n % 2 != 0)
|
||||
{
|
||||
printf("-1");
|
||||
return 0;
|
||||
}
|
||||
int i = 0;
|
||||
while (now * 2 <= n)
|
||||
{
|
||||
now *= 2;
|
||||
i++;
|
||||
}
|
||||
int i1 = i;
|
||||
while (now > 1)
|
||||
{
|
||||
if (n - now >= 0)
|
||||
{
|
||||
a[i1] = 1;
|
||||
n -= now;
|
||||
}
|
||||
i1--;
|
||||
now /= 2;
|
||||
}
|
||||
for (int j = i; j >= 1; --j)
|
||||
{
|
||||
if (a[j] == 0)
|
||||
continue;
|
||||
long long ans = pow(2, j);
|
||||
printf("%lld ", ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
21
FZOI/「CSP-J2020」优秀的拆分.cpp
Normal file
21
FZOI/「CSP-J2020」优秀的拆分.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int n, a[30], j, k;
|
||||
int main(){
|
||||
cin >> n;
|
||||
if(n % 2 == 1) cout << -1;
|
||||
else{
|
||||
for(int i = n; i != 0; i /= 2){
|
||||
j ++ ;
|
||||
a[j] = i % 2;
|
||||
}
|
||||
k = j - 1;
|
||||
for(int i = j; i >= 1; i -- ){
|
||||
long long s = pow(2, k);
|
||||
if(a[i] != 0) cout << s << " " ;
|
||||
k -- ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
27
FZOI/「HNOI2003」激光炸弹.cpp
Normal file
27
FZOI/「HNOI2003」激光炸弹.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int maxn = 5005;
|
||||
int s[maxn][maxn];
|
||||
int main(){
|
||||
ios::sync_with_stdio(false);
|
||||
int n,r;
|
||||
cin>>n>>r;
|
||||
int xx=r,yy=r;
|
||||
for(int i=1;i<=n;i++){
|
||||
int x,y,w;
|
||||
cin>>x>>y>>w;
|
||||
x++,y++;
|
||||
s[x][y]+=w;
|
||||
xx=max(xx,x);
|
||||
yy=max(yy,y);
|
||||
}
|
||||
for(int i=1;i<=xx;i++)
|
||||
for(int j=1;j<=yy;j++)
|
||||
s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
|
||||
int ans=0;
|
||||
for(int i=r;i<=xx;i++)
|
||||
for(int j=r;j<=yy;j++)
|
||||
ans=max(ans,s[i][j]-s[i-r][j]-s[i][j-r]+s[i-r][j-r]);
|
||||
cout<<ans;
|
||||
return 0;
|
||||
}
|
24
FZOI/「NOIP2001」数的划分.cpp
Normal file
24
FZOI/「NOIP2001」数的划分.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int n, k, cnt;
|
||||
|
||||
void dfs(int last, int sum, int cur)
|
||||
{
|
||||
if (cur == k)
|
||||
{
|
||||
if (sum == n)
|
||||
cnt++;
|
||||
return;
|
||||
}
|
||||
for (int i = last; sum + i * (k - cur) <= n; i++)
|
||||
dfs(i, sum + i, cur + 1);
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n >> k ;
|
||||
dfs(1, 0, 0);
|
||||
cout << cnt ;
|
||||
}
|
43
FZOI/「NOIP2003 普及组」乒乓球.cpp
Normal file
43
FZOI/「NOIP2003 普及组」乒乓球.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
long long i, k = 0, w = 0, l = 0, w1 = 0, l1 = 0, a[100000], b[100000];
|
||||
char t;
|
||||
int main()
|
||||
{
|
||||
while(t != 'E')
|
||||
{
|
||||
cin >> t;
|
||||
if(t == 'W')
|
||||
{
|
||||
w ++ ;
|
||||
w1 ++ ;
|
||||
}
|
||||
else if(t == 'L')
|
||||
{
|
||||
l ++ ;
|
||||
l1 ++ ;
|
||||
}
|
||||
if((w >= 11 || l >= 11) && abs(w - l) > 1)
|
||||
{
|
||||
cout << w << ":" << l << endl;
|
||||
w = 0;
|
||||
l = 0;
|
||||
}
|
||||
if((w1 >= 21 || l1 >= 21) && abs(w1 - l1) > 1)
|
||||
{
|
||||
k ++ ;
|
||||
a[k] = w1;
|
||||
b[k] = l1;
|
||||
w1 = 0;
|
||||
l1 = 0;
|
||||
}
|
||||
}
|
||||
cout << w << ":" << l << endl << endl;
|
||||
for (i=1;i<=k;i++)
|
||||
cout << a[i] << ":" << b[i] << endl;
|
||||
cout << w1 << ":" << l1;
|
||||
return 0;
|
||||
}
|
59
FZOI/「NOIP2004」合并果子.cpp
Normal file
59
FZOI/「NOIP2004」合并果子.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
using namespace std;
|
||||
|
||||
const int N = 20005;
|
||||
|
||||
int n, heap[N], size;
|
||||
|
||||
void put(int t)
|
||||
{
|
||||
int p1, p2;
|
||||
heap[ ++ size] = t;
|
||||
p1 = size;
|
||||
while(p1 > 1)
|
||||
{
|
||||
p2 = p1 / 2;
|
||||
if(heap[p1] >= heap[p2]) return ;
|
||||
swap(heap[p1], heap[p2]);
|
||||
p1 = p2;
|
||||
}
|
||||
}
|
||||
|
||||
int out()
|
||||
{
|
||||
int p = 1, g, ans;
|
||||
ans = heap[1];
|
||||
heap[1] = heap[size -- ];
|
||||
while(p * 2 <= size)
|
||||
{
|
||||
g = p * 2;
|
||||
if(g < size && heap[g + 1] < heap[g]) g ++ ;
|
||||
if(heap[p] <= heap[g]) return ans;
|
||||
swap(heap[p], heap[g]);
|
||||
p = g;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int ans = 0;
|
||||
cin >> n ;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
int q;
|
||||
cin >> q ;
|
||||
put(q);
|
||||
}
|
||||
size = n;
|
||||
while(size > 1)
|
||||
{
|
||||
int x = out(), y = out();
|
||||
ans += (x + y);
|
||||
put(x + y);
|
||||
}
|
||||
cout << ans ;
|
||||
return 0;
|
||||
}
|
121
FZOI/「NOIP2007」字符串的展开.cpp
Normal file
121
FZOI/「NOIP2007」字符串的展开.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int p1, p2, p3;
|
||||
cin >> p1 >> p2 >> p3 ;
|
||||
string s;
|
||||
cin >> s ;
|
||||
for(int i = 0; i < s.size(); ++ i)
|
||||
{
|
||||
if(s[i] == '-')
|
||||
{
|
||||
if(s[i - 1] >= '0' && s[i - 1] <= '9' && s[i + 1] >= '0' && s[i + 1] <= '9' && s[i + 1] > s[i - 1])
|
||||
{
|
||||
if(p1 != 3)
|
||||
{
|
||||
if(p3 == 1)
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p3 == 2)
|
||||
{
|
||||
for(int j = s[i + 1] - s[i - 1] - 1; j >= 1; -- j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << '*' ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(s[i - 1] >= 'a' && s[i - 1] <= 'z' && s[i + 1] >= 'a' && s[i + 1] <= 'z' && s[i + 1] > s[i - 1])
|
||||
{
|
||||
if(p1 == 1)
|
||||
{
|
||||
if(p3 == 1)
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p3 == 2)
|
||||
{
|
||||
for(int j = s[i + 1] - s[i - 1] - 1; j >= 1; -- j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p1 == 2)
|
||||
{
|
||||
if(p3 == 1)
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j - 32) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(p3 == 2)
|
||||
{
|
||||
for(int j = s[i + 1] - s[i - 1] - 1; j >= 1; -- j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << (char)(s[i - 1] + j - 32) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int j = 1; j < s[i + 1] - s[i - 1]; ++ j)
|
||||
{
|
||||
for(int k = 1; k <= p2; ++ k)
|
||||
{
|
||||
cout << '*' ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << s[i] ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << s[i] ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
26
FZOI/「NOIP2011」铺地毯.cpp
Normal file
26
FZOI/「NOIP2011」铺地毯.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
int a[101000], b[101000], c[101000], d[101000];
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
|
||||
}
|
||||
int num = -1;
|
||||
int x, y;
|
||||
cin >> x >> y;
|
||||
for(int i = n; i >= 1; i--) {
|
||||
if(a[i] <= x && b[i] <= y && c[i] + a[i] >= x && d[i] + b[i] >= y)
|
||||
{
|
||||
num = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cout << num;
|
||||
return 0;
|
||||
}
|
20
FZOI/「NOIP2012」Vigenère 密码.cpp
Normal file
20
FZOI/「NOIP2012」Vigenère 密码.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int k = -1;
|
||||
string a, b;
|
||||
int main(){
|
||||
cin >> b >> a;
|
||||
int lena = a.length(), lenb = b.length();
|
||||
for(int i = 0; i < lena; i ++ ){
|
||||
++ k;
|
||||
if(k == lenb) k -= lenb;
|
||||
char c = tolower(a[i]), d = tolower(b[k]);
|
||||
int x = (c - 'a') - (d - 'a');
|
||||
if(x < 0) x += 26;
|
||||
x ++ ;
|
||||
if(a[i] >= 'a' && a[i] <= 'z') printf("%c", x + 'a' - 1);
|
||||
else printf("%c", x + 'A' - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
33
FZOI/「NOIP2014 普及组」珠心算测验.cpp
Normal file
33
FZOI/「NOIP2014 普及组」珠心算测验.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
bool a[20010];
|
||||
int b[20010];
|
||||
int main()
|
||||
{
|
||||
int n, x, sum = 0;
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
cin >> x;
|
||||
a[x] = 1;
|
||||
}
|
||||
for(int i = 1; i <= 10000; i ++ )
|
||||
{
|
||||
if(a[i] == 1)
|
||||
{
|
||||
for(int j = i + 1; j <= 10000; j ++ )
|
||||
{
|
||||
if(a[j] == 1 && a[i + j] == 1)
|
||||
b[i + j] ++ ;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= 20010; i ++ )
|
||||
{
|
||||
if(b[i] >= 1)
|
||||
sum ++ ;
|
||||
}
|
||||
cout << sum;
|
||||
return 0;
|
||||
}
|
18
FZOI/「NOIP2014」生活大爆炸版石头剪刀布.cpp
Normal file
18
FZOI/「NOIP2014」生活大爆炸版石头剪刀布.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int MAXN = 200 + 10;
|
||||
int n, na, nb, a[MAXN], b[MAXN], cnta, cntb;
|
||||
int vs[5][5] = {{0, 0, 1, 1, 0}, {1, 0, 0, 1, 0}, {0, 1, 0, 0, 1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0}};
|
||||
int main()
|
||||
{
|
||||
cin >> n >> na >> nb;
|
||||
for(int i = 0; i < na; i++) cin >> a[i];
|
||||
for(int i = 0; i < nb; i++) cin >> b[i];
|
||||
for(int i = 0; i < n; i++)
|
||||
{
|
||||
cnta += vs[a[i % na]][b[i % nb]];
|
||||
cntb += vs[b[i % nb]][a[i % na]];
|
||||
}
|
||||
cout << cnta << " " << cntb << endl;
|
||||
return 0;
|
||||
}
|
34
FZOI/「NOIP2016」玩具谜题.cpp
Normal file
34
FZOI/「NOIP2016」玩具谜题.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include<cstdio>
|
||||
using namespace std;
|
||||
const int MAXN = 100010;
|
||||
|
||||
int n, m;
|
||||
struct TOY{
|
||||
int pos;
|
||||
char name[100];
|
||||
};
|
||||
TOY toy[MAXN];
|
||||
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1; i <= n; i ++ ) scanf("%d%s", &toy[i].pos, &toy[i].name);
|
||||
int now = 1;
|
||||
int zy, s;
|
||||
for (int i = 1; i <= m; i ++ )
|
||||
{
|
||||
scanf("%d%d", &zy, &s);
|
||||
if ((toy[now].pos == 0 && zy == 1) || (toy[now].pos == 1 && zy == 0))
|
||||
{
|
||||
now += s;
|
||||
if (now > n) now = now % n;
|
||||
}
|
||||
else
|
||||
{
|
||||
now -= s;
|
||||
if (now <= 0) now = n + now;
|
||||
}
|
||||
}
|
||||
printf("%s", toy[now].name);
|
||||
return 0;
|
||||
}
|
11
FZOI/「NOIP2018 普及组」标题统计.cpp
Normal file
11
FZOI/「NOIP2018 普及组」标题统计.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int i, l;
|
||||
string s;
|
||||
int main(){
|
||||
getline(cin, s);
|
||||
for(i = 0; i < s.size(); i ++ ){
|
||||
if(s[i] != ' ') l ++ ;
|
||||
}
|
||||
cout << l;
|
||||
}
|
42
FZOI/「POJ2456」Aggressive Cows.cpp
Normal file
42
FZOI/「POJ2456」Aggressive Cows.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
int judge(int, int);
|
||||
int arr[100000];
|
||||
int n, c;
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &c);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &arr[i]);
|
||||
}
|
||||
sort(arr, arr + n);
|
||||
int l = arr[0];
|
||||
int r = arr[n - 1] - arr[0];
|
||||
int D;
|
||||
while (r >= l)
|
||||
{
|
||||
D = (l + r) >> 1;
|
||||
if (judge(n, D) >= c)
|
||||
l = D + 1;
|
||||
else
|
||||
r = D - 1;
|
||||
}
|
||||
printf("%d\n", l - 1);
|
||||
return 0;
|
||||
}
|
||||
int judge(int n, int D)
|
||||
{
|
||||
int i, s = 1, p = arr[0];
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
if (arr[i] - p >= D)
|
||||
{
|
||||
s++;
|
||||
p = arr[i];
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
33
FZOI/「USACO1.1」Broken Necklace.cpp
Normal file
33
FZOI/「USACO1.1」Broken Necklace.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
#define N 355
|
||||
using namespace std;
|
||||
|
||||
char a;
|
||||
int b[N];
|
||||
int n, ans;
|
||||
|
||||
int solve(int p, int dir)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
for(int j = p + n; len < n; len ++ , j += dir)
|
||||
{
|
||||
if(b[p] && b[j%n] && b[j % n] != b[p]) break;
|
||||
if(!b[p]) p = j % n;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d ", &n);
|
||||
for(int i = 0; i < n; i ++ )
|
||||
{
|
||||
a = getchar();
|
||||
b[i] = a == 'b' ? 1 : a == 'r' ? 2 : 0;
|
||||
}
|
||||
for(int i = 0; i < n; i ++ ) ans = max(ans, solve(i, - 1) + solve(i + 1, 1));
|
||||
ans = min(ans, n);
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
44
FZOI/「USACO2.4」The Tamworth Two.cpp
Normal file
44
FZOI/「USACO2.4」The Tamworth Two.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 10;
|
||||
char g[N][N];
|
||||
|
||||
int dx[] = {-1, 0, 1, 0};
|
||||
int dy[] = {0, 1, 0, -1};
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
for (int j = 0; j < 10; j++)
|
||||
cin >> g[i][j];
|
||||
int x1, y1, x2, y2;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
if (g[i][j] == 'C') x1 = i, y1 = j;
|
||||
if (g[i][j] == 'F') x2 = i, y2 = j;
|
||||
}
|
||||
}
|
||||
int cd = 0, fd = 0;
|
||||
int cnt = 0;
|
||||
while (true) {
|
||||
if (x1 + dx[cd] >= 10 || x1 + dx[cd] < 0 || y1 + dy[cd] >= 10 || y1 + dy[cd] < 0 || g[x1 + dx[cd]][y1 + dy[cd]] == '*') cd = (cd + 1) % 4;
|
||||
else x1 += dx[cd], y1 += dy[cd];
|
||||
if (x2 + dx[fd] >= 10 || x2 + dx[fd] < 0 || y2 + dy[fd] >= 10 || y2 + dy[fd] < 0 || g[x2 + dx[fd]][y2 + dy[fd]] == '*') fd = (fd + 1) % 4;
|
||||
else x2 += dx[fd], y2 += dy[fd];
|
||||
cnt++;
|
||||
if(x1 == x2 && y1 == y2)
|
||||
{
|
||||
cout << cnt << endl;
|
||||
break;
|
||||
}
|
||||
if (cnt > 1000000)
|
||||
{
|
||||
cout << 0 << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
57
FZOI/「USACO2007JAN」Balanced Lineup.cpp
Normal file
57
FZOI/「USACO2007JAN」Balanced Lineup.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int n, m;
|
||||
int a[100050], dpmax[50005][22], dpmin[50005][21];
|
||||
int LOG[50005];
|
||||
void build()
|
||||
{
|
||||
LOG[0] = -1;
|
||||
for (int i = 1; i <= 50005; i++)
|
||||
LOG[i] = LOG[i >> 1] + 1;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
dpmin[i][0] = dpmax[i][0] = a[i];
|
||||
}
|
||||
int p = log2(n);
|
||||
for (int k = 1; k <= p; k++)
|
||||
{
|
||||
for (int s = 1; s + (1 << k) <= n + 1; s++)
|
||||
{
|
||||
dpmax[s][k] = max(dpmax[s][k - 1], dpmax[s + (1 << (k - 1))][k - 1]);
|
||||
dpmin[s][k] = min(dpmin[s][k - 1], dpmin[s + (1 << (k - 1))][k - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
int query(int l, int r)
|
||||
{
|
||||
int k = LOG[r - l + 1];
|
||||
int x = max(dpmax[l][k], dpmax[r - (1 << k) + 1][k]);
|
||||
int y = min(dpmin[l][k], dpmin[r - (1 << k) + 1][k]);
|
||||
return x - y;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
build();
|
||||
for (int i = 1; i <= m; i++)
|
||||
{
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
cout << query(l, r) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
29
FZOI/「USACO2007JAN」Tallest Cow.cpp
Normal file
29
FZOI/「USACO2007JAN」Tallest Cow.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include<cstdio>
|
||||
#include<cmath>
|
||||
#include<cstring>
|
||||
#include<algorithm>
|
||||
#include<map>
|
||||
using namespace std;
|
||||
|
||||
struct node {
|
||||
int first;
|
||||
int second;
|
||||
}h[10005];
|
||||
int kdl[10005][10005];
|
||||
int n, f[10005], hest, r, t, a, b, c, d;
|
||||
int main() {
|
||||
scanf("%d%d%d%d", &n, &t, &hest, &r);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
f[i] = hest;
|
||||
}
|
||||
for (int i = 1; i <= r; i++) {
|
||||
scanf("%d%d", &a, &b);
|
||||
h[i].first = min(a, b);
|
||||
h[i].second = max(a, b);
|
||||
if (kdl[a][b] == 1)continue;
|
||||
kdl[a][b] = 1;
|
||||
for(int j=h[i].first+1;j<h[i].second;j++)f[j]--;
|
||||
}
|
||||
for(int i=1;i<=n;i++)printf("%d\n",f[i]);
|
||||
return 0;
|
||||
}
|
49
FZOI/「USACO2007MAR」Monthly Expense.cpp
Normal file
49
FZOI/「USACO2007MAR」Monthly Expense.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
int a[110000];
|
||||
int s[110000];
|
||||
int n, m;
|
||||
bool check(int x)
|
||||
{
|
||||
int len = 1, d = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if (a[i] > x)
|
||||
return false;
|
||||
if (d + a[i] > x)
|
||||
{
|
||||
len++;
|
||||
d = a[i];
|
||||
if (len > m)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
d += a[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", &a[i]);
|
||||
int l = 0, r = 1000000000;
|
||||
int ans = 0;
|
||||
while (l <= r)
|
||||
{
|
||||
int mid = (l + r) / 2;
|
||||
if (check(mid) == true)
|
||||
{
|
||||
ans = mid;
|
||||
r = mid - 1;
|
||||
}
|
||||
else
|
||||
l = mid + 1;
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
18
FZOI/「模板」64 位整数乘法.cpp
Normal file
18
FZOI/「模板」64 位整数乘法.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int A, B, P, ANS;
|
||||
__int128 a, b, p, ans;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> A >> B >> P ;
|
||||
a = A;
|
||||
b = B;
|
||||
p = P;
|
||||
ans = a * b % p;
|
||||
ANS = ans;
|
||||
cout << ANS ;
|
||||
return 0;
|
||||
}
|
50
FZOI/「模板」PYB的高斯消元.cpp
Normal file
50
FZOI/「模板」PYB的高斯消元.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int n;
|
||||
double a[M][M];
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n + 1; j++) cin >> a[i][j];
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int flag = 1;
|
||||
for (int j = i; j <= n; j++)
|
||||
{
|
||||
if (fabs(a[j][i]) > 1e-8) {
|
||||
flag = 0;
|
||||
for (int k = 1; k <= n + 1; k ++ ) swap(a[i][k], a[j][k]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
cout << "No Solution" << endl ;
|
||||
return 0;
|
||||
}
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (i != j) {
|
||||
double rate = a[j][i] / a[i][i];
|
||||
for (int k = i; k <= n + 1; k++) a[j][k] -= a[i][k] * rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= n; i++) printf("%.2lf\n", a[i][n + 1] / a[i][i]);
|
||||
return 0;
|
||||
}
|
59
FZOI/「模板」快速排序.cpp
Normal file
59
FZOI/「模板」快速排序.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define ll long long
|
||||
int n, l, num, head[1001], tail[1001], a[100001], ans[100001];
|
||||
void selection_sort(int l, int r)
|
||||
{
|
||||
int length = r - l + 1;
|
||||
for (int i = 1; i <= length; i++)
|
||||
{
|
||||
int aim = l + i - 1;
|
||||
for (int j = l + i - 1; j <= r; j++)
|
||||
if (a[j] < a[aim])
|
||||
aim = j;
|
||||
swap(a[l + i - 1], a[aim]);
|
||||
}
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
|
||||
l = sqrt(n);
|
||||
num = (n - 1) / l + 1;
|
||||
for (int i = 1; i <= num - 1; i++)
|
||||
{
|
||||
head[i] = l * (i - 1) + 1;
|
||||
tail[i] = head[i] + l - 1;
|
||||
}
|
||||
head[num] = l * (num - 1) + 1;
|
||||
tail[num] = n;
|
||||
for (int i = 1; i <= num; i++)
|
||||
selection_sort(head[i], tail[i]);
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
int aim = 0;
|
||||
for (int j = 1; j <= num; j++)
|
||||
if (head[j] <= tail[j])
|
||||
{
|
||||
aim = j;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int j = aim + 1; j <= num; j++)
|
||||
{
|
||||
if (head[j] > tail[j])
|
||||
continue;
|
||||
if (a[head[j]] < a[head[aim]])
|
||||
aim = j;
|
||||
}
|
||||
ans[i] = a[head[aim]];
|
||||
head[aim]++;
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
cout << ans[i] << ' ';
|
||||
return 0;
|
||||
}
|
63
FZOI/【模板】负环.cpp
Normal file
63
FZOI/【模板】负环.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF 0x3f3f3f3f3f3f3f3fl
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const lo N = 1e5 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
struct Edge {
|
||||
lo u, v, w;
|
||||
};
|
||||
|
||||
lo t, n, m;
|
||||
lo c, p, W;
|
||||
|
||||
vector<Edge> edge;
|
||||
|
||||
lo dis[N], u, v, w;
|
||||
|
||||
bool bellmanford(lo n, lo s)
|
||||
{
|
||||
memset(dis, 0x3f, (n + 1) * sizeof(lo));
|
||||
dis[s] = 0;
|
||||
bool flag = false;
|
||||
for (lo i = 1; i <= n; i++) {
|
||||
flag = false;
|
||||
for (lo j = 0; j < edge.size(); j++) {
|
||||
u = edge[j].u, v = edge[j].v, w = edge[j].w;
|
||||
if (dis[u] == INF) continue;
|
||||
if (dis[v] > dis[u] + w) {
|
||||
dis[v] = dis[u] + w;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
edge.clear();
|
||||
cin >> n >> m;
|
||||
for (lo i = 1; i <= m; i++) {
|
||||
cin >> c >> p >> W;
|
||||
edge.push_back({c, p, W});
|
||||
if (W >= 0) edge.push_back({p, c, W});
|
||||
}
|
||||
if (bellmanford(n, 1)) {
|
||||
cout << "YES" << endl;
|
||||
} else {
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
}
|
||||
}
|
37
FZOI/亲密数对.cpp
Normal file
37
FZOI/亲密数对.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int sumOfDivisors(int n) {
|
||||
int sum = 0;
|
||||
for (int i = 2; i * i <= n; i++) {
|
||||
if (n % i == 0) {
|
||||
if(i * i != n)
|
||||
{
|
||||
sum += i;
|
||||
sum += n / i;
|
||||
}
|
||||
else{
|
||||
sum += i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int N;
|
||||
cin >> N;
|
||||
|
||||
for (int i = 2; i <= N; i++) {
|
||||
for(int j = 2; j <= N; ++ j)
|
||||
{
|
||||
if(sumOfDivisors(i) == j && sumOfDivisors(j) == i && i != j)
|
||||
{
|
||||
cout << i << " " << j << endl ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
58
FZOI/任意进制转换.cpp
Normal file
58
FZOI/任意进制转换.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
long long n;
|
||||
cin >> n;
|
||||
|
||||
if(n == 0)
|
||||
{
|
||||
cout << 0 << endl << 0 << endl << 0 ;
|
||||
}
|
||||
|
||||
if(n == 1)
|
||||
{
|
||||
cout << 1 << endl << 1 << endl << 1 ;
|
||||
}
|
||||
|
||||
string binary = "";
|
||||
long long temp = n;
|
||||
while (temp > 0) {
|
||||
binary = to_string(temp % 2) + binary;
|
||||
temp /= 2;
|
||||
}
|
||||
if(n < 0)
|
||||
{
|
||||
cout << 1 << binary << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << binary << endl;
|
||||
}
|
||||
|
||||
|
||||
string octal = "";
|
||||
temp = n;
|
||||
while (temp > 0) {
|
||||
octal = to_string(temp % 8) + octal;
|
||||
temp /= 8;
|
||||
}
|
||||
cout << octal << endl;
|
||||
|
||||
string hex = "";
|
||||
temp = n;
|
||||
while (temp > 0) {
|
||||
long long remainder = temp % 16;
|
||||
if (remainder < 10) {
|
||||
hex = to_string(remainder) + hex;
|
||||
} else {
|
||||
hex = static_cast<char>('A' + (remainder - 10)) + hex;
|
||||
}
|
||||
temp /= 16;
|
||||
}
|
||||
cout << hex << endl;
|
||||
|
||||
return 0;
|
||||
}
|
20
FZOI/你知道ABC么? .cpp
Normal file
20
FZOI/你知道ABC么? .cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include<iostream>
|
||||
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
typedef pair<int ,string> PII;
|
||||
#define x first
|
||||
#define y second
|
||||
const int N = 1e4+10;
|
||||
const int mod = 100000007;
|
||||
|
||||
int main(){
|
||||
int a[10];
|
||||
for(int i = 0; i < 7; i ++ )
|
||||
cin >> a[i];
|
||||
sort(a, a+7);
|
||||
printf("%d %d %d",a[0],a[1],a[6]-a[0]-a[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
16
FZOI/俄罗斯方块.cpp
Normal file
16
FZOI/俄罗斯方块.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include<cstdio>
|
||||
int n,a,tag;
|
||||
bool pos=true;
|
||||
signed main(void){
|
||||
scanf("%d",&n);
|
||||
scanf("%d" ,&a);
|
||||
tag =(a&1);
|
||||
for(int i=1;i<n;i++){
|
||||
scanf("%d",&a);
|
||||
if((a&1)!=tag){
|
||||
pos=false;
|
||||
}
|
||||
}
|
||||
printf("%d\n",pos?1:0);
|
||||
return 0;
|
||||
}
|
29
FZOI/全排列问题.cpp
Normal file
29
FZOI/全排列问题.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int n, arr[1030], ans[10];
|
||||
void dfs(int i, int s)
|
||||
{
|
||||
if (i > n)
|
||||
{
|
||||
for (int p = 1; p <= n; p++) printf("%5d", ans[p]);
|
||||
cout << endl;
|
||||
return;
|
||||
}
|
||||
for (int j = s; j > 0; j -= j & (-j))
|
||||
{
|
||||
int temp = j & (-j);
|
||||
ans[i] = arr[temp];
|
||||
dfs(i + 1, s - temp);
|
||||
}
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
arr[1] = 1;
|
||||
for (int i = 2; i <= n; i++)
|
||||
arr[1 << (i - 1)] = i;
|
||||
dfs(1, (1 << n) - 1);
|
||||
return 0;
|
||||
}
|
75
FZOI/分组(groping).cpp
Normal file
75
FZOI/分组(groping).cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
// 判定函数:给定组的最小人数为x,判断是否可以分组
|
||||
bool canGroup(const vector<int>& a, int x) {
|
||||
int n = a.size();
|
||||
int count = 0; // 记录已经分成的组数量
|
||||
int group_size = 1; // 当前组的队员人数
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (a[i] == a[i - 1] + 1) {
|
||||
// 实力值连续,当前组人数增加
|
||||
group_size++;
|
||||
} else {
|
||||
// 实力值不连续,组结束
|
||||
if (group_size >= x) {
|
||||
count++; // 记录一个符合条件的组
|
||||
}
|
||||
group_size = 1; // 开始新组
|
||||
}
|
||||
}
|
||||
|
||||
// 更新最后一组的判断
|
||||
if (group_size >= x) {
|
||||
count++;
|
||||
}
|
||||
|
||||
// 如果我们可以将所有人分成符合条件的组,返回true
|
||||
return count * x <= n;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
int n;
|
||||
cin >> n; // 读取队员数量
|
||||
vector<int> a(n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> a[i]; // 读取每个队员的实力值
|
||||
}
|
||||
|
||||
// 对实力值进行排序
|
||||
sort(a.begin(), a.end());
|
||||
|
||||
// 使用二分查找最小组人数的最大值
|
||||
int left = 1, right = n;
|
||||
int ans = 1;
|
||||
|
||||
while (left <= right) {
|
||||
int mid = left + (right - left) / 2;
|
||||
|
||||
if (canGroup(a, mid)) {
|
||||
// 如果可以分组,尝试更大的值
|
||||
ans = mid;
|
||||
left = mid + 1;
|
||||
} else {
|
||||
// 否则尝试更小的值
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 输出最小的组人数的最大值
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
56
FZOI/分身术.cpp
Normal file
56
FZOI/分身术.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define fp(_a, _b, _c, _d) for (int _a = _b; _a <= _c; _a += _d)
|
||||
#define fm(_a, _b, _c, _d) for (int _a = _b; _a <= _c; _a -= _d)
|
||||
#define fin(_a, _b) for (int ss = 1; ss <= _a; ss++) cin >> _b[ss];
|
||||
#define fout(_a, _b, _c) for (int ss = 1; ss <= _a; ss++) cout << _b[ss] << _c;
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
@author: BunDragon126
|
||||
@link: https://www.setbun.com/
|
||||
*/
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int n, k;
|
||||
vector<int> a(N), b(N);
|
||||
deque<int> deque1, deque2;
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
cin >> n >> k;
|
||||
for (int i = 0; i < n; ++ i) cin >> a[i];
|
||||
for (int i = 0; i < n; ++ i) cin >> b[i];
|
||||
int mn = n + 1;
|
||||
for (int l = 0, r = 0; r < n; ++ r)
|
||||
{
|
||||
while (!deque1.empty() && a[deque1.back()] >= a[r])
|
||||
deque1.pop_back();
|
||||
deque1.push_back(r);
|
||||
while (!deque2.empty() && b[deque2.back()] <= b[r])
|
||||
deque2.pop_back();
|
||||
deque2.push_back(r);
|
||||
while (a[deque1.front()] <= k && b[deque2.front()] > a[deque1.front()])
|
||||
{
|
||||
mn = min(mn, r - l + 1);
|
||||
if (deque1.front() == l)
|
||||
deque1.pop_front();
|
||||
if (deque2.front() == l)
|
||||
deque2.pop_front();
|
||||
++ l;
|
||||
}
|
||||
}
|
||||
if (mn == n + 1)
|
||||
{
|
||||
cout << "So Sad!" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << mn << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
51
FZOI/区间最大值.cpp
Normal file
51
FZOI/区间最大值.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
|
||||
int n, m;
|
||||
int a[100050], dpmax[100050][100];
|
||||
int LOG[500005];
|
||||
void build()
|
||||
{
|
||||
LOG[0] = -1;
|
||||
for (int i = 1; i <= 500005; i++)
|
||||
LOG[i] = LOG[i >> 1] + 1;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
dpmax[i][0] = a[i];
|
||||
}
|
||||
int p = log2(n);
|
||||
for (int k = 1; k <= p; k++) {
|
||||
for (int s = 1; s + (1 << k) <= n + 1; s++) {
|
||||
dpmax[s][k] = max(dpmax[s][k - 1], dpmax[s + (1 << (k - 1))][k - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
int query(int l, int r)
|
||||
{
|
||||
int k = LOG[r - l + 1];
|
||||
int x = max(dpmax[l][k], dpmax[r - (1 << k) + 1][k]);
|
||||
return x;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
"toothless. #17";
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
build();
|
||||
for (int i = 1; i <= m; i++) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
cout << query(l, r) << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
32
FZOI/去重.cpp
Normal file
32
FZOI/去重.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int n;
|
||||
int a[N];
|
||||
map<int, bool> mp;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i ++ ) {
|
||||
cin >> a[i];
|
||||
}
|
||||
for (int i = 1; i <= n; i ++ ) {
|
||||
if (!mp[a[i]]) {
|
||||
cout << a[i] << " ";
|
||||
mp[a[i]] = true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
20
FZOI/取余运算 加强版.cpp
Normal file
20
FZOI/取余运算 加强版.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int m;
|
||||
|
||||
int f(int a, int b)
|
||||
{
|
||||
if(b == 0) return 1 % m;
|
||||
else if(b % 2 == 1) return (f(a, (b - 1)) * a) % m;
|
||||
return (f(a, b / 2) * f(a, b / 2)) % m;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int a, b;
|
||||
cin >> a >> b >> m ;
|
||||
cout << a << "^" << b << " mod " << m << "=" << f(a, b) ;
|
||||
return 0;
|
||||
}
|
56
FZOI/四色问题.cpp
Normal file
56
FZOI/四色问题.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 8;
|
||||
int n;
|
||||
int arr[MAXN][MAXN];
|
||||
int color[MAXN];
|
||||
int ans;
|
||||
|
||||
bool f(int v, int c)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (arr[v][i] && color[i] == c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void dfs(int v)
|
||||
{
|
||||
if (v == n)
|
||||
{
|
||||
ans++;
|
||||
return;
|
||||
}
|
||||
for (int c = 1; c <= 4; c++)
|
||||
{
|
||||
if (f(v, c))
|
||||
{
|
||||
color[v] = c;
|
||||
dfs(v + 1);
|
||||
color[v] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
memset(color, 0, sizeof(color));
|
||||
ans = 0;
|
||||
dfs(0);
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
33
FZOI/回文数个数.cpp
Normal file
33
FZOI/回文数个数.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isPalindrome(int num) {
|
||||
string str = to_string(num);
|
||||
int left = 0, right = str.length() - 1;
|
||||
while (left < right) {
|
||||
if (str[left] != str[right]) {
|
||||
return false;
|
||||
}
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (isPalindrome(i)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
53
FZOI/地毯填补.cpp
Normal file
53
FZOI/地毯填补.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <iostream>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
int kr, x, y;
|
||||
void fenz(int wx, int wy, int a, int b, int k);
|
||||
signed main()
|
||||
{
|
||||
cin >> kr >> x >> y;
|
||||
fenz(1, 1, x, y, kr);
|
||||
return 0;
|
||||
}
|
||||
void fenz(int wx, int wy, int a, int b, int k)
|
||||
{
|
||||
if (k == 0)
|
||||
return;
|
||||
int lsa = 2 << (k - 2);
|
||||
if (k == 1)
|
||||
lsa = 1;
|
||||
int midx = wx + lsa;
|
||||
int midy = wy + lsa;
|
||||
if (a < midx && midy <= b)
|
||||
{
|
||||
printf("%d %d %d\n", midx, midy - 1, 1);
|
||||
fenz(wx, wy, midx - 1, midy - 1, k - 1);
|
||||
fenz(wx, midy, a, b, k - 1);
|
||||
fenz(midx, wy, midx, midy - 1, k - 1);
|
||||
fenz(midx, midy, midx, midy, k - 1);
|
||||
}
|
||||
else if (midx <= a && midy > b)
|
||||
{
|
||||
printf("%d %d %d\n", midx - 1, midy, 2);
|
||||
fenz(wx, wy, midx - 1, midy - 1, k - 1);
|
||||
fenz(wx, midy, midx - 1, midy, k - 1);
|
||||
fenz(midx, wy, a, b, k - 1);
|
||||
fenz(midx, midy, midx, midy, k - 1);
|
||||
}
|
||||
else if (a < midx && b < midy)
|
||||
{
|
||||
printf("%d %d %d\n", midx, midy, 3);
|
||||
fenz(wx, wy, a, b, k - 1);
|
||||
fenz(wx, midy, midx - 1, midy, k - 1);
|
||||
fenz(midx, wy, midx, midy - 1, k - 1);
|
||||
fenz(midx, midy, midx, midy, k - 1);
|
||||
}
|
||||
else if (midx <= a && midy <= b)
|
||||
{
|
||||
printf("%d %d %d\n", midx - 1, midy - 1, 4);
|
||||
fenz(wx, wy, midx - 1, midy - 1, k - 1);
|
||||
fenz(wx, midy, midx - 1, midy, k - 1);
|
||||
fenz(midx, wy, midx, midy - 1, k - 1);
|
||||
fenz(midx, midy, a, b, k - 1);
|
||||
}
|
||||
}
|
57
FZOI/堆【模板题】.cpp
Normal file
57
FZOI/堆【模板题】.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
using namespace std;
|
||||
|
||||
const int N = 20005;
|
||||
|
||||
int n, heap[N], size;
|
||||
|
||||
void add(int t)
|
||||
{
|
||||
int p1, p2;
|
||||
heap[ ++ size] = t;
|
||||
p1 = size;
|
||||
while(p1 > 1)
|
||||
{
|
||||
p2 = p1 / 2;
|
||||
if(heap[p1] >= heap[p2]) return ;
|
||||
swap(heap[p1], heap[p2]);
|
||||
p1 = p2;
|
||||
}
|
||||
}
|
||||
|
||||
void out()
|
||||
{
|
||||
int p = 1, g, ans;
|
||||
ans = heap[1];
|
||||
heap[1] = heap[size -- ];
|
||||
while(p * 2 <= size)
|
||||
{
|
||||
g = p * 2;
|
||||
if(g < size && heap[g + 1] < heap[g]) g ++ ;
|
||||
if(heap[p] <= heap[g]) return ;
|
||||
swap(heap[p], heap[g]);
|
||||
p = g;
|
||||
}
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int ans = 0;
|
||||
cin >> n ;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
int q;
|
||||
cin >> q ;
|
||||
if(q == 1)
|
||||
{
|
||||
int x;
|
||||
cin >> x;
|
||||
add(x);
|
||||
}
|
||||
else if(q == 2) cout << heap[1] << endl ;
|
||||
else out();
|
||||
}
|
||||
return 0;
|
||||
}
|
66
FZOI/复制书稿.cpp
Normal file
66
FZOI/复制书稿.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int n, m;
|
||||
int a[505];
|
||||
int x[505], y[505];
|
||||
|
||||
bool check(int s)
|
||||
{
|
||||
int num = 1, t = 0;
|
||||
for (int i = n; i >= 1; i--)
|
||||
{
|
||||
if (t + a[i] > s)
|
||||
t = 0, num++;
|
||||
t += a[i];
|
||||
}
|
||||
return num <= m;
|
||||
}
|
||||
|
||||
int find(int low, int high)
|
||||
{
|
||||
int mid;
|
||||
while (low + 1 < high)
|
||||
{
|
||||
mid = low + (high - low) / 2;
|
||||
if (check(mid))
|
||||
high = mid;
|
||||
else
|
||||
low = mid;
|
||||
}
|
||||
return high;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int low = 0, high = 0;
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
cin >> a[i];
|
||||
high += a[i];
|
||||
low = max(low, a[i]);
|
||||
}
|
||||
int s = find(low, high);
|
||||
int t = 0, num = 1;
|
||||
for (int i = 1; i <= m; i++)
|
||||
x[i] = y[i] = 0;
|
||||
|
||||
y[1] = n;
|
||||
for (int i = n; i >= 1; i--)
|
||||
{
|
||||
if (t + a[i] > s)
|
||||
{
|
||||
t = 0;
|
||||
x[num] = i + 1;
|
||||
y[++num] = i;
|
||||
}
|
||||
t += a[i];
|
||||
}
|
||||
x[num] = 1;
|
||||
|
||||
for (int i = m; i >= 1; i--)
|
||||
cout << x[i] << " " << y[i] << endl;
|
||||
return 0;
|
||||
}
|
28
FZOI/奇怪的电梯.cpp
Normal file
28
FZOI/奇怪的电梯.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
int n, a, b, k[201], dis[201];
|
||||
|
||||
void dfs(int node, int step)
|
||||
{
|
||||
dis[node] = step;
|
||||
int v = node - k[node];
|
||||
if (1 <= v && step + 1 < dis[v])
|
||||
dfs(v, step + 1);
|
||||
v = node + k[node];
|
||||
if (v <= n && step + 1 < dis[v])
|
||||
dfs(v, step + 1);
|
||||
return;
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
memset(dis, 0x3f, sizeof(dis));
|
||||
cin >> n >> a >> b;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> k[i];
|
||||
dfs(a, 0);
|
||||
if(dis[b] == 0x3f3f3f3f3f3f3f3f) cout << -1 << endl;
|
||||
else cout << dis[b] << endl;
|
||||
return 0;
|
||||
}
|
20
FZOI/字符串翻转 .cpp
Normal file
20
FZOI/字符串翻转 .cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
string str;
|
||||
string inpt;
|
||||
while(true)
|
||||
{
|
||||
cin >> inpt ;
|
||||
if(inpt == ".")
|
||||
{
|
||||
break;
|
||||
}
|
||||
inpt.append(1, ' ');
|
||||
str.insert(0, inpt);
|
||||
}
|
||||
cout << str ;
|
||||
return 0;
|
||||
}
|
31
FZOI/字符数组合并 .cpp
Normal file
31
FZOI/字符数组合并 .cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int arr[100005];
|
||||
|
||||
int main()
|
||||
{
|
||||
int cnt = 0;
|
||||
char ch;
|
||||
while(cnt < 2)
|
||||
{
|
||||
ch = getchar();
|
||||
|
||||
if(ch == '.')
|
||||
{
|
||||
cnt ++ ;
|
||||
}
|
||||
if(ch >= 'a' && ch <= 'z')
|
||||
{
|
||||
arr[ch] ++ ;
|
||||
}
|
||||
}
|
||||
for(int i = 97; i <= 121; ++ i)
|
||||
{
|
||||
for(int j = 1; j <= arr[i]; ++ j)
|
||||
{
|
||||
cout << (char)i ;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
36
FZOI/工作分配问题.cpp
Normal file
36
FZOI/工作分配问题.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 20;
|
||||
int n;
|
||||
int arr[MAXN][MAXN];
|
||||
int mn;
|
||||
void f()
|
||||
{
|
||||
mn = INT_MAX;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int cnt = 0;
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
cnt += arr[j][i];
|
||||
}
|
||||
mn = min(mn, cnt);
|
||||
}
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
f();
|
||||
cout << mn << endl;
|
||||
return 0;
|
||||
}
|
42
FZOI/循环赛日程表.cpp
Normal file
42
FZOI/循环赛日程表.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
void f(vector<vector<int>> &vt, int n)
|
||||
{
|
||||
if (n == 1)
|
||||
{
|
||||
vt[0][0] = 0;
|
||||
return;
|
||||
}
|
||||
int m = n / 2;
|
||||
f(vt, m);
|
||||
for (int i = 0; i < m; ++i)
|
||||
{
|
||||
for (int j = 0; j < m; ++j)
|
||||
{
|
||||
vt[i][j + m] = vt[i][j] + m;
|
||||
vt[i + m][j] = vt[i][j + m];
|
||||
vt[i + m][j + m] = vt[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int m;
|
||||
cin >> m;
|
||||
int n = pow(2, m);
|
||||
vector<vector<int>> vt(n, vector<int>(n));
|
||||
f(vt, n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
for (int j = 0; j < n; ++j)
|
||||
{
|
||||
cout << vt[i][j] + 1 << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
38
FZOI/找拖后腿的.cpp
Normal file
38
FZOI/找拖后腿的.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int n;
|
||||
|
||||
struct stu
|
||||
{
|
||||
int id, sc;
|
||||
} name[N];
|
||||
|
||||
|
||||
int g;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
name[i].id = i;
|
||||
cin >> name[i].sc;
|
||||
g += name[i].sc;
|
||||
}
|
||||
g /= n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if(name[i].sc < g) cout << name[i].id << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
50
FZOI/括号匹配.cpp
Normal file
50
FZOI/括号匹配.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
bool f(const string &s)
|
||||
{
|
||||
stack<char> st;
|
||||
|
||||
for (char c : s)
|
||||
{
|
||||
if (c == '(' || c == '[')
|
||||
{
|
||||
st.push(c);
|
||||
}
|
||||
else if (c == ')' || c == ']')
|
||||
{
|
||||
if (st.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char top = st.top();
|
||||
st.pop();
|
||||
|
||||
if ((c == ')' && top != '(') || (c == ']' && top != '['))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return st.empty();
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
string s;
|
||||
cin >> s;
|
||||
|
||||
if (f(s))
|
||||
{
|
||||
cout << "OK" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Wrong" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
32
FZOI/插入.cpp
Normal file
32
FZOI/插入.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if(dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
int n;
|
||||
int a[N];
|
||||
int m;
|
||||
|
||||
signed main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
cin >> m;
|
||||
a[n + 1] = m;
|
||||
sort(a + 1, a + n + 2);
|
||||
for (int i = 1; i <= n + 1; i++) {
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
30
FZOI/数位递增数.cpp
Normal file
30
FZOI/数位递增数.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isIncreasingNumber(int n) {
|
||||
string num = to_string(n);
|
||||
for (int i = 0; i < num.size() - 1; i++) {
|
||||
if (num[i] > num[i + 1]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 10; i <= n; i++) {
|
||||
if (isIncreasingNumber(i)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
46
FZOI/数列分段.cpp
Normal file
46
FZOI/数列分段.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int maxn = 1e5 + 5;
|
||||
int n, m, l, r;
|
||||
int a[maxn];
|
||||
bool check(int x)
|
||||
{
|
||||
int sum = 0, num = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if (sum + a[i] <= x)
|
||||
{
|
||||
sum += a[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
sum = a[i];
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return num >= m;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d %d", &n, &m);
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
l = max(l, a[i]);
|
||||
r += a[i];
|
||||
}
|
||||
while (l <= r)
|
||||
{
|
||||
int mid = (l + r) / 2;
|
||||
if (check(mid))
|
||||
{
|
||||
l = mid + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
printf("%d", l);
|
||||
return 0;
|
||||
}
|
23
FZOI/数列分段2.cpp
Normal file
23
FZOI/数列分段2.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
int n, m, a[100010], ans, sum;
|
||||
int main()
|
||||
{
|
||||
cin >> n >> m;
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
cin >> a[i];
|
||||
for(int i = 1; i <= n; i ++ )
|
||||
{
|
||||
if(sum + a[i] < m) sum += a[i];
|
||||
else
|
||||
{
|
||||
ans ++ ;
|
||||
if(sum + a[i] > m) sum = a[i];
|
||||
else sum=0;
|
||||
}
|
||||
}
|
||||
ans += (sum > 0);
|
||||
cout << ans;
|
||||
return 0;
|
||||
}
|
38
FZOI/数的组合.cpp
Normal file
38
FZOI/数的组合.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#define int long long
|
||||
|
||||
using namespace std;
|
||||
|
||||
int m, cnt = 0;
|
||||
|
||||
void f(int n, vector<int>& vt, int start) {
|
||||
if (n == 0) {
|
||||
cout << m << "=" << vt[0];
|
||||
for (int i = 1; i < vt.size(); i++) {
|
||||
cout << "+" << vt[i];
|
||||
}
|
||||
cout << endl ;
|
||||
cnt ++ ;
|
||||
} else {
|
||||
for (int i = start; i >= 1; i--) {
|
||||
if (n >= i) {
|
||||
vt.push_back(i);
|
||||
f(n - i, vt, i);
|
||||
vt.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signed main() {
|
||||
cin >> m;
|
||||
|
||||
vector<int> vt;
|
||||
f(m, vt, m - 1);
|
||||
|
||||
cout << "total=" << cnt << endl;
|
||||
|
||||
return 0;
|
||||
}
|
111
FZOI/数的计数 + 输出.cpp
Normal file
111
FZOI/数的计数 + 输出.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
#define IMX LONG_LONG_MAX
|
||||
#define IMN LONG_LONG_MIN
|
||||
#define debug$ if (dev)
|
||||
using namespace std;
|
||||
|
||||
/* toothless. #17 */
|
||||
|
||||
const int N = 1e7 + 10;
|
||||
const int M = 2e3 + 5;
|
||||
const bool dev = false;
|
||||
|
||||
string s;
|
||||
int len, last, pre, x, flag, cs;
|
||||
char ch;
|
||||
vector<string> lstr, rstr;
|
||||
|
||||
bool iszf(char ch)
|
||||
{
|
||||
return ch == '+' || ch == '-' || ch == '*' || ch == '/';
|
||||
}
|
||||
|
||||
bool is_num(char s)
|
||||
{
|
||||
return s >= '0' && s <= '9';
|
||||
}
|
||||
|
||||
bool is_str(const std::string &s)
|
||||
{
|
||||
char *endptr;
|
||||
strtod(s.c_str(), &endptr);
|
||||
return !(*endptr == '\0');
|
||||
}
|
||||
|
||||
int renum(string s)
|
||||
{
|
||||
string t = s.substr(0, s.size());
|
||||
return stoi(t);
|
||||
}
|
||||
void print()
|
||||
{
|
||||
int ll = lstr.size();
|
||||
for (int i = 0; i < ll; i ++ )
|
||||
cout << lstr[i] << ' ';
|
||||
cout << endl ;
|
||||
ll = rstr.size();
|
||||
for (int i = 0; i < ll; i ++ )
|
||||
cout << rstr[i] << ' ';
|
||||
cout << endl ;
|
||||
}
|
||||
|
||||
bool is_ch(char ch)
|
||||
{
|
||||
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
ch = ' ';
|
||||
getline(cin, s);
|
||||
len = s.size();
|
||||
for (int i = 0; i < s.size(); i++)
|
||||
{
|
||||
if (!(is_num(s[i])) && !iszf(s[i]) && is_ch(s[i]))
|
||||
ch = s[i];
|
||||
if (s[i] == '=')
|
||||
{
|
||||
flag = 1;
|
||||
lstr.push_back(s.substr(last, i - last));
|
||||
last = i + 1;
|
||||
pre = i;
|
||||
}
|
||||
if (iszf(s[i]))
|
||||
{
|
||||
string wxh = s.substr(last, i - last);
|
||||
if (wxh.size() == 1 && is_str(wxh))
|
||||
{
|
||||
wxh.insert(0, "1");
|
||||
}
|
||||
if (!flag)
|
||||
lstr.push_back(wxh);
|
||||
else
|
||||
rstr.push_back(wxh);
|
||||
last = i;
|
||||
}
|
||||
}
|
||||
string wty = s.substr(last, s.size() - last);
|
||||
if (wty.size() == 1 && is_str(wty))
|
||||
wty.insert(0, "1");
|
||||
rstr.push_back(wty);
|
||||
int l = lstr.size();
|
||||
for (int i = 0; i < l; i ++ )
|
||||
{
|
||||
if (!is_str(lstr[i]))
|
||||
cs += stod(lstr[i]);
|
||||
else
|
||||
x -= renum(lstr[i]);
|
||||
}
|
||||
l = rstr.size();
|
||||
for (int i = 0; i < l; i ++ )
|
||||
{
|
||||
if (!is_str(rstr[i]))
|
||||
cs -= stod(rstr[i]);
|
||||
else
|
||||
x += renum(rstr[i]);
|
||||
}
|
||||
double cnt = cs * 1.0 / (x == 0 ? 1 : x);
|
||||
printf("%c=%.3lf", ch, cnt);
|
||||
return 0;
|
||||
}
|
69
FZOI/最小花费.cpp
Normal file
69
FZOI/最小花费.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int n, m;
|
||||
struct Node
|
||||
{
|
||||
int x;
|
||||
double z;
|
||||
};
|
||||
vector<Node> g[100001];
|
||||
double d[100001];
|
||||
bool b[100001];
|
||||
void asdf(int x)
|
||||
{
|
||||
fill(d, d + 100001, 0x7f7f7f7f);
|
||||
priority_queue<pair<double, int>> q;
|
||||
d[x] = 100.0;
|
||||
q.push(make_pair(100.0, x));
|
||||
while (!q.empty())
|
||||
{
|
||||
int ax = q.top().second;
|
||||
q.pop();
|
||||
if (b[ax] == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
b[ax] = 1;
|
||||
for (int i = 0; i < g[ax].size(); i++)
|
||||
{
|
||||
if (d[ax] / g[ax][i].z < d[g[ax][i].x])
|
||||
{
|
||||
q.push(make_pair(-d[ax] / g[ax][i].z, g[ax][i].x));
|
||||
d[g[ax][i].x] = d[ax] / g[ax][i].z;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
scanf("%d", &n);
|
||||
scanf("%d", &m);
|
||||
for (int i = 1; i <= m; i++)
|
||||
{
|
||||
int x, y;
|
||||
int z;
|
||||
scanf("%d%d%d", &x, &y, &z);
|
||||
Node u, p;
|
||||
u.x = y;
|
||||
u.z = 1 - z * 1.0 / 100.0;
|
||||
p.x = x;
|
||||
p.z = 1 - z * 1.0 / 100.0;
|
||||
g[x].push_back(u);
|
||||
g[y].push_back(p);
|
||||
}
|
||||
int s, t;
|
||||
scanf("%d%d", &s, &t);
|
||||
asdf(t);
|
||||
printf("%.8lf", d[s]);
|
||||
return 0;
|
||||
}
|
63
FZOI/最少步数.cpp
Normal file
63
FZOI/最少步数.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
|
||||
const int N = 100;
|
||||
const vector<pair<int, int>> knight_moves = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, 2}, {1, -2}, {-1, 2}, {-1, -2}};
|
||||
const vector<pair<int, int>> elephant_moves = {{2, 2}, {2, -2}, {-2, 2}, {-2, -2}};
|
||||
|
||||
int bfs(int start_x, int start_y)
|
||||
{
|
||||
vector<vector<bool>> vis(N + 1, vector<bool>(N + 1, false));
|
||||
queue<tuple<int, int, int>> que;
|
||||
que.push({start_x, start_y, 0});
|
||||
vis[start_x][start_y] = true;
|
||||
|
||||
while (!que.empty())
|
||||
{
|
||||
auto [x, y, steps] = que.front();
|
||||
que.pop();
|
||||
|
||||
if (x == 1 && y == 1)
|
||||
{
|
||||
return steps;
|
||||
}
|
||||
for (const auto &move : knight_moves)
|
||||
{
|
||||
int nx = x + move.first;
|
||||
int ny = y + move.second;
|
||||
if (nx >= 1 && nx <= N && ny >= 1 && ny <= N && !vis[nx][ny])
|
||||
{
|
||||
vis[nx][ny] = true;
|
||||
que.push({nx, ny, steps + 1});
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &move : elephant_moves)
|
||||
{
|
||||
int nx = x + move.first;
|
||||
int ny = y + move.second;
|
||||
if (nx >= 1 && nx <= N && ny >= 1 && ny <= N && !vis[nx][ny])
|
||||
{
|
||||
vis[nx][ny] = true;
|
||||
que.push({nx, ny, steps + 1});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
int x, y, x1, y1;
|
||||
cin >> x >> y >> x1 >> y1;
|
||||
|
||||
int steps_A = bfs(x, y);
|
||||
int steps_B = bfs(x1, y1);
|
||||
|
||||
cout << steps_A << endl;
|
||||
cout << steps_B << endl;
|
||||
|
||||
return 0;
|
||||
}
|
55
FZOI/最短路径问题.cpp
Normal file
55
FZOI/最短路径问题.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define lo long long
|
||||
#define INF INT_MAX
|
||||
#define LLM LONG_LONG_MAX
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e7 + 10;
|
||||
/*
|
||||
toothless. #17
|
||||
@fredcss_dev
|
||||
*/
|
||||
|
||||
int n, m, s, t;
|
||||
double ma[101][101], dp[101][101];
|
||||
|
||||
struct Node {
|
||||
int x, y;
|
||||
} a[101];
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
cout.tie(0);
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i].x >> a[i].y;
|
||||
}
|
||||
cin >> m;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
int c, d;
|
||||
cin >> c >> d;
|
||||
double k = sqrt(double(pow((a[c].x - a[d].x), 2)) + double(pow((a[c].y - a[d].y), 2)));
|
||||
ma[c][d] = k;
|
||||
ma[d][c] = k;
|
||||
}
|
||||
cin >> s >> t;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (ma[i][j]) {
|
||||
dp[i][j] = ma[i][j];
|
||||
} else {
|
||||
dp[i][j] = INT_MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int k = 1; k <= n; k++) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%.2lf", dp[s][t]);
|
||||
}
|
52
FZOI/求逆序对.cpp
Normal file
52
FZOI/求逆序对.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <bits/stdc++.h>
|
||||
#define int long long
|
||||
using namespace std;
|
||||
const int N = 5e5 + 10;
|
||||
int tree[N];
|
||||
|
||||
void updata(int idx, int k)
|
||||
{
|
||||
while(idx <= N)
|
||||
{
|
||||
tree[idx] += k;
|
||||
idx += (idx) & (-idx);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int query(int idx)
|
||||
{
|
||||
int res = 0;
|
||||
while(idx)
|
||||
{
|
||||
res += tree[idx];
|
||||
idx -= (idx) & (-idx);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
signed main()
|
||||
{
|
||||
int n;
|
||||
cin >> n ;
|
||||
vector<int> a(n + 1);
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
cin >> a[i];
|
||||
}
|
||||
vector<int> b = a;
|
||||
sort(b.begin() + 1, b.end());
|
||||
map<int, int> cnt;
|
||||
int t = 1;
|
||||
for(int i = 1; i <= n; ++ i)
|
||||
{
|
||||
if(!cnt.count(b[i])) cnt[b[i]] = t, t ++ ;
|
||||
}
|
||||
for(int i = 1; i <= n; ++ i) a[i] = cnt[a[i]];
|
||||
int ans = 0;
|
||||
for(int i = n; i >= 1; -- i)
|
||||
{
|
||||
updata(a[i], 1);
|
||||
ans += query(a[i] - 1);
|
||||
}
|
||||
cout <<ans << endl ;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user