賽前最後給自己一點建議
阿新 • • 發佈:2021-10-21
#include <cstdio> #include <algorithm> #include <ctime> #include <set> using namespace std; int a[11], b[11], c[11]; int main(){ // 檔案對比 /*while (1){ if (system("fc print1.txt print2.txt")) break; }*/ // 隨機數 /*srand(time(0)); int n = rand() % 10000; printf("%d\n", n);*/ // 讀寫 /*freopen("csp2021.in", "r", stdin); freopen("csp2021.out", "w", stdout);*/ // 離散化 /*a[1] = 10, a[2] = 9, a[3] = 15, a[4] = 1, a[5] = 15; c[1] = 10, c[2] = 9, c[3] = 15, c[4] = 1, a[5] = 15; sort(a + 1, a + 5 + 1); int len = unique(a + 1, a + 5 + 1) - a - 1; for (int i = 1; i <= len; ++i) b[i] = lower_bound(a + 1, a + len + 1, c[i]) - a; for (int i = 1; i <= len; ++i) printf("%d ", b[i]); // 3 2 4 1 */ // set (不可重複) multiset (可重複) // 插入 -> insert 刪除 -> erase set<int> s1; // 0 1 2 3 4 5 s1.insert(10), s1.insert(5), s1.insert(77), s1.insert(7), s1.insert(8), s1.insert(7777777); s1.erase(5); printf("%d\n", *s1.find(777)); printf("%d\n", *s1.lower_bound(8));// >= x 的最小的一個 printf("%d\n", *s1.end()); printf("%d\n", *s1.upper_bound(4));// > x 的最小的一個 // next_permutation /*for (int i = 1; i <= 4; ++i) a[i] = i; do { for (int i = 1; i <= 4; ++i) printf("%d ", a[i]); puts(""); } while (next_permutation(a + 1, a + 5));*/ return 0; }