3 | #include
4 | using namespace std;
5 | int main()
6 | {
7 | char n[100];
8 | cin>>n;
9 | char *p=strtok(n," ");
10 | while(p!=NULL)
11 | {
12 | cout<
17 | #include
18 | using namespace std;
19 | int main() {
20 | int N, i;
21 | double sum;
22 | while (cin >> N) {
23 | sum = 0;
24 | for (i = 2; i <= N; i++) sum += log10(i);
25 | cout << (int)sum + 1 << endl;
26 | }
27 | return 0;
28 | }
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec01/qsort_sort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | int cmp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
6 | int main() {
7 | int data[10];
8 | for (int i = 0; i < 5; i++) cin >> data[i];
9 | qsort(data, 5, sizeof(data[0]), cmp);
10 | for (int i = 0; i < 5; i++) cout << a[i] << endl;
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec01/stl_sort.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | int main() {
6 | int data[10];
7 | for (int i = 0; i < 5; i++) cin >> data[i];
8 | sort(data, data + 5);
9 | for (int i = 0; i < 5; i++) cout << a[i] << endl;
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec01/typeid.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | void judge(int n)
6 | {
7 | cout<<"int"<
2 | #include
3 | #include
4 | using namespace std;
5 | namespace s
6 | {
7 | int y;
8 | void judge()
9 | {
10 | if(y%4==0&&y%100!=0||y%400==0)
11 | cout<<"yes"<>y)
21 | {
22 | judge();
23 | }
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec02/Practice1.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by zj on 17-6-29.
3 | */
4 | public class Practice1 {
5 | public static void main(String[] args) {
6 | int x=1023;
7 | String s=Integer.toString(x);
8 | String s2=s.substring(1);//"023"
9 | int y=Integer.parseInt(s2);//23
10 | System.out.println(y);
11 | System.out.println(Integer.parseInt(Integer.toString(x).substring(1)));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec02/cyclist.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main() {
4 | cout << "Hello" << endl;
5 | return 0;
6 | }
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec02/readme.MD:
--------------------------------------------------------------------------------
1 | # 知识点
2 | ## 例题
3 | ## 习题
4 | ## AOJ对应练习题(增补及数据完善)
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec02pm/BigAddAB.java:
--------------------------------------------------------------------------------
1 | package lec02pm;
2 |
3 | import java.math.BigInteger;
4 | import java.util.Scanner;
5 |
6 | /**
7 | * Created by zj on 17-6-29.
8 | */
9 | public class BigAddAB {
10 | public static void main(String[] args) {
11 | Scanner cin=new Scanner(System.in);
12 | BigInteger a=new BigInteger(cin.next());
13 | BigInteger b=cin.nextBigInteger();
14 | System.out.println(a.multiply(b));
15 | cin.close();
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec02pm/P1039.java:
--------------------------------------------------------------------------------
1 | package lec02pm;
2 |
3 | import java.math.BigInteger;
4 |
5 | /**
6 | * Created by zj on 17-6-29.
7 | */
8 | public class P1039 {
9 | public static void main(String[] args) {
10 | BigInteger prod=new BigInteger("1");
11 | for (int i = 2; i <=1997 ; i++) {
12 | prod=prod.multiply(new BigInteger(Integer.toString(i)));
13 | }
14 | System.out.println(prod);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec03am/NullPointerDemo.java:
--------------------------------------------------------------------------------
1 | package lec03am;
2 |
3 | /**
4 | * Created by zj on 17-6-30.
5 | */
6 | public class NullPointerDemo {
7 | public static void main(String[] args) {
8 | String a[] = new String[10];
9 | for (int i = 0; i < a.length; i++) {
10 | System.out.print(a[i]);
11 | }
12 | System.out.println(a[0].length());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec03am/SortDemo2.java:
--------------------------------------------------------------------------------
1 | package lec03am;
2 |
3 | import java.util.Arrays;
4 | import java.util.Collections;
5 |
6 | /**
7 | * Created by zj on 17-6-30.
8 | */
9 | public class SortDemo2 {
10 | public static void main(String[] args) {
11 | Integer a[] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0};
12 | Arrays.sort(a);
13 | System.out.println(Arrays.toString(a));
14 | Arrays.sort(a, Collections.reverseOrder());
15 | System.out.println(Arrays.toString(a));
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec03am/aoj1042_factorial.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | Description
3 | 计算一个整数N的阶乘
4 | Input
5 | 一个整数N, (0〈=N〈=12)
6 | Output
7 | 整数N的阶乘.
8 | Sample Input
9 | 5
10 | Sample Output
11 | 120
12 | */
13 |
14 | #include
15 | #include
16 | #include
17 | using namespace std;
18 | int fact(int n) { return n == 0 ? 1 : fact(n - 1) * n; }
19 | int main() {
20 | int n;
21 | while (cin >> n) cout << fact(n) << endl;
22 | return 0;
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec03am/readme.MD:
--------------------------------------------------------------------------------
1 | # 知识点
2 | ## 例题
3 | ## 习题
4 | ## AOJ对应练习题(增补及数据完善)
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec05/readme.MD:
--------------------------------------------------------------------------------
1 | # 知识点
2 | ## 例题
3 | ## 习题
4 | ## AOJ对应练习题(增补及数据完善)
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec06/outline.MD:
--------------------------------------------------------------------------------
1 | ## 搜索入门
2 |
3 | ### 深度优先搜索(DFS) Depth-First-Serach
4 | - DFS的本质来讲是递归,递归就是自己调用自己
5 | ```
6 | void dfs(){
7 | dfs();
8 | }
9 | ```
10 | - 一个函数dfs()的内部又调用了自己,这就叫递归.
11 | 我们很容易发现上面那个dfs()是个无限循环,很简单,因为没有终至条件,自然会一直dfs()下去,所以递归一般来讲还要有终止条件.
12 |
13 | ```
14 | void dfs(int step) {
15 | if (step == 5) return;
16 | dfs(step + 1);
17 | }
18 | ```
19 |
20 | - 我们稍微修改一下,这样就能停止了.
21 |
22 | 显然DFS是一种一条路走到黑的方法,例如有N个阶段,我在第N个阶段走不通就返回第N-1个阶段尝试其他的可能,N-1不行我再返回到第N-2个阶段…..
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec06/readme.MD:
--------------------------------------------------------------------------------
1 | # 知识点
2 | ## 例题
3 | ## 习题
4 | ## AOJ对应练习题(增补及数据完善)
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec09/readme.MD:
--------------------------------------------------------------------------------
1 | # 知识点
2 | ## 例题
3 | ## 习题
4 | ## AOJ对应练习题(增补及数据完善)
--------------------------------------------------------------------------------
/ACM/2017ACM集训/lec15/phi.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/2017ACM集训/lec15/phi.cpp
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(CMAKE_CXX_STANDARD 11)
2 | add_executable(cp4 lec01/D1.cpp)
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/README.md:
--------------------------------------------------------------------------------
1 | # 2019ACMStep
2 | 2019ACM中级算法 网络课
3 |
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec/outline.md:
--------------------------------------------------------------------------------
1 | # 树状数组
2 | ## 单点修改,区间查询
3 | # *线段树*
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec01/A1.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | typedef long long LL;
5 |
6 | int main() {
7 | ifstream cin("A.in");//代码洁癖
8 | LL a, b, c;
9 | char op, eq;
10 | int tot = 0;
11 | while (cin >> a >> op >> b >> eq >> c) {//ok
12 | if (op == '+') {
13 | if (a + b == c)++tot;
14 | } else if (op == '-') {
15 | if (a - b == c)++tot;
16 | }
17 | }
18 | cout << "RIGHT:" << tot << endl;
19 |
20 | return 0;
21 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec01/B.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | // bitset<32> b(65535<<8>>16);
7 | // cout<> n;
10 | if (n < 256)n += 256;//(1)
11 | // n=(n<<16)>>16;//舍去高16位 rand() [0,RAND_MAX)
12 | n = (n & ((1 << 16) - 1));
13 | n = n * n;
14 | n = (n << 8) >> 16;
15 | cout << n << endl;
16 |
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec01/C.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int n = 6;//cin>>n;
7 | int m = n * 2;
8 | int k = sqrt(m);
9 | if (k * (k + 1) == m)cout << "YES" << endl;
10 | else cout << "NO" << endl;
11 |
12 | return 0;
13 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec02/A_square.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {//O(n^2)
6 | int n = 100005;
7 | cin >> n;
8 | for (int i = 1; i <= n / 2; i++)
9 | for (int j = i + 1; j <= n - i; j++) {
10 | int s = (i + j) * (j - i + 1) / 2;
11 | if (s == n) {
12 | cout << i << " " << j << endl;
13 | }
14 | }
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/app2.cpp:
--------------------------------------------------------------------------------
1 | //排序去重的set版本
2 | #include
3 |
4 | using namespace std;
5 |
6 |
7 | int main() {
8 | int a[] = {1, 1, 6, 3, 3,};
9 | set S;//排序树(红黑树)实现的集合
10 | for (int i = 0; i < 5; i++)S.insert(a[i]);//如果a[i]不在这个集合中O(logN),就把a[i]元素放入这个树种依然保持树的有序性O(logN)
11 | cout << S.size() << endl;
12 | for (auto e:S)//for each
13 | cout << e << " ";
14 | cout << endl;
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/array_bad.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | const int MAXN = 1000;
5 | int a[MAXN];
6 |
7 | int main() {
8 |
9 | int *p = (int *) malloc(sizeof(int) * 100000);
10 | if (p != NULL) {
11 | //开辟成功
12 | } else {
13 | //申请失败
14 | }
15 | free(p);
16 | int *q = new int[1000];
17 | //
18 | free(q);//释放内存
19 |
20 | return 0;
21 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/map.cpp:
--------------------------------------------------------------------------------
1 | //map基本应用 map 里面每一个节点都是pair,整体数据结构是一个排序树
2 | #include
3 |
4 | using namespace std;
5 |
6 |
7 | int main() {
8 | ifstream cin("input.txt");
9 | map M;
10 | for (string s; cin >> s;) {
11 | M[s]++;
12 | }
13 | for (auto e:M) {
14 | cout << e.first << ":" << e.second << endl;
15 | }
16 | return 0;
17 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/queue.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | //int data[1000],head,tail;
5 |
6 | int main() {
7 | queue Q;//FIFO
8 | for (int i = 0; i < 10; i++)Q.push(i);//0~9依次入队
9 | while (not Q.empty()) {
10 | cout << Q.front() << endl;//队头元素
11 | Q.pop();//
12 | }
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/stack.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int Stack[1000], top = -1;
5 |
6 | //括号配对 进制转化 递归化简 后缀式计算
7 | int main() {
8 | stack S;//FILO
9 | for (int i = 0; i < 10; i++)S.push(i);
10 | while (not S.empty()) {
11 | cout << S.top() << endl;
12 | S.pop();
13 | }
14 | return 0;
15 | }
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/str2int.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int n = 123456, m; //m=612345;
7 | char buffer[100];
8 | //printf("%d%d", n % 10, n / 10);
9 | sprintf(buffer, "%d%d", n % 10, n / 10);//int2str
10 | //scanf("%d", &m);
11 | sscanf(buffer, "%d", &m);//str2int atoi/itoa 不是ASCI C的标准API
12 | printf("%d\n", m);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/str2int2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int n = 1234, m;
7 | ostringstream oss;
8 | oss << n % 10 << n / 10;//cout
9 | // cout << oss.str() << endl;//string
10 | istringstream iss(oss.str());
11 | iss >> m;//cin
12 | cout << m << endl;
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/lec03/strstr2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | string s("to know everything is to know nothing");
7 | string t = "to";
8 | auto pos = s.find(t);
9 | if (pos == string::npos) {//npos string中内置的一个静态常数,表示不可能的位置
10 | cout << "not found!" << endl;
11 | } else {
12 | cout << pos << endl;
13 | }
14 | pos = s.find(t, pos + t.size());
15 | cout << pos << endl;
16 | return 0;
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/ACM/2019ACM中级算法网络课(bilibli直播)/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main()
4 | {
5 |
6 | cout<<"Welcome everybody!"<
2 |
3 | using namespace std;
4 |
5 | void print(int *a, int *b) {
6 | copy(a, b, ostream_iterator(cout, " "));
7 | cout << endl;
8 | }
9 |
10 | int main() {
11 | int a[] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0};
12 | int n = sizeof(a) / sizeof(a[0]);
13 | for (int i = 0; i < n - 1; i++) {
14 | int j = min_element(a + i, a + n) - a;
15 | swap(a[i], a[j]);
16 | print(a, a + n);
17 | }
18 |
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec03math/NTL_1_A_PrimeFactorize.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main() {
4 | int n;
5 | cin >> n;
6 | cout << n << ":";
7 | for (int i = 2; n > 1; i++) {
8 | if (i * i > n) break;
9 | while (n % i == 0) {
10 | cout << " " << i;
11 | n /= i;
12 | }
13 | }
14 | if (n > 1) cout << " " << n;
15 | cout << endl;
16 | return 0;
17 | }
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec03math/NTL_1_B_Power.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | typedef long long LL;
4 | const int MOD = 1e9 + 7;
5 | LL mpower(LL a, int n) {
6 | long long ans = 1;
7 | while (n > 0) {
8 | if (n & 1) {
9 | ans *= a;
10 | ans %= MOD;
11 | }
12 | a *= a % MOD;
13 | a %= MOD;
14 | n >>= 1;
15 | }
16 | return ans % MOD;
17 | }
18 | int main() {
19 | int n, m;
20 | cin >> m >> n;
21 | cout << mpower(m, n) << endl;
22 |
23 | return 0;
24 | }
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec03math/NTL_1_C_LCM.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | typedef long long LL;
4 | LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
5 | LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
6 | int main() {
7 | int n;
8 | cin >> n;
9 | int ans = 1;
10 | while (n--) {
11 | int t;
12 | cin >> t;
13 | ans = lcm(ans, t);
14 | }
15 | cout << ans << endl;
16 |
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec03math/NTL_1_D_EulerFunction.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | typedef long long LL;
4 | int phi(int n) {
5 | int ret = n;
6 | for (int i = 2; i * i <= n; i++)
7 | if (n % i == 0) {
8 | ret = ret / i * (i - 1); //先进行除法防止溢出(ret=ret*(1-1/p(i)))
9 | while (n % i == 0) n /= i;
10 | }
11 | if (n > 1) ret = ret / n * (n - 1);
12 | return ret;
13 | }
14 | int main() {
15 | int n;
16 | cin >> n;
17 | cout << phi(n) << endl;
18 |
19 | return 0;
20 | }
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/1212a.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int main() //n!
5 | {
6 | int a[]= {0,1,2,3,4,5,6,7};
7 | do
8 | {
9 | bool ok=true;
10 | for(int i=0; i<8; i++)
11 | for(int j=i+1; j<8; j++)
12 | if(abs(a[i]-a[j])==j-i)
13 | ok=false;
14 | if(ok)
15 | cout<
2 | #define N 4
3 | int a[N];
4 | int used[N] = {0};
5 | void fill() {
6 | int i;
7 | for (i = 0; i < 4; i++) a[i] = i + 1;
8 | }
9 | void dfs(int k) {
10 | if (k == N) {
11 | int i;
12 | for (i = 0; i < k; i++)
13 | if (used[i]) printf("%d ", a[i]);
14 | printf("\n");
15 | return;
16 | }
17 | used[k] = 1;
18 | dfs(k + 1);
19 | used[k] = 0;
20 | dfs(k + 1);
21 | }
22 | int main() {
23 | fill();
24 | dfs(0);
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/dfs2.c:
--------------------------------------------------------------------------------
1 | #include
2 | #define N 4
3 | int a[N];
4 | int used[N] = {0};
5 |
6 | void dfs(int k) {
7 | if (k == N) {
8 | int i;
9 | for (i = 0; i < k; i++)
10 | if (used[i]) printf("%d ", a[i]);
11 | printf("\n");
12 | return;
13 | }
14 | int i;
15 | for (i = 0; i < N; i++)
16 | if (used[i] == 0) {
17 | used[i] = 1;
18 | a[i] = k;
19 | dfs(k + 1);
20 | used[i] = 0;
21 | }
22 | }
23 | int main() {
24 | dfs(0);
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/n的全排列.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/2019ACM集训/lec04dfsbfs/n的全排列.cpp
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/per1.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int main(){//n!
5 | int a, b, c, d;
6 | for (int a = 1; a <= 4; a++)
7 | for (int b = 1; b <= 4; b++)
8 | for (int c = 1; c <= 4; c++)
9 | for (int d = 1; d <= 4; d++) {
10 | if (a != b && a != c && a != d && b != c && b != d && c != d)
11 | printf("%d %d %d %d\n", a, b, c, d);
12 | }
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/per2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int main() //n!
5 | {
6 | int a[]= {0,1,2,3,4,5,6,7};
7 | do
8 | {
9 | bool ok=true;
10 | for(int i=0; i<8; i++)
11 | for(int j=i+1; j<8; j++)
12 | if(abs(a[i]-a[j])==j-i)
13 | ok=false;
14 | if(ok)
15 | cout<
3 | int main() {
4 | int a, b, c, d;
5 | for (int a = 1; a <= 4; a++)
6 | for (int b = 1; b <= 4; b++)
7 | for (int c = 1; c <= 4; c++)
8 | for (int d = 1; d <= 4; d++) {
9 | if (a != b && a != c && a != d && b != c && b != d && c != d)
10 | printf("%d %d %d %d\n", a, b, c, d)
11 | }
12 |
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/perm0.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int main(){
5 | int a, b, c, d;
6 | for (int a = 1; a <= 4; a++)
7 | for (int b = 1; b <= 4; b++)
8 | for (int c = 1; c <= 4; c++)
9 | for (int d = 1; d <= 4; d++) {
10 | if (a != b && a != c && a != d && b != c && b != d && c != d)
11 | printf("%d %d %d %d\n", a, b, c, d);
12 | }
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/prob.md:
--------------------------------------------------------------------------------
1 | ## 1. 选人。一个小组共五人,分别为A、B、C、D、E。现有一项任务,要他们中的3个人去完成。已知:(1)A、C不能都去;(2)B、C不能都不去;(3)如果C去了,D、E就只能去一个,且必须去一个;(4)B、C、D不能都去;(5)如果B去了,D、E就不能都去。编程找出此项任务该由哪三人去完成的所有组合。
2 | ## 2 1~9分成1:2:3的三个3位数
3 | 将1到9 这九个数字分成三个3位数,分求第一个3位数,正好是第二个3位数的二倍,是第三个3位数的三倍。问应当怎样分法。
4 | ## 3 1~9组成三个3位的平方数
5 | ## 将1、2、3、4、5、6、7、8、9九个数字分成三组,每个数字只能用一次,即每组三个数不允许有重复数字,也不许同其它组的三个数字重复,要求每组中的三位数都组成一个平方数。
6 | ## 4 九位累进可除数
7 | ## 求九位累进可除数。所谓九位累进可除数就是这样一个数:这个数用到1到9这九个数字组成,每个数字刚好只出现一次。这九个位数的前两位能被2整除,前三位能被3整除......前N位能被N整除,整个九位数能被9整除。
8 |
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/search.md:
--------------------------------------------------------------------------------
1 | # lec11: 搜索
2 |
3 | ## 万能的解法之搜索
4 |
5 | - 解空间
6 | - 几何空间
7 | - 子集空间
8 | - 全排列空间
9 | - 深度优先搜索DFS
10 | - 广度优先搜索BFS
11 |
12 | ## 深度优先搜素dfs
13 |
14 | ## 利用dfs遍历子集空间
15 |
16 | ## 利用dfs遍历全排列空间
17 |
18 | # dfs应用
19 | ## 单调空间的二分搜索
20 | - 二分查找
21 | - 二分答案
22 |
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec04dfsbfs/subset2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int main() //2^4 0000~1111
5 | {
6 | int A[]={3,4,7,9},M=20;
7 | for(int i=0;i<(1< B(i);
10 | cout<
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int t;
7 | cin >> t;
8 | while (t--) {
9 | int n;
10 | cin >> n;
11 | cout << '[';
12 | for (int i = 1; i <= n; i++)
13 | cout << '>';
14 | for (int i = 1; i <= 100 - n; i++)
15 | cout << ' ';
16 | cout << ']';
17 | cout << setw(2) << setfill('0') << n << endl;
18 | }
19 |
20 | return 0;
21 | }
--------------------------------------------------------------------------------
/ACM/2019ACM集训/lec08final/I.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | const int INF = 0x3f3f3f3f3f;
6 |
7 | const int MAXN = 1e5 + 10;
8 | int dis[MAXN];
9 | int n, l, r;
10 |
11 | int main() {
12 | cin >> n;
13 | for (int i = 1; i <= n - 1; i++) {
14 | cin >> l >> r;
15 | dis[l]++;
16 | dis[r]++;
17 | }
18 | int res = 0;
19 | for (int i = 1; i <= n; i++) {
20 | res = max(dis[i] + 1, res);
21 | }
22 | cout << res << endl;
23 |
24 | return 0;
25 | }
--------------------------------------------------------------------------------
/ACM/AHCPC/2010/A3.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | using namespace std;
5 |
6 | int main() {
7 | for (string a, b; getline(cin, a) and getline(cin, b);) {
8 | transform(a.begin(), a.end(), a.begin(), _tolower);
9 | transform(b.begin(), b.end(), b.begin(), _tolower);
10 | int ans = 0;
11 | for (auto p = b.find(a); p != string::npos; p = b.find(a, p + a.size())) ++ans;
12 | cout << ans << endl;
13 | }
14 | return 0;
15 | }
--------------------------------------------------------------------------------
/ACM/AHCPC/2011/I.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | for (int n, m; cin >> n >> m;) {
7 | for (int i = 0; i <= n; i++) {
8 | int j = n - i;
9 | if (4 * i + 2 * j == m) {
10 | cout << i << " " << j << endl;
11 | break;
12 | }
13 | }
14 | }
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/ACM/AHCPC/2012/D.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | using namespace std;
5 |
6 | int main() {
7 | int n;
8 | //freopen("D.in", "r", stdin);
9 | //freopen("D.out", "w", stdout);
10 | while (scanf("%d", &n) != EOF) {
11 | int sum = 0;
12 | for (int i = 0; i < n; i++) {
13 | int x;
14 | scanf("%d", &x);
15 | sum ^= x;
16 | }
17 | if (sum) printf("Yes\n");
18 | else printf("No\n");
19 | }
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/ACM/AHCPC/2016/A.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int n, ax, bx, ay, by;
7 | for (scanf("%d", &n); n--;) {
8 | scanf("%d%d%d%d", &ax, &ay, &bx, &by);
9 | printf("%d\n", abs(ax * ay - bx * by));
10 | }
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/ACM/AHCPC/2017/A.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/AHCPC/2017/A.cpp
--------------------------------------------------------------------------------
/ACM/AHCPC/2017/B.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/AHCPC/2017/B.cpp
--------------------------------------------------------------------------------
/ACM/AHCPC/2017/E.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/AHCPC/2017/E.cpp
--------------------------------------------------------------------------------
/ACM/AHCPC/2018/C.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/AHCPC/2018/C.cpp
--------------------------------------------------------------------------------
/ACM/AHCPC/2018/E.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/AHCPC/2018/E.cpp
--------------------------------------------------------------------------------
/ACM/AHCPC/2018/K.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | typedef long long LL;
6 |
7 | int main() {
8 | LL n;
9 | int t;
10 | cin >> t;
11 | while (t--) {
12 | cin >> n;
13 | if (n % 4 == 0) {
14 | cout << "Bob win" << endl;
15 | } else {
16 | cout << "Alice win" << endl;
17 | }
18 | }
19 |
20 | return 0;
21 | }
--------------------------------------------------------------------------------
/ACM/AHCPC/2019/H.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | const int N = 3e2 + 5;
5 | char s[N];
6 | int n, ans;
7 |
8 | int main() {
9 | scanf("%s", s + 1);
10 | n = strlen(s + 1);
11 |
12 | s[0] = '0';
13 | for (int i = 2; i <= n; ++i) {
14 | if (s[i] == s[i - 1] || s[i] == s[i - 2])
15 | ans++, s[i] = '0';
16 | }
17 |
18 | printf("%d\n", ans);
19 | return 0;
20 | }
--------------------------------------------------------------------------------
/ACM/AHCPC/2019/_A2.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by webturing on 2019/5/19.
3 | //
4 |
5 | #include
6 |
7 | using namespace std;
8 |
9 | //2019ahcpc热身赛第一题: 喝个够
10 | //n瓶饮料 m个空瓶可以换一瓶饮料 问这个人最多可以喝多少瓶
11 | //数学算法 m个空瓶子可以换一瓶,所以实际上是m-1个瓶子换了一瓶(没有瓶子)的饮料
12 | //考虑到他最后必然手里有一个无法兑换的瓶子所以 n-1
13 | int main() {
14 | int n, m;
15 | cin >> n >> m;
16 | cout << n + (n - 1) / (m - 1) << endl;
17 | return 0;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/ACM/AHCPC/2020Sep/read.md:
--------------------------------------------------------------------------------
1 | 2020AHCPC 9月赛
2 |
--------------------------------------------------------------------------------
/ACM/CCPC/2019CCPCwfinal/BGcd.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | using ll = long long;
5 |
6 | int main() {
7 | ll n;
8 | cin >> n;
9 | ll s = n * (n + 1) / 2;
10 | for (ll p = 2; p <= s; p++) {
11 | if (s % p == 0) {
12 | cout << s / p << endl;
13 | break;
14 | }
15 | }
16 | return 0;
17 | }
--------------------------------------------------------------------------------
/ACM/CCPC/2019CCPCwfinal/JTangram.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | using LL = unsigned long long;
5 |
6 | int main() {
7 | LL n;
8 | cin >> n;
9 | LL r = 7 + 6 * n + n * (n - 1) / 2;
10 | cout << r << endl;
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/ACM/CCPC/CCPC2016hefei/A.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/CCPC/CCPC2016hefei/A.cpp
--------------------------------------------------------------------------------
/ACM/CCPC/CCPC2016hefei/J.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/CCPC/CCPC2016hefei/J.cpp
--------------------------------------------------------------------------------
/ACM/CCPC/CCPC2018/1010.txt:
--------------------------------------------------------------------------------
1 |
2 | 2
3 | 3
4 | 1 1 1
5 | 1 2 2
6 | 3 3 1
7 | 3
8 | 1 1 1
9 | 1 2 2
10 | 3 3 1
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018/B.txt:
--------------------------------------------------------------------------------
1 | 2 10
2 | 1 1 1 23
3 | 1 1 0 233
4 | 2 1 1
5 | 1 2 1 2333
6 | 1 2 1 23333
7 | 3 1 2 1
8 | 2 2 0
9 | 2 1 1
10 | 2 1 0
11 | 2 1 1
12 |
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018/B2.txt:
--------------------------------------------------------------------------------
1 | 2 4
2 | 1 1 1 1
3 | 1 1 2 1
4 | 3 1 1 1
5 | 2 1 1
6 |
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018/C.txt:
--------------------------------------------------------------------------------
1 | 5 1
2 | 11010
3 | 5 2
4 | 11010
5 | 5 1
6 | 00111
7 | 6 2
8 | 011010
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018/CAC.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/Contests/baiduStar2018/CAC.java
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018B/A.in:
--------------------------------------------------------------------------------
1 | 2
2 | 3 1 1
3 | 1 2
4 | 8 6 0
5 | 1 2
6 | 3 1
7 | 5 6
8 | 4 1
9 | 6 4
10 | 7 0
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018B/B.in:
--------------------------------------------------------------------------------
1 | 1
2 | 3
3 | 012
4 | 3456
5 | 789ab
6 | cdef
7 | ghi
8 | 10
9 | 1 3 1
10 | 1 3 2
11 | 1 3 3
12 | 9 3 1
13 | 7 3 1
14 | 3 3 1
15 | 3 3 2
16 | 5 3 1
17 | 5 3 2
18 | 2 2 2
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018B/C.in:
--------------------------------------------------------------------------------
1 | 1
2 | 11 2
3 | 0 1 100
4 | 0 2 199700
5 | 0 3 200
6 | 1 4 120000
7 | 1 5 80000
8 | 3 6 100000
9 | 3 7 100000
10 | 7 8 90000
11 | 7 9 90000
12 | 7 10 20000
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018B/D.in:
--------------------------------------------------------------------------------
1 | 3
2 | 5
3 | -4 2 2 2 2
4 | 3
5 | 1 2 4
6 | 2
7 | 0 100000000
8 |
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018B/E.in:
--------------------------------------------------------------------------------
1 | 2
2 | 5
3 | 1 0 1 0 1
4 | 9
5 | 1 0 1 0 1 -3 4 0 4
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018B/F.in:
--------------------------------------------------------------------------------
1 | 2
2 | 4 4 1
3 | 2 2
4 | 10 7 3
5 | 6 3
6 | 2 6
7 | 9 5
--------------------------------------------------------------------------------
/ACM/Contests/baiduStar2018B/G.in:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/Contests/baiduStar2018B/G.in
--------------------------------------------------------------------------------
/ACM/Contests/nowcoder201807monthly/A.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int n;
7 | cin >> n;
8 | int sum = 0;
9 | int x;
10 | for (int i = 0; i < n; i++) {
11 | cin >> x;
12 | while (x % 2 == 0) {
13 | x /= 2;
14 | sum++;
15 | }
16 | }
17 | cout << sum << endl;
18 | return 0;
19 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/books.aHaAlgorithm/Dijkstra算法_单源最短路.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/代码模板库/BOOKS/books.aHaAlgorithm/Dijkstra算法_单源最短路.cpp
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/books.aHaAlgorithm/c0101BucketSort.py:
--------------------------------------------------------------------------------
1 | # coding=utf-8
2 | '''
3 | 数组的桶排序 O(n)*O(MAX-MIN)
4 |
5 | '''
6 |
7 | MIN,MAX=0,100#约定每一个数据都在[0,100)之间
8 | def bucketSort(lst):
9 | ans=[] #返回值
10 | freq=[0]*(MAX-MIN) #每一个数频度都置为0
11 | for ele in lst:
12 | freq[ele]+=1 #统计频率
13 | for idx in xrange(MIN,MAX): #还原
14 | for k in xrange(freq[idx]):
15 | ans.append(idx),
16 | return ans
17 |
18 | if __name__=='__main__':
19 | lst=[2,8,5,3,5]
20 | print bucketSort(lst)
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/books.aHaAlgorithm/c0102BubbleSort.py:
--------------------------------------------------------------------------------
1 | # coding=utf-8
2 | '''
3 | 数组的冒泡排序 O(n^2)
4 |
5 | '''
6 |
7 |
8 | def bubbleSort(lst):
9 | for i in xrange(len(lst)):
10 | for j in xrange(len(lst)-i-1):
11 | if lst[j]>lst[j+1]:
12 | lst[j],lst[j+1]=lst[j+1],lst[j]
13 | return lst
14 |
15 |
16 | if __name__=='__main__':
17 | lst=[12,35,99,18,76]
18 | print bubbleSort(lst)
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/books.aHaAlgorithm/c0103QuickSort.py:
--------------------------------------------------------------------------------
1 | # coding=utf-8
2 | '''
3 | 数组的快速排序 O(NlogN)
4 |
5 | '''
6 |
7 | def quickSort(lst):
8 | if len(lst)<=1:
9 | return lst
10 | mid=[x for x in lst if x==lst[0]]
11 | left=[x for x in lst if xlst[0]]
13 | return quickSort(left)+mid+quickSort(right)
14 |
15 |
16 | if __name__=='__main__':
17 | lst=[6,1,7,2,9,3,4,5,10,8]
18 | print quickSort(lst)
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/books.aHaAlgorithm/c0104SelectionSort.py:
--------------------------------------------------------------------------------
1 | # coding=utf-8
2 | '''
3 | 数组的选择排序 O(n^2)
4 |
5 | '''
6 |
7 | def selectionSort(lst):
8 | for i in xrange(len(lst)):
9 | minIndex=lst[i:].index(min(lst[i:]))+i ##容易犯错,查找的是lst[i:]的坐标,相对于lst应该+i
10 | lst[i],lst[minIndex]=lst[minIndex],lst[i]
11 | return lst
12 |
13 |
14 | if __name__=='__main__':
15 | lst=[12,35,99,18,76]
16 | print selectionSort(lst)
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/books.aHaAlgorithm/comments.MD:
--------------------------------------------------------------------------------
1 | # 啊哈算法
2 | - 基础算法教材
3 | - 可以作为算法导论的前奏
4 | - 看完就可以认真饱读AOCP
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/books.aHaAlgorithm/n的全排列.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/代码模板库/BOOKS/books.aHaAlgorithm/n的全排列.cpp
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/chapter02AlgorithmComplexity/ALDS0101DMaximumProfit.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | int n;
7 | cin >> n;
8 | vector R(n);
9 | for (auto &i:R)cin >> i;
10 | //O(n^2)
11 | int maxv = -1;
12 | for (int j = 1; j < n; j++)
13 | for (int i = 0; i < j; i++)
14 | maxv = max(maxv, R[j] - R[i]);
15 | cout << maxv << endl;
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/chapter02AlgorithmComplexity/ALDS0101DMaximumProfit3.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | int n;
7 | cin >> n;
8 | int t;
9 | cin >> t;
10 | //O(N)+O(1)
11 | int maxv = -200000000;
12 | int minv = t;
13 | for (int i = 1; i < n; i++) {
14 | cin >> t;
15 | maxv = max(maxv, t - minv);
16 | minv = min(minv, t);
17 | }
18 |
19 | cout << maxv << endl;
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/chapter02AlgorithmComplexity/Ex0202Top3B.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | int main(int argc, char const *argv[]) {
7 | vector S(10);
8 | for (auto &i:S) {
9 | cin >> i;
10 | }
11 | sort(S.begin(), S.end());
12 | copy(S.rbegin(), S.rbegin() + 3, ostream_iterator(cout, " "));
13 | cout << endl;
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/chapter02AlgorithmComplexity/Ex0202Top3C.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | int main(int argc, char const *argv[]) {
7 | vector S(10);
8 | for (auto &i:S)cin >> i;
9 | vector C(101, 0);
10 | for (auto s:S) {
11 | C[s]++;
12 | }
13 | int cnt = 3;
14 | for (int p = 100; cnt && p >= 0; p--) {
15 | while (C[p] && cnt) {
16 | cout << p << " ";
17 | --cnt;
18 | }
19 | }
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0101.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | cout << 1 + 2 << endl;
5 | cout << 3 - 4 << endl;
6 | cout << 5 + 6 << endl;
7 | cout << 8 / 4 << endl;
8 | cout << 8 / 5 << endl;
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0102.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | cout << fixed << setprecision(1) << 8.0 / 5.0 << endl;
5 | cout << fixed << setprecision(1) << 8 / 5 << endl;
6 | cout << fixed << setprecision(0) << 8.0 / 5.0 << endl;
7 | return 0;
8 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0103.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | cout << fixed << setprecision(8) << (1 + 2 * sqrt(3)) / (5 - 0.1) << endl;
5 | return 0;
6 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0104.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int a, b;
5 | cin >> a >> b;
6 | cout << a + b << endl;
7 | return 0;
8 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0105.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | const double PI = acos(-1);
4 | int main(int argc, char const *argv[]) {
5 | double r, h, s1, s2, s;
6 | cin >> r >> h;
7 | s1 = PI * r * r;
8 | s2 = 2 * PI * r * h;
9 | s = s1 * 2 + s2;
10 | cout << "Area = " << fixed << setprecision(3) << s << endl;
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0106.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int n = 120;
5 | int a = n / 100;
6 | int b = (n % 100) / 10;
7 | int c = n % 10;
8 | cout << c << b << a << endl;
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0107.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int n = 120;
5 | int a = n / 100;
6 | int b = (n % 100) / 10;
7 | int c = n % 10;
8 | cout << 100 * c + 10 * b + a << endl;
9 | cout << setw(3) << setfill('0') << 100 * c + 10 * b + a << endl;
10 | return 0;
11 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0108.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int a, b;
5 | cin >> a >> b;
6 | int t = a;
7 | a = b;
8 | b = t;
9 | cout << a << " " << b << endl;
10 | return 0;
11 | }
12 | // swap 1
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0109.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int a, b;
5 | cin >> a >> b;
6 | a = a + b;
7 | b = a - b;
8 | a = a - b;
9 | cout << a << " " << b << endl;
10 | return 0;
11 | }
12 | // swap 2
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0110.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int a, b;
5 | cin >> a >> b;
6 | cout << b << " " << a << endl;
7 | swap(a, b);
8 | cout << a << " " << b << endl;
9 | return 0;
10 | }
11 | // swap 3
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0111.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int a, b, n, m;
5 | cin >> n >> m;
6 | a = (4 * n - m) / 2;
7 | b = n - a;
8 | if (m % 2 == 0 && a >= 0 && b >= 0) {
9 | cout << a << " " << b << endl;
10 | } else {
11 | cout << "No answer" << endl;
12 | }
13 | return 0;
14 | }
15 | //鸡兔同笼
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/example0112.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | ifstream cin("sort3.in");
5 |
6 | int a, b, c;
7 | while (cin >> a >> b >> c) {
8 | if (a > b) swap(a, b);
9 | if (a > c) swap(a, c);
10 | if (b > c) swap(b, c);
11 | cout << a << " " << b << " " << c << endl;
12 | }
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch01/sort3.in:
--------------------------------------------------------------------------------
1 | 1 2 3
2 | 1 3 2
3 | 2 1 3
4 | 2 3 1
5 | 3 1 2
6 | 3 2 1
7 | 1 1 2
8 | 1 2 1
9 | 2 1 1
10 | 1 1 1
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch02/example0201.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | int n;
5 | cin >> n;
6 | for (int i = 1; i <= n; i++) {
7 | cout << i << endl;
8 | }
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch02/example0202.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | for (int a = 1; a <= 9; a++)
5 | for (int b = 0; b <= 9; b++) {
6 | int n = a * 1100 + b * 11;
7 | int m = floor(sqrt(n) + 0.5);
8 | if (m * m == n) cout << n << endl;
9 | }
10 | return 0;
11 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch02/example0203.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | for (int i = 34; i * i <= 9999; i++) {
5 | int a = i * i / 100;
6 | int b = i * i % 100;
7 | if (a % 11 == 0 && b % 11 == 0) {
8 | cout << i *i << endl;
9 | }
10 | }
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch02/example0204.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | // int n;//bugs
5 | long long n;
6 | cin >> n;
7 | int cnt = 0;
8 | while (n > 1) {
9 | if (n % 2 == 0) {
10 | n /= 2;
11 | } else {
12 | n = 3 * n + 1;
13 | }
14 | ++cnt;
15 | }
16 | cout << cnt << endl;
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch03/UVa10082.cpp:
--------------------------------------------------------------------------------
1 | // UVa10082 WERTYU
2 | // Rujia Liu
3 | #include
4 | char s[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
5 | int main() {
6 | int i, c;
7 | while((c = getchar()) != EOF) {
8 | for (i=1; s[i] && s[i]!=c; i++); // 找错位之后的字符在常量表中的位置
9 | if (s[i]) putchar(s[i-1]); // 如果找到,则输出它的前一个字符
10 | else putchar(c);
11 | }
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch03/UVa272.cpp:
--------------------------------------------------------------------------------
1 | // UVa272 Tex Quotes
2 | // Rujia Liu
3 | #include
4 | int main() {
5 | int c, q = 1;
6 | while((c = getchar()) != EOF) {
7 | if(c == '"') { printf("%s", q ? "``" : "''"); q = !q; }
8 | else printf("%c", c);
9 | }
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch03/readme.md:
--------------------------------------------------------------------------------
1 | 《算法竞赛入门经典》第二版 范例代码
2 |
3 | 刘汝佳
4 |
5 | 第三章
6 |
7 | 例题
8 |
9 | 注:所有代码都可以用C99和C++编译,为了和后面统一,后缀名均为cpp
10 |
11 | 3-1. UVa272 Tex Quotes
12 |
13 | 3-2. UVa10082 WERTYU
14 |
15 | 3-3. UVa401 Palindromes
16 |
17 | 3-4. UVa340 Master-Mind Hints
18 |
19 | 3-5. UVa1583 Digit Generator
20 |
21 | 3-6. UVa1584 Circular Sequence
22 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch04/fp.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /*
4 | 演示一些浮点误差
5 | 在笔者的环境下,运行结果为:
6 | 0.9999990
7 | 0.2499998
8 | 0.2
9 | */
10 |
11 | int main() {
12 | double f;
13 | for(f = 2; f > 1; f -= 1e-6);
14 | printf("%.7f\n", f);
15 | printf("%.7f\n", f / 4);
16 | printf("%.1f\n", f / 4);
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch04/point.cpp:
--------------------------------------------------------------------------------
1 | struct Point {
2 | double x, y;
3 | };
4 |
5 | double dist(Point a, Point b) { return 0; }
6 |
7 | int main() { return 0; }
8 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch04/uva12412_sample.in:
--------------------------------------------------------------------------------
1 | 1
2 | 0011223344 1 John 79 98 91 100
3 | 0022334455 1 Tom 59 72 60 81
4 | 0011223344 2 Alice 100 100 100 100
5 | 2423475629 2 John 60 80 30 99
6 | 0
7 | 3
8 | 0022334455
9 | John
10 | 0
11 | 5
12 | 1
13 | 2
14 | 0011223344
15 | 0
16 | 5
17 | 0
18 | 4
19 | 0
20 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch05/5-1.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int a, b;
5 | while(scanf("%d%d", &a, &b) == 2) printf("%d\n", a+b);
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch05/5-2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | int main() {
6 | long long a, b;
7 | while(cin >> a >> b) {
8 | cout << min(a,b) << "\n";
9 | }
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch05/5-3.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | struct Point {
5 | int x, y;
6 | Point(int x=0, int y=0):x(x),y(y) {}
7 | };
8 |
9 | int main() {
10 | Point p1, p2;
11 | swap(p1, p2);
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch05/pq.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | struct cmp {
6 | bool operator() (const int a, const int b) const { // a的优先级比b小时返回true
7 | return a % 10 > b % 10;
8 | }
9 | };
10 |
11 | int main() {
12 | priority_queue, cmp> pq;
13 | pq.push(1);
14 | pq.push(3);
15 | pq.push(22);
16 | pq.push(44);
17 | while(!pq.empty()) {
18 | cout << pq.top() << "\n";
19 | pq.pop();
20 | }
21 |
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part01-language/ch05/test_sstream.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 |
6 | int main() {
7 | string line;
8 | while(getline(cin, line)) {
9 | int sum = 0, x;
10 | stringstream ss(line);
11 | while(ss >> x) sum += x;
12 | cout << sum << "\n";
13 | }
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part02-basic/ch6/UVa679.cpp:
--------------------------------------------------------------------------------
1 | // UVa679 Dropping Balls
2 | // Rujia Liu
3 | #include
4 | int main() {
5 | int T, D, I;
6 | scanf("%d", &T);
7 | while(T--) {
8 | scanf("%d%d", &D, &I);
9 | int k = 1;
10 | for(int i = 0; i < D-1; i++)
11 | if(I%2) { k = k*2; I = (I+1)/2; }
12 | else { k = k*2+1; I /= 2; }
13 | printf("%d\n", k);
14 | }
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part02-basic/ch7/8a.in:
--------------------------------------------------------------------------------
1 | 2 6 4 1 3 7 0 5 8
2 | 8 1 5 7 3 6 4 0 2
3 |
4 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part02-basic/ch7/8b.in:
--------------------------------------------------------------------------------
1 | 1 2 3 4 5 6 7 8 0
2 | 1 2 3 4 5 6 8 7 0
3 |
4 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part02-basic/ch7/p1603.ans:
--------------------------------------------------------------------------------
1 | 4
2 | 6
3 | 8
4 | 8
5 | 7
6 | 7
7 | 2
8 | 4
9 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part02-basic/ch7/p1603.in:
--------------------------------------------------------------------------------
1 | 8
2 | 3
3 | 8 1 3 4 7 18 21 22 24
4 | 3
5 | 0
6 | 4
7 | 2 6 30
8 | 4
9 | 4 1 5 36 40
10 | 4
11 | 4 16 20 21 25
12 | 4
13 | 8 1 2 5 6 10 11 14 15
14 | 4
15 | 9 6 8 17 19 20 28 29 26 35
16 | 3
17 | 2 12 13
18 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part02-basic/ch7/pp3.cpp:
--------------------------------------------------------------------------------
1 | // 可重集的全排列(next_permutation版)
2 | // Rujia Liu
3 | #include
4 | #include
5 | using namespace std;
6 |
7 | int main() {
8 | int n, p[10];
9 | scanf("%d", &n);
10 | for(int i = 0; i < n; i++) scanf("%d", &p[i]);
11 | sort(p, p+n); // 排序,得到p的最小排列
12 | do {
13 | for(int i = 0; i < n; i++) printf("%d ", p[i]); // 输出排列p
14 | printf("\n");
15 | } while(next_permutation(p, p+n)); // 求下一个排列
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part02-basic/ch7/subset3.cpp:
--------------------------------------------------------------------------------
1 | // {0~n-1}的所有子集:二进制法
2 | // Rujia Liu
3 | #include
4 | using namespace std;
5 |
6 | void print_subset(int n, int s) { // 打印{0, 1, 2, ..., n-1}的子集S
7 | for(int i = 0; i < n; i++)
8 | if(s&(1<
4 | int main() {
5 | int n, T;
6 | scanf("%d", &T);
7 | while(T--) {
8 | scanf("%d", &n);
9 | int V = 0, E = 0;
10 | for(int i = 0; i <= n-2; i++)
11 | V += i*(n-2-i), E += i*(n-2-i)+1;
12 | V = V*n/4+n;
13 | E = E*n/2+n;
14 | printf("%d\n", E-V+1);
15 | }
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part03-contest/ch10/UVa10288.in:
--------------------------------------------------------------------------------
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5
6 | 6
7 | 7
8 | 8
9 | 9
10 | 10
11 | 11
12 | 12
13 | 13
14 | 14
15 | 15
16 | 16
17 | 17
18 | 18
19 | 19
20 | 20
21 | 21
22 | 22
23 | 23
24 | 24
25 | 25
26 | 26
27 | 27
28 | 28
29 | 29
30 | 30
31 | 31
32 | 32
33 | 33
34 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part03-contest/ch10/UVa1641.cpp:
--------------------------------------------------------------------------------
1 | // UVa1641/LA5910 ASCII Area
2 | // Rujia Liu
3 | #include
4 | int main() {
5 | int h, w;
6 | char s[999];
7 | while(scanf("%d%d", &h, &w) == 2) {
8 | int ans = 0, c = 0;
9 | while(h--) {
10 | scanf("%s", s);
11 | int in = 0;
12 | for(int i = 0; i < w; i++) {
13 | if(s[i] == '/' || s[i] == '\\') { c++; in = !in; }
14 | else if(in) ans++;
15 | }
16 | }
17 | printf("%d\n", ans + c/2);
18 | }
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part03-contest/ch10/UVa580.cpp:
--------------------------------------------------------------------------------
1 | // UVa580 Critical Mass
2 | // Rujia Liu
3 | #include
4 | using namespace std;
5 |
6 | int f[31], g[31];
7 |
8 | int main() {
9 | f[0] = f[1] = f[2] = 0;
10 | g[0] = 1; g[1] = 2; g[2] = 4;
11 | for(int n = 3; n <= 30; n++) {
12 | f[n] = 1 << (n-3);
13 | for(int i = 2; i <= n-2; i++)
14 | f[n] += g[i-2] * (1 << (n-i-2));
15 | g[n] = (1<> n && n)
19 | cout << f[n] << "\n";
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part03-contest/ch10/uva10491.cpp:
--------------------------------------------------------------------------------
1 | // UVa10491 Cows and Cars
2 | // Rujia Liu
3 | #include
4 | int main() {
5 | int a, b, c;
6 | while(scanf("%d%d%d", &a, &b, &c) == 3)
7 | printf("%.5lf\n", (double)(a*b+b*(b-1)) / (a+b) / (a+b-c-1));
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part03-contest/ch10/uva11346.cpp:
--------------------------------------------------------------------------------
1 | // UVa11346 Probability
2 | // Rujia Liu
3 | #include
4 | #include
5 | int main() {
6 | int T;
7 | scanf("%d", &T);
8 | while(T--) {
9 | double a, b, s, ans;
10 | scanf("%lf%lf%lf", &a, &b, &s);
11 | double m = a*b;
12 | if(fabs(s) < 1e-6) ans = 1;
13 | else if(s > m) ans = 0;
14 | else ans = (m - s - s * log(m/s)) / m;
15 | printf("%.6lf%%\n", ans * 100);
16 | }
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part03-contest/ch10/uva12230.cpp:
--------------------------------------------------------------------------------
1 | // UVa12230 Crossing Rivers
2 | // Rujia Liu
3 | #include
4 | int main() {
5 | int n, D, p, L, v, kase = 0;
6 | while(scanf("%d%d", &n, &D) == 2 && D) {
7 | double ans = 0;
8 | while(n--) {
9 | scanf("%d%d%d", &p, &L, &v);
10 | D -= L; ans += 2.0 * L / v;
11 | }
12 | printf("Case %d: %.3lf\n\n", ++kase, ans + D);
13 | }
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/ACM/代码模板库/BOOKS/part03-contest/ch8/UVa11054.cpp:
--------------------------------------------------------------------------------
1 | // UVa11054 Wine trading in Gergovia
2 | // Rujia Liu
3 | #include
4 | #include
5 | using namespace std;
6 |
7 | int main() {
8 | int n;
9 | while(cin >> n && n) {
10 | long long ans = 0, a, last = 0;
11 | for(int i = 0; i < n; i++) {
12 | cin >> a;
13 | ans += abs(last);
14 | last += a;
15 | }
16 | cout << ans << "\n";
17 | }
18 | return 0;
19 | }
20 |
--------------------------------------------------------------------------------
/ACM/代码模板库/README.md:
--------------------------------------------------------------------------------
1 | # ACM-Code-Library
2 | @Author calabash_boy
3 |
4 | ## Blog:[calabash_boy](http://blog.csdn.net/calabash_boy)
5 |
6 | ## Team Wiki:[Calabash!](http://wiki-calabash.icpc.camp)
7 |
8 |
--------------------------------------------------------------------------------
/ACM/代码模板库/WF-Team-Reference-Document.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/代码模板库/WF-Team-Reference-Document.pdf
--------------------------------------------------------------------------------
/ACM/代码模板库/sam.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/代码模板库/sam.png
--------------------------------------------------------------------------------
/ACM/代码模板库/template.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/ACM/代码模板库/template.pdf
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(cplusplus)
3 |
4 | set(CMAKE_CXX_STANDARD 11)
5 |
6 | set(SOURCE_FILES main.cpp)
7 | add_executable(cplusplus ${SOURCE_FILES})
--------------------------------------------------------------------------------
/CppSTL/algorithm/copy_if.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | vector v{1, 3, 5, 8, 7, 9, 4};
7 | vector w(v.size());
8 | auto pos = copy_if(v.begin(), v.end(), w.begin(), [](int x) {
9 | return x & 1;
10 | });
11 | w.erase(pos, w.end());
12 | copy(w.begin(), w.end(), ostream_iterator(cout, " "));
13 |
14 | return 0;
15 | }
--------------------------------------------------------------------------------
/CppSTL/algorithm/find_if_not.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | vector v{1, 3, 5, 8, 7, 9, 4};
7 |
8 | cout << "first odd is " << *find_if(v.begin(), v.end(), [](int x) {
9 | return x & 1;
10 | }) << endl;
11 |
12 |
13 | cout << "first even is " << *find_if_not(v.begin(), v.end(), [](int x) {
14 | return x & 1;
15 | }) << endl;
16 |
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/CppSTL/algorithm/iota.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | vector v(10);
7 | iota(v.begin(), v.end(), 2);//??a[0]=1 a[i]=a[i-1]+1????
8 |
9 | copy(v.begin(), v.end(), ostream_iterator(cout, " "));
10 | cout << endl;
11 |
12 | array a;
13 | iota(a.begin(), a.end(), 3);
14 |
15 | copy(a.begin(), a.end(), ostream_iterator(cout, " "));
16 | cout << endl;
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/CppSTL/algorithm/is_sorted.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | vector a{1, 2, 3, 6, 5, 4, 7};
7 | auto p = is_sorted_until(a.begin(), a.end());
8 |
9 | copy(a.begin(), p, ostream_iterator(cout, " "));
10 | cout << endl;
11 |
12 | cout << is_sorted(a.begin(), a.end()) << endl;
13 |
14 | sort(a.begin(), a.end());
15 |
16 | cout << is_sorted(a.begin(), a.end()) << endl;
17 |
18 | return 0;
19 | }
--------------------------------------------------------------------------------
/CppSTL/algorithm/minmax_element.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 |
7 | vector v = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0};
8 | auto result = minmax_element(v.begin(), v.end());
9 | cout << *result.first << " " << *result.second << endl;
10 |
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/CppSTL/algorithm/nth_element.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | vector v{1, 3, 4, 5, 2, 6, 8, 7, 9};
7 | for_each(v.begin(), v.end(), [](int x) {
8 | cout << x << " ";
9 | });
10 | cout << endl;
11 |
12 | nth_element(v.begin(), v.begin() + 5, v.end());
13 |
14 | copy(v.begin(), v.end(), ostream_iterator(cout, " "));
15 | cout << endl;
16 |
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/CppSTL/cxx11.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | template
4 | T read() {
5 | T x;
6 | cin >> x;
7 | return x;
8 | }
9 | const int N = read();
10 | vector A(N, 0);
11 | int B[N];
12 | int main() {
13 | for (int i = 0; i < N; i++) cout << A[i] << endl;
14 |
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/CppSTL/rmq.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/CppSTL/rmq.cpp
--------------------------------------------------------------------------------
/CppSTL/sstreamDemo.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | int main() {
6 | int x = 123, y = 45;
7 | ostringstream oss;
8 | cout << x << y << " " << y << x << endl; // 12345 45123
9 | oss << x << y << " " << y << x;
10 | int a, b;
11 | istringstream iss(oss.str());
12 | iss >> a >> b;
13 | cout << "a=" << a << endl;
14 | cout << "b=" << b << endl;
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/CppSTL/testCPU.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/CppSTL/testCPU.cpp
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1027.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | template
4 | T read(){
5 | T x;
6 | cin >> x;
7 | return x;
8 | }
9 | int main(){
10 | int r = read(), g = read(), b = read();
11 | string s = "0123456789ABC";
12 | cout << "#" << s[r / 13] << s[r % 13] << s[g / 13] << s[g % 13] << s[b / 13] << s[b % 13] << endl;
13 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1031.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(){
4 | string s;
5 | cin >> s;
6 | int n = s.size() + 2;
7 | int n1 = n / 3, n2 = n / 3 + n % 3;
8 | for(int i = 0; i < n1-1; i++){
9 | cout << s[i];
10 | for(int j = 1; j < n2-1; j++){
11 | cout << ' ';
12 | }
13 | cout << s[s.size() - i - 1] << endl;
14 | }
15 | for(int i = 0; i < n2; i++){
16 | cout << s[n1-1 + i];
17 | }
18 | cout << endl;
19 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1041.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | template
5 | T read(){
6 | T x;
7 | cin >> x;
8 | return x;
9 | }
10 | int main(){
11 | int n = read();
12 | mapM;
13 | vectorv(n);
14 | for(int i = 0; i < n; i++){
15 | v[i] = read();
16 | M[v[i]]++;
17 | }
18 | for(int i = 0; i < n; i++){
19 | if(M[v[i]] == 1){
20 | cout << v[i] << endl;
21 | return 0;
22 | }
23 | }
24 | cout << "None" << endl;
25 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1050.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(){
4 | string s1, s2;
5 | getline(cin, s1);
6 | getline(cin, s2);
7 | mapM;
8 | for(auto i: s2){
9 | M[i] = true;
10 | }
11 | for(auto i: s1){
12 | if(M[i])continue;
13 | cout << i;
14 | }
15 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1054.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | template
4 | T read(){
5 | T x;
6 | cin >> x;
7 | return x;
8 | }
9 | int main(){
10 | int n = read(), m = read();
11 | mapM;
12 | for(int i = 0; i < n; i++){
13 | for(int j = 0; j < m; j++){
14 | M[read()]++;
15 | }
16 | }
17 | int res = 0, val = 0;
18 | for(auto i: M){
19 | if(val < i.second){
20 | val = i.second;
21 | res = i.first;
22 | }
23 | }
24 | cout << res << endl;
25 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1058.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(){
4 | int a1, a2, a3, b1, b2, b3;
5 | scanf("%d.%d.%d %d.%d.%d", &a1, &a2, &a3, &b1, &b2, &b3);
6 | a1 += b1;
7 | a2 += b2;
8 | a3 += b3;
9 | a2 += a3/29;
10 | a3 %= 29;
11 | a1 += a2/17;
12 | a2 %= 17;
13 | printf("%d.%d.%d\n", a1, a2, a3);
14 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1067.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(){
4 | int n;
5 | cin >> n;
6 | vectora(n);
7 | int cnt = 0, r = 0;
8 | for(int i = 0; i < n; i++){
9 | int t;
10 | cin >> t;
11 | a[t] = i;
12 | }
13 | for(int i = 0; i < n; i++){
14 | if(a[i] != i){
15 | while(a[0] != 0){
16 | swap(a[0], a[a[0]]);
17 | cnt++;
18 | }
19 | if(a[i] != i){
20 | swap(a[0], a[i]);
21 | cnt++;
22 | }
23 | }
24 | }
25 | cout << cnt << endl;
26 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1085.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | using ll = long long;
4 | int main(){
5 | int n, k;
6 | cin >> n >> k;
7 | vectorv(n);
8 | for(int i = 0; i < n; i++){
9 | cin >> v[i];
10 | }
11 | sort(v.begin(), v.end());
12 | int best = 0;
13 | for(int i = 0; i < n; i++){
14 | ll minimum = v[i];
15 | ll maximum = minimum*k;
16 | int j = upper_bound(v.begin(), v.end(), maximum) - v.begin();
17 | best = max(best, j - i);
18 | }
19 | cout << best << endl;
20 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1092.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(){
4 | string s1, s2;
5 | cin >> s1 >> s2;
6 | mapM1, M2;
7 | for(auto i: s1){
8 | M1[i]++;
9 | }
10 | for(auto i: s2){
11 | M2[i]++;
12 | }
13 | int cnt = 0;
14 | for(auto i: M2){
15 | if(i.second > M1[i.first])
16 | cnt += i.second - M1[i.first];
17 | }
18 | if(cnt == 0){
19 | cout << "Yes " << s1.size() - s2.size() << endl;
20 | }else{
21 | cout << "No " << cnt << endl;
22 | }
23 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1093.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | const int MOD = 1000000007;
4 | int main(){
5 | string s;
6 | cin >> s;
7 | long long a = 0, b = 0, c = 0;
8 | for(int i = 0; i < s.size(); i++){
9 | if(s[i] == 'P'){
10 | a++;
11 | }else if(s[i] == 'A'){
12 | b += a;
13 | }else if(s[i] == 'T'){
14 | c += b;
15 | }
16 | }
17 | cout << c%MOD << endl;
18 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/1104.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(){
4 | int n;
5 | cin >> n;
6 | double sum = 0;
7 | for(int i = 0; i < n; i++){
8 | double x;
9 | cin >> x;
10 | sum += (i+1) * x * (n-i);
11 | }
12 | cout << fixed << setprecision(2) << sum << endl;
13 | }
--------------------------------------------------------------------------------
/JAL/PAT/Advanced/input.txt:
--------------------------------------------------------------------------------
1 | 7 3
2 | 07:55:00 16
3 | 17:00:01 2
4 | 07:59:59 15
5 | 08:01:00 60
6 | 08:00:00 30
7 | 08:00:02 2
8 | 08:03:00 10
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1001b.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | using ll = long long;
5 |
6 | int main() {
7 | ll x, step = 0;
8 | cin >> x;
9 | while (x > 1) {
10 | if (x & 1) {
11 | x = 3 * x + 1;
12 | } else {
13 | x >>= 1;
14 | ++step;
15 | }
16 | }
17 | cout << step << endl;
18 | return 0;
19 | }
20 |
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1028.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 | int N;
6 | cin >> N;
7 | string today("2014/09/06");
8 | vector> V(N);
9 | for (auto &v : V) {
10 | cin >> v.first >> v.second;
11 | }
12 | sort(V.begin(), V.end(),
13 | [today](pair a, vector b) {
14 |
15 | });
16 | return 0;
17 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1029.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main() {
4 | string a;
5 | string b;
6 | cin >> a >> b;
7 | transform(a.begin(), a.end(), a.begin(), ::toupper);
8 | transform(b.begin(), b.end(), b.begin(), ::toupper);
9 | map M;
10 | for (char c : a) {
11 | if (b.find(c) == string::npos) {
12 | if (!M[c]) {
13 | cout << c;
14 | M[c] = true;
15 | }
16 | }
17 | }
18 | cout << endl;
19 | return 0;
20 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1030.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | template
4 | T read(){
5 | T x;
6 | cin >> x;
7 | return x;
8 | }
9 | int main(){
10 | int n = read(), p = read();
11 | vectorv(n);
12 | for(auto &i: v){
13 | i = read();
14 | }
15 | sort(v.begin(), v.end());
16 | int best = 0;
17 | for(int i = 0; i < n; i++){
18 | int m = v[i];
19 | int j = upper_bound(v.begin(), v.end(), 1LL*m*p) - v.begin();
20 | best = max(best, j - i);
21 | }
22 | cout << best << endl;
23 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1036.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int a;
7 | char c;
8 | cin >> a >> c;
9 | int b = (a + 1) / 2;
10 | for (int i = 0; i < b; i++) {
11 | for (int j = 0; j < a; j++) {
12 | if (j == 0 || i == 0 || i == b - 1 || j == a - 1)
13 | cout << c;
14 | else
15 | cout << ' ';
16 | }
17 | cout << endl;
18 | }
19 |
20 | return 0;
21 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1038.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | int main() {
7 | int n;
8 | cin >> n;
9 | map M;
10 | while (n--) {
11 | int s;
12 | cin >> s;
13 | M[s]++;
14 | }
15 | int q;
16 | cin >> q;
17 | for (int i = 0; i < q; i++) {
18 | int s;
19 | cin >> s;
20 | if (i)cout << " ";
21 | cout << M[s];
22 | }
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1042.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main() {
4 | map M;
5 | for (char c; cin >> c; M[tolower(c)]++)
6 | ;
7 | char m = 'a';
8 | for (char c = 'b'; c <= 'z'; ++c) {
9 | if (M[c] > M[m]) m = c;
10 | }
11 |
12 | cout << m << " " << M[m] << endl;
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1086.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | using LL = long long;
4 |
5 | int main() {
6 | LL a, b;
7 | cin >> a >> b;
8 | LL c = a * b;
9 | LL d = 0;
10 | do {
11 | d = d * 10 + c % 10;
12 | c /= 10;
13 | } while (c > 0);
14 | cout << d << endl;
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1087.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | using LL = long long;
4 |
5 | int main() {
6 | set S;
7 | int n;
8 | cin >> n;
9 | for (int i = 1; i <= n; i++) {
10 | S.insert((i) / 2 + (i) / 3 + (i) / 5);
11 | }
12 | cout << S.size();
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1093.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main() {
4 | string a, b;
5 | getline(cin, a);
6 | getline(cin, b);
7 | a += b;
8 | string h;
9 | for (char c : a) {
10 | if (h.find(c) == string::npos) {
11 | cout << c;
12 | h.push_back(c);
13 | }
14 | }
15 |
16 | return 0;
17 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/1206.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main() {
4 | int a, b; cin >> a >> b;
5 | b -= a;
6 | b = (b + 50) / 100;
7 | int h, m, s;
8 | h = (b / 3600)%24;
9 | b %= 3600;
10 | m = b / 60;
11 | s = b % 60;
12 | cout << h << ":" << m << ":" << s << endl;
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/JAL/PAT/Medium/input.txt:
--------------------------------------------------------------------------------
1 | 4
2 | 320124198808240056
3 | 12010X198901011234
4 | 110108196711301866
5 | 37070419881216001X
--------------------------------------------------------------------------------
/JAL/PAT/Other/Z02.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | bool prime(int n) {
4 | if (n == 2) return true;
5 | if (n < 2 or n % 2 == 0) return false;
6 | for (int c = 3; c * c <= n; c += 2) {
7 | if (n % c == 0) return false;
8 | }
9 | return true;
10 | }
11 | int main() {
12 | int n;
13 | cin >> n;
14 | int tot(0);
15 | for (int i = 3; i + 2 <= n; i += 2) {
16 | if (prime(i) and prime(i + 2)) ++tot;
17 | }
18 | cout << tot << endl;
19 | return 0;
20 | }
--------------------------------------------------------------------------------
/JAL/PAT/Other/sstreamDemo.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 | int main() {
6 | int x = 123, y = 45;
7 | ostringstream oss;
8 | cout << x << y << " " << y << x << endl; // 12345 45123
9 | oss << x << y << " " << y << x;
10 | int a, b;
11 | istringstream iss(oss.str());
12 | iss >> a >> b;
13 | cout << "a=" << a << endl;
14 | cout << "b=" << b << endl;
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/JAL/usaco/P1200.cc:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int Hash(string s) {
6 | int ret = 1;
7 | for (auto c : s) ret = ret * (c - 'A' + 1) % 47;
8 | return ret;
9 | }
10 |
11 | int main() {
12 | string a, b;
13 | cin >> a >> b;
14 | if (Hash(a) == Hash(b)) {
15 | cout << "GO" << endl;
16 | } else {
17 | cout << "STAY" << endl;
18 | }
19 | return EXIT_SUCCESS;
20 | }
--------------------------------------------------------------------------------
/JAL/usaco/readme.md:
--------------------------------------------------------------------------------
1 | # usaco
2 | tst
3 | #test
4 |
--------------------------------------------------------------------------------
/JAL/wangyi/formal/A橡皮泥捏斑马.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by jal on 18-9-8.
3 | //
4 | #include
5 |
6 | using namespace std;
7 |
8 | int main() {
9 | string s;
10 | cin >> s;
11 | int w = 0, b = 0;
12 | for (auto c : s) {
13 | if (c == 'w') {
14 | w++;
15 | } else {
16 | b++;
17 | }
18 | }
19 | int t = min(w, b) * 2;
20 | if (s.size() > t)t++;
21 | cout << t << endl;
22 | }
--------------------------------------------------------------------------------
/JAL/wangyi/test/A俄罗斯方块.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by jal on 18-9-8.
3 | //
4 | #include
5 |
6 | using namespace std;
7 | int a[1001] = {0};
8 |
9 | int main() {
10 | int n, m;
11 | cin >> n >> m;
12 | int g = 0;
13 | for (int i = 0; i < m; i++) {
14 | int x;
15 | cin >> x;
16 | a[x]++;
17 | }
18 | cout << *min_element(a + 1, a + n + 1) << endl;
19 | }
20 |
--------------------------------------------------------------------------------
/NOIP/NOIP2000/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2000/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2001/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2001/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2002/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2002/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2003/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2003/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2004/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2004/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2005/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2005/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2006/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2006/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2007/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2007/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2008/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2008/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2009/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2009/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2010/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2010/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2011/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2011/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2012/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2012/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2013/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2013/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2014/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2014/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2015/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2015/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2016/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2016/outline.md
--------------------------------------------------------------------------------
/NOIP/NOIP2017/A_P3951_小凯的疑惑.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | typedef long long LL;
4 | int main() {
5 | LL a, b;
6 | cin >> a >> b;
7 | cout << a *b - a - b << endl;
8 | return 0;
9 | }
--------------------------------------------------------------------------------
/NOIP/NOIP2017/outline.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/NOIP2017/outline.md
--------------------------------------------------------------------------------
/NOIP/P1001A+B.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int a, b;
7 | cin >> a >> b;
8 | cout << a + b << endl;
9 | return EXIT_SUCCESS;
10 | }
--------------------------------------------------------------------------------
/NOIP/P1024一元三次方程.cc:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | double a, b, c, d;
4 | inline double f(double x) { return a * x * x * x + b * x * x + c * x + d; }
5 | int main(int argc, char const *argv[]) {
6 | cin >> a >> b >> c >> d;
7 | for (double x = -100; x <= 100; x += 0.01) {
8 | if (abs(f(x)) <= 1e-3) cout << fixed << setprecision(2) << x << " ";
9 | }
10 | cout << endl;
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/NOIP/P1421.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | const int M = 190;
7 | int a, b;
8 | cin >> a >> b;
9 | int N = 100 * a + b * 10;
10 | cout << N / M << endl;
11 |
12 | return 0;
13 | }
--------------------------------------------------------------------------------
/NOIP/ccf认证/Calculator-bobo.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/ccf认证/Calculator-bobo.cpp
--------------------------------------------------------------------------------
/NOIP/ccf认证/公共钥匙盒.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/ccf认证/公共钥匙盒.cpp
--------------------------------------------------------------------------------
/NOIP/ccf认证/图像旋转.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int arr[1000][1000];
5 |
6 | int main() {
7 | int n, m;
8 | cin >> n >> m;
9 |
10 |
11 | for (int i = 0; i < n; i++) {
12 | for (int j = 0; j < m; j++)
13 | cin >> arr[i][j];
14 | }
15 |
16 | for (int j = m - 1; j >= 0; j--) {
17 | for (int i = 0; i < n; i++)
18 | cout << arr[i][j] << " ";
19 | cout << endl;
20 | }
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/NOIP/ccf认证/学生排队.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/ccf认证/学生排队.cpp
--------------------------------------------------------------------------------
/NOIP/ccf认证/小球碰撞.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/ccf认证/小球碰撞.cpp
--------------------------------------------------------------------------------
/NOIP/ccf认证/游戏.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webturing/cplusplus/6b9c671b0c9a7c0d24d937610bf54e9aec9a5a1f/NOIP/ccf认证/游戏.cpp
--------------------------------------------------------------------------------
/NOIP/ccf认证/相反数.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int n;
7 | cin >> n;
8 | int arr[n];
9 | for (int i = 0; i < n; i++)
10 | cin >> arr[i];
11 |
12 | int cnt = 0;
13 | for (int i = 0; i < n; i++) {
14 | for (int j = i + 1; j < n; j++) {
15 | if (arr[i] == -arr[j]) {
16 | cnt++;
17 | //arr[j]=arr[i];
18 | }
19 | }
20 | }
21 | cout << cnt;
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/NOIP/input.txt:
--------------------------------------------------------------------------------
1 | 5
2 | at
3 | touch
4 | cheat
5 | choose
6 | tact
7 | a
8 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/100003.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | typedef unsigned long long LL;
5 |
6 | int main() {
7 | std::ios::sync_with_stdio(false);
8 | std::cin.tie(0);
9 | vector f(31, 1);
10 | for (int i = 2; i < f.size(); i++)
11 | f[i] = f[i - 1] + f[i - 2];
12 | int n;
13 | cin >> n;
14 | cout << f[n] << endl;
15 |
16 |
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/100007.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | int n, k, f[2][100];//f[1][i]保存第i位不为0的方案数
5 |
6 | int main() {
7 | std::ios::sync_with_stdio(false);
8 | std::cin.tie(0);
9 | cin >> n >> k; //非0的k进制数有k-1种
10 | k--;
11 | f[1][0] = 1; //预处理第0位
12 | for (int i = 1; i <= n; i++) {
13 | f[0][i] = f[1][i - 1];
14 | f[1][i] = k * (f[0][i - 1] + f[1][i - 1]);
15 | }
16 | cout << f[1][n] << endl;
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1001F2C.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | double f;
5 | cin >> f;
6 | double c = (f - 32) / 9 * 5;
7 | cout << fixed << setprecision(4) << c << endl;
8 | return 0;
9 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1002TriangleArea.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main(int argc, char const *argv[]) {
4 | double a, b, c;
5 | cin >> a >> b >> c;
6 | double s = (a + b + c) / 2;
7 | double area = sqrt(s * (s - a) * (s - b) * (s - c));
8 | cout << fixed << setprecision(4) << area << endl;
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1003GuessNumber.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int x;
7 | cin >> x;
8 | int y = x * 1000 + x;
9 | cout << y / 7 / 11 / 13 << endl;
10 | return 0;
11 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1004FillRectangles.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | // ifstream cin("sample.out");
7 | int n, m, a;
8 | while (cin >> n >> m >> a)
9 | cout << 1LL * (n / a) * (m / a) << endl;
10 | // cin.close();
11 | return 0;
12 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1005SavingIncome.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | double r, x, p;
7 | cin >> r >> x >> p;
8 | double y = x * pow((100 + r) / 100, p);
9 | cout << setiosflags(ios::fixed) << setprecision(2) << y << endl;
10 | return 0;
11 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1006Pick20Stone.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | int a, b, c;
7 | cin >> a >> b >> c;
8 | cout << 20 - a - b - c << endl;
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1007FloatMod.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | double a, b;
7 | cin >> a >> b;
8 | cout << setiosflags(ios::fixed) << setprecision(2) << fmod(a, b) << endl;
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1008Daffodil2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 | int main() {
4 | int x;
5 | cin >> x;
6 | if (x == 153 || x == 371 || x == 370 || x == 407) {
7 | cout << "YES" << endl;
8 | } else {
9 | cout << "NO" << endl;
10 | }
11 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1008daffodil.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int flowers[] = {153, 371, 370, 407};
7 | int n = sizeof(flowers) / sizeof(flowers[0]);
8 | int x;
9 | cin >> x;
10 | if (find(flowers, flowers + n, x) != flowers + n) {
11 | cout << "YES" << endl;
12 | } else {
13 | cout << "NO" << endl;
14 | }
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1009AssignMission.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int boy, girl;
7 | cin >> boy >> girl;
8 | if (boy + girl < 10)
9 | cout << "water" << endl;
10 | else if (boy > girl)
11 | cout << "tree" << endl;
12 | else
13 | cout << "tea" << endl;
14 | return 0;
15 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1011Square.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 |
7 | double x, y;
8 | cin >> x >> y;
9 | if (fabs(x) <= 1 && fabs(y) <= 1) {
10 | cout << "Yes" << endl;
11 | } else {
12 | cout << "No" << endl;
13 | }
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1012TransformCode.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | int n;
7 | cin >> n;
8 | int t = n % 123;
9 | if (t >= 97)
10 | cout << (char) t << endl;
11 | else {
12 | t = n % 91;
13 | if (t >= 65)
14 | cout << (char) t << endl;
15 | else
16 | cout << "*" << endl;
17 | }
18 |
19 |
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1014WriteComments.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main() {
6 | int score;
7 | cin >> score;
8 | if (score < 60) {
9 | cout << "Fail" << endl;
10 | } else if (score < 80) {
11 | cout << "Pass" << endl;
12 | } else if (score < 90) {
13 | cout << "Good" << endl;
14 | } else {
15 | cout << "Excellent" << endl;
16 | }
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1015WhatDay.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | vector week(8);
7 | week[1] = "Monday";
8 | week[2] = "Tuesday";
9 | week[3] = "Wednesday";
10 | week[4] = "Thursday";
11 | week[5] = "Friday";
12 | week[6] = "Saturday";
13 | week[7] = "Sunday";
14 | int d;
15 | cin >> d;
16 | cout << week[d] << endl;
17 |
18 | return 0;
19 | }
20 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1018Telephone.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | double findTime(double c) {
7 | if (c == 0.5)
8 | return 3;
9 | return (c - 0.5) / 0.2 + 3;
10 | }
11 |
12 | int main(int argc, char const *argv[]) {
13 | double x;
14 | cin >> x;
15 | cout << findTime(x) << endl;
16 |
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1019SegmentFunction.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | double f(double x) {
7 | if (x < 5)return x + 2.5;
8 | if (x < 10)return 2 - 1.5 * (x - 3) * (x - 3);
9 | return x / 2 - 1.5;
10 | }
11 |
12 | int main(int argc, char const *argv[]) {
13 | double x;
14 | cin >> x;
15 | cout << setiosflags(ios::fixed) << setprecision(3) << f(x) << endl;
16 |
17 | return 0;
18 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1020RecognizeNumber.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 |
6 | int main(int argc, char const *argv[]) {
7 | string s;
8 | cin >> s;
9 | cout << s.length() << endl;
10 | for (auto i = s.begin(); i != s.end(); ++i)
11 | cout << *i << endl;
12 |
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1022AverageAge.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | int n;
7 | cin >> n;
8 | vector v(n);
9 | for (auto &i:v)cin >> i;
10 | cout << setiosflags(ios::fixed) << setprecision(2) << 1.0 * accumulate(v.begin(), v.end(), 0) / v.size() << endl;
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1023MaxGap.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | int n;
7 | cin >> n;
8 | vector v(n);
9 | for (auto &i:v)cin >> i;
10 | sort(v.begin(), v.end());
11 | cout << v[v.size() - 1] - v[0] << endl;
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1024CountDivisors.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | unsigned n;
7 | cin >> n;
8 | int tot = 0, t = 1, m = sqrt(n);
9 | for (; t <= m; t++)//O(sqrt(n))
10 | if (n % t == 0)
11 | tot += 2;
12 | if (m * m == n)
13 | --tot;
14 | cout << tot << endl;
15 |
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/NOIP/oj.noi.cn/1026PerformanceRating.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 |
5 | int main(int argc, char const *argv[]) {
6 | vector v((istream_iterator(cin)), istream_iterator