From 394e431a4a428df7d0422017f579596558327e8f Mon Sep 17 00:00:00 2001 From: BunDragon Date: Sat, 28 Dec 2024 14:11:21 +0800 Subject: [PATCH] upload some new code --- .DS_Store | Bin 10244 -> 10244 bytes FZOI/#1074. 「NOIP2005」过河.cpp | 53 +++++++ FZOI/#1203. 「ZJOI2008」树的统计.cpp | 62 ++++++++ FZOI/Fibonacci 前n项和.cpp | 78 ++++++++++ FZOI/Tad的小蛋糕.cpp | 61 ++++++++ FZOI/[CSP-S 2024] 决斗.cpp | 35 +++++ FZOI/「COCI2006:2007」slikar.cpp | 133 ++++++++++++++++++ FZOI/「CSP-J2020」优秀的拆分 copy.cpp | 55 ++++++++ FZOI/「USACO2007JAN」Balanced Lineup.cpp | 57 ++++++++ FZOI/「模板」PYB的高斯消元.cpp | 50 +++++++ FZOI/分组(groping).cpp | 75 ++++++++++ FZOI/区间最大值.cpp | 51 +++++++ FZOI/去重.cpp | 32 +++++ FZOI/找拖后腿的.cpp | 38 +++++ FZOI/插入.cpp | 32 +++++ FZOI/数的计数 + 输出.cpp | 111 +++++++++++++++ FZOI/纪念品分组.cpp | 35 +++++ FZOI/菲波拉契数列.cpp | 77 ++++++++++ FZOI/计算器的改良.cpp | 57 ++++++++ FZOI/银行卡.cpp | 61 ++++++++ ...19 [USACO1.5] 八皇后 Checker Challenge.cpp | 60 ++++++++ Luogu/【模板】排序.cpp | 23 +++ 22 files changed, 1236 insertions(+) create mode 100644 FZOI/#1074. 「NOIP2005」过河.cpp create mode 100644 FZOI/#1203. 「ZJOI2008」树的统计.cpp create mode 100644 FZOI/Fibonacci 前n项和.cpp create mode 100644 FZOI/Tad的小蛋糕.cpp create mode 100644 FZOI/[CSP-S 2024] 决斗.cpp create mode 100644 FZOI/「COCI2006:2007」slikar.cpp create mode 100644 FZOI/「CSP-J2020」优秀的拆分 copy.cpp create mode 100644 FZOI/「USACO2007JAN」Balanced Lineup.cpp create mode 100644 FZOI/「模板」PYB的高斯消元.cpp create mode 100644 FZOI/分组(groping).cpp create mode 100644 FZOI/区间最大值.cpp create mode 100644 FZOI/去重.cpp create mode 100644 FZOI/找拖后腿的.cpp create mode 100644 FZOI/插入.cpp create mode 100644 FZOI/数的计数 + 输出.cpp create mode 100644 FZOI/纪念品分组.cpp create mode 100644 FZOI/菲波拉契数列.cpp create mode 100644 FZOI/计算器的改良.cpp create mode 100644 FZOI/银行卡.cpp create mode 100644 Luogu/P1219 [USACO1.5] 八皇后 Checker Challenge.cpp create mode 100644 Luogu/【模板】排序.cpp diff --git a/.DS_Store b/.DS_Store index 31194284ed9a8ee0517a81a79cc5ba7fc39fdbfb..4fcf7761424a83333ad0d1ad3f34c34ffe6652b2 100644 GIT binary patch delta 175 zcmZn(XbIS$DiFtF6Ue~8z`~%%kj{|FP?DSP;*yk;p9B=+us?VxB`W-wBdUA~UipFy z!{Frn+ybB;1_quBo0|nxnC%XMO>kp~V(@41M7BY7OI$SE2Dm)J2C)3*r^50g00$o{ A=Kufz delta 175 zcmZn(XbIS$DiFuKOM`)dfrUYjA)O(Up(Hoo#U&{xKM5$t@!icOG9vt#BdUA~UipFy z!{Frn+ybB;1_myL&CLQT%y!GbCb%&~G59lhBHOSoy|zCRW&>OvVFOrx^HX7Y5dhX) BEA0RP diff --git a/FZOI/#1074. 「NOIP2005」过河.cpp b/FZOI/#1074. 「NOIP2005」过河.cpp new file mode 100644 index 0000000..128d706 --- /dev/null +++ b/FZOI/#1074. 「NOIP2005」过河.cpp @@ -0,0 +1,53 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/#1203. 「ZJOI2008」树的统计.cpp b/FZOI/#1203. 「ZJOI2008」树的统计.cpp new file mode 100644 index 0000000..b67ed1b --- /dev/null +++ b/FZOI/#1203. 「ZJOI2008」树的统计.cpp @@ -0,0 +1,62 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/Fibonacci 前n项和.cpp b/FZOI/Fibonacci 前n项和.cpp new file mode 100644 index 0000000..eab6f84 --- /dev/null +++ b/FZOI/Fibonacci 前n项和.cpp @@ -0,0 +1,78 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/Tad的小蛋糕.cpp b/FZOI/Tad的小蛋糕.cpp new file mode 100644 index 0000000..fa9e894 --- /dev/null +++ b/FZOI/Tad的小蛋糕.cpp @@ -0,0 +1,61 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/[CSP-S 2024] 决斗.cpp b/FZOI/[CSP-S 2024] 决斗.cpp new file mode 100644 index 0000000..337b82d --- /dev/null +++ b/FZOI/[CSP-S 2024] 决斗.cpp @@ -0,0 +1,35 @@ +#include +#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; +} diff --git a/FZOI/「COCI2006:2007」slikar.cpp b/FZOI/「COCI2006:2007」slikar.cpp new file mode 100644 index 0000000..8ada3a6 --- /dev/null +++ b/FZOI/「COCI2006:2007」slikar.cpp @@ -0,0 +1,133 @@ +#include +#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 Water; +node startt, endd; +queue 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(); +} \ No newline at end of file diff --git a/FZOI/「CSP-J2020」优秀的拆分 copy.cpp b/FZOI/「CSP-J2020」优秀的拆分 copy.cpp new file mode 100644 index 0000000..9541cb9 --- /dev/null +++ b/FZOI/「CSP-J2020」优秀的拆分 copy.cpp @@ -0,0 +1,55 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/「USACO2007JAN」Balanced Lineup.cpp b/FZOI/「USACO2007JAN」Balanced Lineup.cpp new file mode 100644 index 0000000..1f577a2 --- /dev/null +++ b/FZOI/「USACO2007JAN」Balanced Lineup.cpp @@ -0,0 +1,57 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/「模板」PYB的高斯消元.cpp b/FZOI/「模板」PYB的高斯消元.cpp new file mode 100644 index 0000000..a88ef0a --- /dev/null +++ b/FZOI/「模板」PYB的高斯消元.cpp @@ -0,0 +1,50 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/分组(groping).cpp b/FZOI/分组(groping).cpp new file mode 100644 index 0000000..136f783 --- /dev/null +++ b/FZOI/分组(groping).cpp @@ -0,0 +1,75 @@ +#include +#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& 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 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; +} \ No newline at end of file diff --git a/FZOI/区间最大值.cpp b/FZOI/区间最大值.cpp new file mode 100644 index 0000000..eec21f7 --- /dev/null +++ b/FZOI/区间最大值.cpp @@ -0,0 +1,51 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/去重.cpp b/FZOI/去重.cpp new file mode 100644 index 0000000..b697468 --- /dev/null +++ b/FZOI/去重.cpp @@ -0,0 +1,32 @@ +#include +#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 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; +} \ No newline at end of file diff --git a/FZOI/找拖后腿的.cpp b/FZOI/找拖后腿的.cpp new file mode 100644 index 0000000..bd799b5 --- /dev/null +++ b/FZOI/找拖后腿的.cpp @@ -0,0 +1,38 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/插入.cpp b/FZOI/插入.cpp new file mode 100644 index 0000000..7e4542b --- /dev/null +++ b/FZOI/插入.cpp @@ -0,0 +1,32 @@ +#include +#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; +} \ No newline at end of file diff --git a/FZOI/数的计数 + 输出.cpp b/FZOI/数的计数 + 输出.cpp new file mode 100644 index 0000000..d486d2a --- /dev/null +++ b/FZOI/数的计数 + 输出.cpp @@ -0,0 +1,111 @@ +#include +#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 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; +} \ No newline at end of file diff --git a/FZOI/纪念品分组.cpp b/FZOI/纪念品分组.cpp new file mode 100644 index 0000000..f9a7c09 --- /dev/null +++ b/FZOI/纪念品分组.cpp @@ -0,0 +1,35 @@ +#include +#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 w, ans = 0; +int n, a[N]; +int l, r; + +signed main() +{ + cin >> w >> n; + for (int i = 1; i <= n; i++) cin >> a[i]; + sort(a + 1, a + 1 + n); + l = 1; + r = n; + while (l <= r) { + if (a[l] + a[r] <= w) { + l++, r--, ans++; + } else { + r--, ans++; + } + } + cout << ans; + return 0; +} \ No newline at end of file diff --git a/FZOI/菲波拉契数列.cpp b/FZOI/菲波拉契数列.cpp new file mode 100644 index 0000000..1126e6f --- /dev/null +++ b/FZOI/菲波拉契数列.cpp @@ -0,0 +1,77 @@ +#include +#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[3][3]; +}; + +node z; + +node matrix_nul(node x, node y) +{ + memset(z.mat, 0, sizeof(z.mat)); + for(int i = 1; i <= 2; i ++ ) + { + for(int j = 1; j <= 2; j ++ ) + { + for(int k = 1; k <= 2; k ++ ) + { + z.mat[i][j] += (x.mat[i][k]) * (y.mat[k][j]); + z.mat[i][j]; + } + } + } + return z; +} + +node matrix_pow(int k) +{ + node t, a; + t.mat[1][1] = 1; + t.mat[1][2] = 0; + t.mat[2][1] = 0; + t.mat[2][2] = 1; + a.mat[1][1] = 1; + a.mat[1][2] = 1; + a.mat[2][1] = 1; + a.mat[2][2] = 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 ; + for(int i = 1; i <= n; i ++ ) + { + node temp; + temp = matrix_pow(i - 1); + int ans = temp.mat[1][1] * 1 + temp.mat[2][1] * 0; + ans; + cout << ans << " " ; + } + return 0; +} \ No newline at end of file diff --git a/FZOI/计算器的改良.cpp b/FZOI/计算器的改良.cpp new file mode 100644 index 0000000..9cf9ca7 --- /dev/null +++ b/FZOI/计算器的改良.cpp @@ -0,0 +1,57 @@ +#include +#include +using namespace std; +char c, a; +int f = 1, now = 1, k, b, x; +bool r; +int main() +{ + while (cin >> c) + { + if (c == '-') + { + b += now * f * x; + x = 0; + f = -1; + r = 0; + } + if (c == '+') + { + b += now * f * x; + x = 0; + f = 1; + r = 0; + } + if (c == '=') + { + b += now * f * x; + x = 0; + f = 1; + now = -1; + r = 0; + } + if (c >= 'a' && c <= 'z') + { + if (r) + { + k += now * f * x; + x = 0; + } + else + k += now * f; + a = c; + r = 0; + } + if (c >= '0' && c <= '9') + { + x = x * 10 + c - '0'; + r = 1; + } + } + b += now * f * x; + double ans = double(-b * 1.0 / k); + if (ans == -0.0) + ans = 0; + printf("%c=%.3lf", a, ans); + return 0; +} \ No newline at end of file diff --git a/FZOI/银行卡.cpp b/FZOI/银行卡.cpp new file mode 100644 index 0000000..f04ad9e --- /dev/null +++ b/FZOI/银行卡.cpp @@ -0,0 +1,61 @@ +#include +#define int long long +#define endl "\n" +#define IMX LONG_LONG_MAX +#define IMN LONG_LONG_MIN +using namespace std; + +/* toothless. #17 */ + +int n, pre, len; +string s; + +int f(int n) +{ + int sum = 0; + while (n) + { + sum += n % 10; + n /= 10; + } + return sum; +} + +int Get_ans(string s) +{ + int cnt = 0, sum = 0; + for (int i = len - 2; i >= 0; i--) + { + ++cnt; + if (cnt & 1) + sum += f((s[i] - '0') * 2); + else + sum += s[i] - '0'; + } + return sum * 9 % 10; +} + +signed main() +{ + cin >> n >> s; + len = s.size(); + for (int i = 0; i < len; i++) + { + if (s[i] == 'x') + { + pre = i; + break; + } + } + for (char i = '0'; i <= '9'; i++) + { + s[pre] = i; + int ans = Get_ans(s); + if (ans == s[len - 1] - '0') + { + cout << i; + return 0; + } + } + return 0; +} \ No newline at end of file diff --git a/Luogu/P1219 [USACO1.5] 八皇后 Checker Challenge.cpp b/Luogu/P1219 [USACO1.5] 八皇后 Checker Challenge.cpp new file mode 100644 index 0000000..769d3b2 --- /dev/null +++ b/Luogu/P1219 [USACO1.5] 八皇后 Checker Challenge.cpp @@ -0,0 +1,60 @@ +#include +#define int long long +#define endl "\n" +#define IMX LONG_LONG_MAX +#define IMN LONG_LONG_MIN +#define debug$ if(dev) +using namespace std; + +const int N = 1e7 + 10; +const int M = 2e3 + 5; +const bool dev = false; + +/* toothless. #17 */ + +int a[N], b[N], c[N], d[N]; +int total; +int n; + +void print() +{ + if (total <= 2) + { + for (int k = 1; k <= n; k++) + cout << a[k] << " "; + cout << endl; + } + total++; +} +void queen(int i) +{ + if (i > n) + { + print(); + return; + } + else + { + for (int j = 1; j <= n; j++) + { + if ((!b[j]) && (!c[i + j]) && (!d[i - j + n])) + { + a[i] = j; + b[j] = 1; + c[i + j] = 1; + d[i - j + n] = 1; + queen(i + 1); + b[j] = 0; + c[i + j] = 0; + d[i - j + n] = 0; + } + } + } +} +signed main() +{ + cin >> n; + queen(1); + cout << total; + return 0; +} \ No newline at end of file diff --git a/Luogu/【模板】排序.cpp b/Luogu/【模板】排序.cpp new file mode 100644 index 0000000..d7ba702 --- /dev/null +++ b/Luogu/【模板】排序.cpp @@ -0,0 +1,23 @@ +#include +#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 a[N]; + +signed main() +{ + int n; + cin >> n ; + for(int i = 1; i <= n; i ++ ) cin >> a[i] ; + sort(a + 1, a + 1 + n); + for(int i = 1; i <= n; i ++ ) cout << a[i] << " " ; + return 0; +} \ No newline at end of file