Merge pull request #7 from ToothlessHaveBun/writing

Upload new codes.
This commit is contained in:
Frederick Chen 2025-03-01 00:08:19 +08:00 committed by GitHub
commit 85845ef8b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 749 additions and 1 deletions

1
.gitignore vendored
View File

@ -54,3 +54,4 @@ dkms.conf
# config # config
fame.cpp fame.cpp
.cph/ .cph/
.vscode/

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View File

@ -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;
}

View 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;
}

View File

@ -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;
}

View File

@ -0,0 +1,23 @@
#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
*/
signed main() {
lo V_egg, V_milk, V_tart;
lo e, m, t;
cin >> V_egg >> V_milk >> V_tart;
cin >> e >> m >> t;
lo total_volume = V_egg * e + V_milk * m;
lo num_tarts = (total_volume + V_tart - 1) / V_tart;
lo batches = (num_tarts + t - 1) / t;
cout << batches << endl;
return 0;
}

View File

@ -0,0 +1,27 @@
#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
*/
signed main() {
lo n, x, y;
cin >> n >> x >> y;
lo cw = (y - x + n) % n;
lo cnt = n - cw;
if (cw < cnt) {
cout << "Clockwise Loop" << endl;
} else if (cw > cnt) {
cout << "Counter-clockwise Loop" << endl;
} else {
cout << "\"Wonderful\"" << endl;
}
return 0;
}

View File

@ -0,0 +1,28 @@
#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
*/
signed main() {
lo n, L, R;
cin >> n >> L >> R;
lo S = L;
lo k = S / n;
lo r = S % n;
vector<lo> ans(n, k);
for (lo i = 0; i < r; ++i) {
ans[i] += 1;
}
for (lo i = 0; i < n; ++i) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}

View File

@ -0,0 +1,37 @@
#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 X, Y, K;
cin >> X >> Y >> K;
int mx = -1;
int count = 0;
for (int b = 0; b <= X; ++b) {
for (int p = 1; p <= Y; ++p) {
for (int z = 0; z <= K; ++z) {
int d = (b + p) ^ z;
if (d > mx) {
mx = d;
count = 1;
} else if (d == mx) {
++count;
}
}
}
}
cout << mx << endl;
cout << count << endl;
return 0;
}

View File

@ -0,0 +1,58 @@
#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 f(int n, int k, vector<int>& a) {
// 初始胜场数计算
int red = 0, pink = 0;
for (int ai : a) {
if (ai > 49) {
red++;
} else {
pink++;
}
}
int cnt = 0;
for (int l = 0; l <= n - k; l++) {
int chr = 0, cpi = 0;
for (int i = l; i < l + k; i++) {
bool ysfred = (a[i] > 49);
int tzhred = a[i] - 2;
int tzhpink = 101 - a[i];
bool tzhredWin = (tzhred > tzhpink);
if (ysfred && !tzhredWin) {
chr--;
cpi++;
} else if (!ysfred && tzhredWin) {
chr++;
cpi--;
}
}
int nre = red + chr;
int npi = pink + cpi;
if (npi > nre) {
cnt++;
}
}
return cnt;
}
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int result = f(n, k, a);
cout << result << endl;
return 0;
}

View File

@ -0,0 +1,58 @@
#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;
char s[M];
int a[M], top;
bool check()
{
int t = top / 2;
for (int i = 0; i <= t; ++i)
if (a[i] != a[top - i])
return true;
return false;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, step = 0;
cin >> n >> s;
top = strlen(s) - 1;
for (int i = 0; i <= top; ++i)
if (s[i] >= '0' && s[i] <= '9')
a[top - i] = s[i] - '0';
else
a[top - i] = s[i] - 55;
while (check()) {
if (step > 30) {
cout << "Impossible!";
return 0;
}
for (int i = 0; i <= top; ++i)
if (top - i >= i)
a[i] += a[top - i];
else
a[i] = a[top - i];
for (int i = 0; i <= top; ++i)
if (a[i] >= n)
a[i + 1]++, a[i] -= n;
if (a[top + 1])
top++;
step++;
}
cout << "STEP=" << step;
return 0;
}

View File

@ -0,0 +1,34 @@
#include <bits/stdc++.h>
#define lo long long
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
const int N = 1e7 + 10;
/*
toothless. #17
@fredcss_dev
*/
lo qpow(lo a, lo b, lo p) {
lo result = 0;
while (b) {
if (b & 1) {
result += a;
result %= p;
}
b >>= 1;
a += a;
a %= p;
}
return result;
}
lo a, b, p;
signed main()
{
cin >> a >> b >> p;
cout << qpow(a, b, p);
return 0;
}

View File

@ -0,0 +1,27 @@
#include <bits/stdc++.h>
#define lo long long
#define IMX LONG_LONG_MAX
#define IMN LONG_LONG_MIN
using namespace std;
const int N = 1e7 + 10;
/*
toothless. #17
@fredcss_dev
<2025/1/21>
*/
int m, n, d[N], w, v;
signed main()
{
cin >> m >> n;
for(int i = 1; i <= n; i++) {
cin >> v >> w;
for(int j = m; j >= v; j--){
d[j] = max(d[j], d[j - v] + w * v);
}
}
printf("%d",d[m]);
return 0;
}

View File

@ -0,0 +1,49 @@
#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, k;
int a[N];
int ans=0;
bool isPrime(int x)
{
if (x == 1)
return false;
for (int i = 2; i * i <= x; i++)
if (x % i == 0)
return false;
return true;
}
void dfs(int x, int sum, int cnt)
{
if (x == k) {
if (isPrime(sum))
ans++;
return;
}
for (int i = cnt; i < n; i++) {
dfs(x + 1, sum + a[i], i + 1);
}
}
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dfs(0, 0, 0);
cout << ans << endl;
return 0;
}`

View File

@ -10,6 +10,7 @@ Here's my personal solutions to algorithm problems.
| Name | Link | Account | Name | Link | Account
| :---: | :---: | :---: | | :---: | :---: | :---: |
| AtCoder | atcoder.jp | [wczffL_4ever](https://atcoder.jp/users/wczffL_4ever) |
| Codeforces | codeforces.com | [Fengyi_Chen](https://codeforces.com/profile/Fengyi_Chen) | | Codeforces | codeforces.com | [Fengyi_Chen](https://codeforces.com/profile/Fengyi_Chen) |
| FZOI | 内部 OJ | 内部 OJ | | FZOI | 内部 OJ | 内部 OJ |
| Luogu | luogu.com.cn | [BunDragon126](https://www.luogu.com.cn/user/927203) | | Luogu | luogu.com.cn | [BunDragon126](https://www.luogu.com.cn/user/927203) |