ICPC 常用算法模板
基本算法尺取法/双指针$O(n)$ 12345678910111213// 尺取法获取第k近的点下标void getKth(int k) { int l = 1, r = k + 1; nxt[1] = k + 1; for (int i = 2; i <= n; i++) { while (r + 1 <= n && a[i] - a[l] > a[r + 1] - a[i]) l++, r++; if (a[i] - a[l] < a[r] - a[i]) nxt[i] = r; else nxt[i] = l; }} 123456789101112void add(int x) { if (++mp[a[x]] == 1) cnt++; }void del(int x) { if (--mp[a[x]] == 0) cn...
2024天梯赛选拔赛(一)
L1-1 2018我们要赢12print("""2018wo3 men2 yao4 ying2 !""") L1-2 心理阴影面积1234567#include <bits/stdc++.h>using namespace std;int main() { int x, y; cin >> x >> y; cout << (100 * 100 / 2 - x * y / 2 - (100 - x) * y - (100 - x) * (100 - y) / 2) << '\n';} L1-3 判断素数12345678910111213141516171819#include <bits/stdc++.h>using namespace std;bool isPrime(long long x) { for (long long i = 2; i * i <= x; i...
算法集训#1:C++STL基础
头文件引入12345#include <bits/stdc++.h> // 万能头文件using namespace std; // 使用标准命名空间// 竞赛玩法,完全避免溢出的错误// #define int long long// signed main() {} cin, cout基本类型变量输入输出 支持以下类型 int, long long, float, double, char, char[], string 12345678910111213141516171819 int a; double b; string ss; char s[100];// 输入 cin >> a; cin >> b; cin >> ss; cin >> s;// 输出 cout << a << '\n'; cout << b << '\n'; cout << s...
2023年冬季周赛(四)
1 点燃我,温暖你123456789101112131415161718#include<stdio.h>int main(){ printf(" ********* *********\n"); printf("************* *************\n"); printf("*****************************\n"); printf("*****************************\n"); printf("*****************************\n"); printf(" ***************************\n"); printf(" ***********************\n"); printf(" *******************...
2023年冬季周赛(三)
1 找最大值1234567891011#include <stdio.h>int main() { int mx = 0; for (int i = 0; i < 4; i++) { int x; scanf("%d", &x); mx = mx > x ? mx : x; } printf("%d\n", mx);} 2 二三得六12345678910111213141516171819202122232425#include <stdio.h>int main() { int n, m; scanf("%d %d", &n, &m); int d = m / n; if (m % n != 0) { printf("-1\n"); return 0; ...
2023年冬季周赛(二)
2 a+b?1234567891011121314151617181920212223242526272829#include <stdio.h>#include <string.h>int a[1000005], b[1000005], ans[1000005];char s[1000005], t[1000005];int max(int a, int b) { return a > b ? a : b; }int main() { scanf("%s", s); scanf("%s", t); int len1 = strlen(s), len2 = strlen(t); for (int i = len1 - 1, j = 0; i >= 0; i--, j++) { a[j] = s[i] - '0'; } for (int i = len2 - 1, j = 0; i >...
2023年冬季周赛(一)
12345678#include <stdio.h>int main() { printf("\\ /\n"); printf(" \\/\n"); printf(" /\\\n"); printf("/ \\\n"); return 0;} 2 学号1234567#include<stdio.h>int main () { char s[20]; scanf("%s", s); printf("20%c%c", s[0], s[1]); return 0;} 3 平均数12345678910111213141516#include <bits/stdc++.h>using namespace std;int main() { double a, b, c, d, n, z; cin >> a...
软件开发协会的挑战书
在RSA密码体系中, 欧几里得算法是加密或解密运算的重要组成部分。它的基本运算过程就是解 $ax\equiv 1\pmod n$ 这种方程。整个解的过程是这样的,我们用一个例子来说明。 当 a = 1001 ,n = 3837 时,方程为 x * 1001 ≡ 1 (mod 3837)我们有3837 = 3 * 1001 + 8341001 = 1 * 834 + 167 834 = 4 * 167 + 166 167 = 1 * 166 + 1 所以 1 = 167 + (–1) * 166 = 167 - (834 - 4 * 167) = -1 * 834 + 5 * 167 = 5 *(1001 - 834) – 834 = 5 * 1001 + (-6) * 834 = 5 * 1001 - 6 * (3837 -3 * 1001) = -6 * 3837 + 23 * 1001 然后对等式两端同时模 3837 得 23 * 10...