diff --git a/Google C++ Style Guide.pdf b/Google C++ Style Guide.pdf deleted file mode 100644 index 08f0ea2..0000000 Binary files a/Google C++ Style Guide.pdf and /dev/null differ diff --git a/HANDS-ON.txt b/HANDS-ON.txt deleted file mode 100644 index 94d9e4c..0000000 --- a/HANDS-ON.txt +++ /dev/null @@ -1,593 +0,0 @@ -----------------------2022.2.7------------------------ - -x x --> y x -y y y x - -y y --> y x -x x y x - -x y --> x x --> y x -y x y y y x - -/* 先分别统计这两对字符串中这两种格式的对儿 有多少 */ -/* 然后如果 的数量和 的数量之和是奇数,则直接返回 -1 */ -/* 否则如果每个都是偶数,则返回和的一半。如果每个都是奇数,则返回和的一半 + 1 */ - -/* 构造测试样例: -* s1 = "xxx", s2 = "yyy", answer = -1. -* s1 = "xyyx", s2 = "yxxy", answer = 2. -*/ - -#include - -class Solution { -public: - int minimumSwap(string s1, string s2) { - int cnt1 = 0, cnt2 = 0; - int len = s1.size(); /* len = 4 */ - for (int i = 0; i < len; i++) { - if (s1[i] == 'x' && s2[i] == 'y') cnt1++; - else if (s1[i] == 'y' && s2[i] == 'x') cnt2++; - else {}; - }; /* cnt1 = 2, cnt2 = 2 */ - int ans = (cnt1 + cnt2) & 1 ? -1 : ((cnt1 + cnt2) >> 1) + (cnt1 & 1); - return ans; /* ans = 2 */ - }; -}; - - - - - -/* 先统计出所有的奇数数字的位置,然后以 k 为大小的滑动窗口去遍历 -* 这样就能算出恰好含有 k 个奇数数字的 “极小” 子数组,然后再去看两侧奇数的位置,相乘就可以算出含有部分 “多余偶数” 的数组有多少个 -*/ - -/* 测试用例, nums = <1 1 2 1 1>, k = 2, ans = 5 */ -/* 时间复杂度: O(N), 空间复杂度: O(N) */ - -#include - -using namespace std; - -class Solution{ -public: - int numberOfSubarrays(vector& nums, int k ){ - /* nums: 1 1 2 1 1 */ - int len = nums.size(); - vector v; v.push_back(-1); - for (int i = 0; i < len; i++) - if (nums[i] & 1) { - v.push_back(i); - }; - v.push_back(len); - /* v: -1 0 1 3 4 5 */ - int ans = 0; - for (int start = 1; start < v.size(); start++) { - int end = start + k - 1; - if (end >= v.size() - 1) break; - else ans += (v[start] - v[start - 1]) * (v[end + 1] - v[end]); /* ans += 2 += 1 += 2 = 5 */ - }; - return ans; - }; -}; - - - - - - - - -/* 我们使用栈把字符串中的括号依次压栈,每次压栈的规则是 -* 如果栈为空,则直接压栈。如果栈顶元素是左括号,且当前元素是右括号,刚好匹配,则探出栈顶元素且不压栈当前元素。否则,将当前元素压栈。最后的栈内所有元素就是要被移除的括号。 -* 每次压栈时需要记录位置信息,以便后续删除对应字符串中的括号来获得新的合法字符串。 -* 因此,可以压栈一个数字,如果是左括号则用负号,右括号则用正号,下标从 1 开始。 -*/ - -/* 测试用例: s = "(d)(f))", ans = 1 */ -/* 时间复杂度: O(N), 空间复杂度: O(N) */ - -#include - -class Solution{ -public: - string minRemoveToMakeValid(string s){ - stack ele; - for (int i = 0; i < s.size(); i++) - if (s[i] == '(') ele.push(-(i + 1)); - else if (s[i] == ')') { - if (ele.empty()) ele.push(i + 1); - else if (ele.top() < 0) ele.pop(); - else ele.push(i + 1); - } else {}; - string ans = ""; - int cur_idx = s.size(); - - while (!ele.empty()) { - int last_idx = abs(ele.top()) - 1; - ele.pop(); - ans = s.substr(last_idx + 1, cur_idx - last_idx - 1) + ans; - cur_idx = last_idx; - }; - ans = s.substr(0, cur_idx - 0) + ans; - /*for (int i = s.size() - 1; i >= 0; i--) { - if (!ele.empty() && abs(ele.top()) - 1 == i) { - ele.pop(); - } else { - ans = s[i] + ans; - }; - };*/ - return ans; - }; -}; - - - -/* 查看了维基百科 <裴蜀定理> */ -/* 当且仅当 m 是 a, b 的最大公约数的倍数,ax + by = m 才有解, 此题中 m = 1,因此就是判断 a 和 b 互质 */ - -class Solution{ -public: - int gcd(int a, int b) { - return a == 0 ? b : gcd(b % a, a); - }; - bool isGoodArray(vector& nums) { - int a = nums[0]; - for (auto num: nums) - a = gcd(a, num); - return a == 1; - }; -}; - - ------------------------2022.2.8----------------------------- - - -/* 遍历原来数组,每次将奇数位上的数量的偶数位上的值压入结果数组,返回即可 */ -/* 测试用例:v = {1 3 2 4 5 2}, ans = {3 4 4 2 2 2 2 2} */ -/* 时间复杂度:O(N * max(nums)) 空间复杂度:O(N * max(nums)) */ - -#include - -using namespace std; - -class Solution{ -public: - vector decompressRLElist(vector& nums){ - vector ans; - int len = nums.size(); - for (int i = 0; i < len; i += 2) { - for (int j = 0; j < nums[i]; j++) { - ans.push_back(nums[i + 1]); - }; - }; - return ans; - }; -}; - - -/* 前缀和思想:按行求出前缀和,计算每个元素的时候都根据前缀和按行求出的总和即可 */ -/* 测试用例:mat = { 1 2 3 k = 1, ans = { 12, 21, 16 - 4 5 6 27, 45, 33 - 7 8 9 } 24, 39, 28} -*/ -/* 时间复杂度:O(m * n) 空间复杂度:O(m * n) */ - -#include - -using namespace std; - -class Solution{ -public: - vector> matrixBlockSum(vector>& mat, int k) { - int m = mat.size(), n = mat[0].size(); /* m = 3, n = 3 */ - vector> prefix(m, vector(n, 0)); - /* prefix = { 1 3 6 - 5 12 21 - 12 27 45 } - */ - for (int i = 0; i < m; i++) { - for (int j = 0; j < n; j++) { - if (i == 0 && j == 0) prefix[i][j] = mat[i][j]; - else if (i == 0) prefix[i][j] = prefix[i][j - 1] + mat[i][j]; - else if (j == 0) prefix[i][j] = prefix[i - 1][j] + mat[i][j]; - else prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] + mat[i][j]; - }; - }; - vector> answer(m, vector(n, 0)); - /* top_row = 0 - down_row = 1 - left_col = 1 - right_col = 2 - answer = { 12 21 - */ - for (int i = 0; i < m; i++) - for (int j = 0; j < n; j++) { - int top_row = max(0, i - k), down_row = min(m - 1, i + k); - int left_col = max(0, j - k), right_col = min(n - 1, j + k); - if (top_row == 0 && left_col == 0) answer[i][j] = prefix[down_row][right_col]; - else if (top_row == 0) answer[i][j] = prefix[down_row][right_col] - prefix[down_row][left_col - 1]; - else if (left_col == 0) answer[i][j] = prefix[down_row][right_col] - prefix[top_row - 1][right_col]; - else answer[i][j] = prefix[down_row][right_col] - prefix[top_row - 1][right_col] - prefix[down_row][left_col - 1] + prefix[top_row - 1][left_col - 1]; - }; - return answer; - }; -}; - - -/* 二叉树用数组表示,父节点的下标和子节点的下标的关系 - 0 - 1 2 - 3 4 5 6 -7 8 9 10 11 12 13 14 - -fathers[x] = (x - 1) / 2; -*/ -/* 时间复杂度:O(N), 空间复杂度:O(N) */ - -#include - -using namespace std; - -class Solution{ -public: - void dfs1(TreeNode* cur, TreeNode* fa, unordered_map& father) { - if (cur == NULL) return; - father[cur] = fa; - dfs1(cur->left, cur, father); - dfs1(cur->right, cur, father); - }; - bool OK(TreeNode* cur, unordered_map& father) { - if (cur == NULL || father[cur] == NULL || father[father[cur]] == NULL || (father[father[cur]]->val & 1) != 0) return false; - else return true; - }; - int dfs2(TreeNode* root, unordered_map& father) { - if (root == NULL) return 0; - return (OK(root, father) ? root->val : 0) + dfs2(root->left, father) + dfs2(root->right, father); - }; - int sumEvenGrandparent(TreeNode* root) { - /* 遍历一遍将值存储在数组中 */ - unordered_map father; - dfs1(root, NULL, father); - return dfs2(root, father); - }; -}; - - - - - - - - - -/* 遍历每个子字符串,然后判断随后截取长度相同的子字符串是否与当前子字符串相等即可,*/ -/* 时间复杂度:O(N^2),空间复杂度:O(1) */ -/* 测试用例:text = "aabcaabc" ans = 3 */ - -#include -#include -#include -#include - -using LL = long long; -using namespace std; - -class Solution{ -public: - const int mod = 1e9 + 7; - int getHash(const vector& pre, const vector& mul, int l, int r) { - return (pre[r + 1] - (LL)pre[l] * mul[r - l + 1] % mod + mod) % mod; - }; - int distinctEchoSubstrings(string text) { - int len = text.size(), k = 29; - vector prefix(len + 1, 0), mul(len + 1, 0); - prefix[0] = 0; - mul[0] = 1; - for (int i = 1; i <= len; i++) - { - prefix[i] = ((LL)prefix[i - 1] * k + text[i - 1]) % mod; - mul[i] = (LL)mul[i - 1] * k % mod; - }; - unordered_set seen[len]; - int ans = 0; - for (int i = 0; i < len; i++) { - for (int j = i + 1; j < len; j++) { - int l = j - i; - if (j + l <= len) { - int hash_left = getHash(prefix, mul, i, j - 1); - if (!seen[l - 1].count(hash_left) && hash_left == getHash(prefix, mul, j, j + l - 1)) { - ++ans; - seen[l - 1].insert(hash_left); - }; - }; - }; - } - return ans; - }; -}; - - - ---------------------------2022.2.9----------------------------- - -/* 遍历整个数组,将所有偶数和奇数元素分别取出成为单独的数组,然后再进行拼接即可 */ -/* 测试用例:nums = {2,1,4,3} */ -/* 时间复杂度:O(N),空间复杂度:O(N) */ - -#include - -using namespace std; - -class Solution { -public: - vector sortArrayByParity(vector& nums) { - vector odds, evens, ans; - /* odds = {1, 3} evens = {2, 4} */ - for (auto& num : nums) - if (num & 1) odds.push_back(num); - else evens.push_back(num); - for (auto &num : evens) - ans.push_back(num); // ans = {2, 4} - for (auto &num : odds) - ans.push_back(num); // ans = {2, 4, 1, 3} - return ans; - }; -}; - -/* 动态规划,遍历整个数组,用两个变量记录当前篮子里水果的位置信息并不断更新,直到遇到一个水果和这两个都不相同,那么就需要把位置信息最小的那个水果替换掉 -* 同时维持一个 tot 来记录当前收集的这两种水果的最大数目。 -* 特殊考虑成环,需要重复这个数组的遍历 -*/ - -/* 测试用例:fruits = [0, 0, 1, 1] ans = 4 */ -/* 时间复杂度:O(N), 空间复杂度:O(1) */ - -#include - -using namespace std; - -class Solution{ -public: - int totalFruit(vector& fruits){ - int end1 = -1, end2 = -1, start1 = -1, start2 = -1, tot1 = 0, tot2 = 0, ans = 0; - for (int i = 0; i < fruits.size(); i++) { - // tot1 = 2 - // tot2 = 0 - // start1 = 0 - // end1 = 1 - // start2 = 2 - // end2 = 2 - // ans = 2 - if (end1 >= 0 && fruits[i] == fruits[end1]) { - tot1++; - end1 = i; - } else if (end2 >= 0 && fruits[i] == fruits[end2]) { - tot2++; - end2 = i; - } else if (end1 <= end2) { - tot1 = 1; - tot2 = i - end1 - 1; - start1 = end1 = i; - } else { - tot2 = 1; - tot1 = i - end2 - 1; - start2 = end2 = i; - }; - ans = max(ans, tot1 + tot2); - }; - return ans; - }; -}; - - -/* 二分法,将 arr 分成两个子数组,然后分别求解他们的 min(b) 的总和再相加,中间每次处理都需要 NlogN 的时间,*/ -/* 时间复杂度:O(NlogNlogN),空间复杂度 O(NlogN) */ -/* 测试用例:arr = {3,1,2,4} ans = 17 */ - -#include -#include - -using LL = long long; -using namespace std; - -class Solution{ -public: - const int mod = (int)1e9 + 7; - int _sumSubarrayMins(vector& arr, int left, int right, int dir, vector& m) { - if (left == right) { - m.push_back(arr[left]); - return arr[left]; - }; - - int mid = (left + right) >> 1; - vector m1, m2; - int tot = ((LL)_sumSubarrayMins(arr, left, mid, 1, m1) + (LL)_sumSubarrayMins(arr, mid + 1, right, 0, m2)) % mod; - int len1 = m1.size(), len2 = m2.size(); - vector prefix1(len1 + 1, 0), prefix2(len2 + 1, 0); - for (int i = 0; i < len1; i++) prefix1[i + 1] = prefix1[i] + m1[i]; - for (int i = 0; i < len2; i++) prefix2[i + 1] = prefix2[i] + m2[i]; - for (int i = 0; i < len1; i++) { - int idx = upper_bound(m2.begin(), m2.end(), m1[i]) - m2.begin(); - tot = ((LL)tot + (LL)(len2 - idx) * (LL)m1[i] + (LL)prefix2[idx]) % mod; - }; - if (dir == 0) /* 原数组右侧 */ { - m.push_back(arr[left]); - for (int i = left + 1; i <= right; i++) - m.push_back(min(m.back(), arr[i])); - } else { - m.push_back(arr[right]); - for (int i = right - 1; i >= left; i--) - m.push_back(min(m.back(), arr[i])); - }; - sort(m.begin(), m.end()); - return tot; - }; - int sumSubarrayMins(vector& arr) { - vector m; - return _sumSubarrayMins(arr, 0, arr.size() - 1, 0, m); - }; -}; - - -/* 构造回文数,计算它的平方,如果在范围内且也是回文数则记录在数组中 */ - -#include -#include -#include -#include - -using namespace std; - -class Solution { -public: - int64_t reverse_int(int64_t x) { - int64_t ans = 0; - while (x > 0) { - ans = 10 * ans + x % 10; - x /= 10; - }; - return ans; - }; - bool judge(int64_t x) { - return x == reverse_int(x); - }; - int superpalindromesInRange(string left, string right) { - int n = 100000, UP = (int)1e9 + 7; - int64_t l = stoll(left), r = stoll(right), cnt = 0; - for (int i = 1; i < n; i++) { - string ori = to_string(i); - string rev = ori; reverse(rev.begin(), rev.end()); - string str1 = ori + rev; - int64_t num1 = stoll(str1); - if (num1 < UP) { - num1 = num1 * num1; - if (l <= num1 && num1 <= r) cnt += judge(num1); - else if (l > r) break; - } else break; - }; - for (int i = 1; i < n; i++) { - string ori = to_string(i); - string rev = ori; reverse(rev.begin(), rev.end()); - string str2 = ori.substr(0, ori.size() - 1) + rev; - int64_t num2 = stoll(str2); - if (num2 < UP) { - num2 = num2 * num2; - if (l <= num2 && num2 <= r) cnt += judge(num2); - else if (l > r) break; - } else break; - }; - return cnt; - }; -}; - - - ---------------------2022.2.10---------------------------- - -/* 遍历两边字符串,分别统计1和0连续出现的最长长度,比较即可 */ -/* 时间复杂度:O(N),空间复杂度:O(1) */ -/* 测试用例: 100011 */ - -using namespace std; - -class Solution{ -public: - bool checkZeroOnes(string s){ - int len = s.size(), MAX1 = 0, MAX2 = 0; // len = 6, MAX1 = 0, MAX2 = 0 - int tmp1 = s[0] == '1', tmp2 = s[0] == '0'; // tmp1 = 1, tmp2 = 0 - for (int i = 1; i < len; i++) { - /* - i = 1, tmp1 = 0, tmp2 = 1, MAX1 = 1, MAX2 = 1 - i = 2, tmp1 = 0, tmp2 = 2, MAX1 = 1, MAX2 = 2 - i = 3, tmp1 = 0, tmp2 = 3, MAX1 = 1, MAX2 = 3 - i = 4, tmp1 = 1, tmp2 = 0, MAX1 = 1, MAX2 = 3 - i = 5, tmp1 = 2, tmp2 = 0, MAX1 = 2, MAX2 = 3 - */ - MAX1 = max(MAX1, tmp1); - MAX2 = max(MAX2, tmp2); - if (s[i] == '1') { - tmp1++; - tmp2 = 0; - } else { - tmp2++; - tmp1 = 0; - }; - }; - MAX1 = max(MAX1, tmp1); - MAX2 = max(MAX2, tmp2); - return MAX1 > MAX2; // 2 > 3 = false - }; -}; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/POJ/01A.cpp b/POJ/01A.cpp deleted file mode 100644 index 80c54e8..0000000 --- a/POJ/01A.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include -//ɸ -using namespace std; - -const long long N = 1e5; - -bool sieve[N]; - -int prime[100010]; - -void linear_sieve() -{ - int prime_xb = -1; - - for (int i = 2; i < N; i++) - { - if (!sieve[i]) prime[++prime_xb] = i; // - - for (int j = 0; i * prime[j] < N; j++) - { - sieve[i * prime[j]] = true; //ȥ - - if (i % prime[j] == 0) break; - } - } - //for (int i = 0; i <= prime_xb; i++) - //cout << prime[i] << " "; -} - -bool is(int x) -{ - if (sieve[x] == true) return false; - - int tmp[8], tmp_xb = 0; - while(x > 0) - { - tmp[++tmp_xb] = x % 10; - x /= 10; - } - - int y = 0; - for (int i = 1; i <= tmp_xb; i++) - y = y * 10 + tmp[i]; - if (sieve[y] == true) return false; - - return true; -} - -int main() -{ - memset(prime, 0, sizeof(prime)); - linear_sieve(); - - int M, N; cin >> M >> N; - - int i; - bool flag = true; - - for (i = M; i <= N; i++) - if (is(i)) { cout << i; flag = false; break;}; - - for (i++; i <= N; i++) - if (is(i)) { cout << "," << i; flag = false;}; - - if (flag) cout << "No"; - return 0; -} diff --git a/POJ/01B.cpp b/POJ/01B.cpp deleted file mode 100644 index 32d2d3d..0000000 --- a/POJ/01B.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include - -using namespace std; - -bool is(int x, int y) -{ - int m; - while(y) - { - m = x % y; - x = y; - y = m; - } - return x == 1; -} - -int main() -{ - int N, A, B; cin >> N >> A >> B; - double top = double(A) / B; - - double MAX = 0.0, tmp; - int t, b; - for (int i = N; i > 1; i--) - { - for (int j = i - 1; j > 0; j--) - if (is(i, j) && double(j) / i < top) - { - tmp = double(j) / i; - if (tmp > MAX) - { - MAX = tmp; - t = j; - b = i; - } - break; - } - } - - cout << t << " " << b; - - return 0; -} diff --git a/POJ/01D.cpp b/POJ/01D.cpp deleted file mode 100644 index f50cc54..0000000 --- a/POJ/01D.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -using namespace std; - -const int N = 2000; -const int Inf = 1e9; - -int A[110][N]; - -int main() -{ - int t; scanf("%d", &t); - - while(t--) - { - int n; scanf("%d", &n); - - for (int i = 0; i < 110; i++) - { - if (i == 0) - for (int j = 0; j < N; j++) - A[i][j] = 0; - else - for (int j = 0; j < N; j++) - A[i][j] = Inf; - } - - int m, B, P; - for (int i = 1; i <= n; i++) - { - scanf("%d", &m); - for (int j = 1; j <= m; j++) - { - scanf("%d%d", &B, &P); - for (int k = 1; k < N; k++) - { - if (k <= B) A[i][k] = min(A[i][k], A[i - 1][k] + P); - else A[i][B] = min(A[i][B], A[i - 1][B] + P); - } - } - } - - double MAX = 0.0; - for (int i = 1; i < N; i++) - MAX = max(MAX, double(i) / A[n][i]); - - printf("%.3f\n", MAX); - } - return 0; -} diff --git a/POJ/4326.cpp b/POJ/4326.cpp deleted file mode 100644 index 2df6725..0000000 --- a/POJ/4326.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -using namespace std; -struct node -{ - int ci; //Ǯ - int Ti; // -}; -int A[500020]; // -long long int B[500020]; //ǰ -node C[30]; //ŻƱ -bool myCompare(node A, node B){return A.ci < B.ci;}; - -int main() -{ - int n, m, k; cin >> n >> m >> k; - int i, j, s; - A[0] = B[0] = C[0].ci = C[0].Ti = 0; - - for (i = 1; i <= n; i++) - {scanf("%d",&A[i]); B[i] = i * k;}; - for (i = 1; i <= m; i++) - scanf("%d%d", &C[i].Ti, &C[i].ci); - - sort(C + 1, C + m + 1, myCompare); - - for (i = 1; i <= n; i++) - { - for (j = 1; j <= m; j++) - { - for (s = i - 1; s > 0 && A[i] - A[s] < C[j].Ti; s--); - B[i] = min(B[i], C[j].ci + B[s]); - } - B[i] = min(B[i], B[i - 1] + k); - } - cout << B[n]; - - return 0; -} diff --git a/POJ/4327.cpp b/POJ/4327.cpp deleted file mode 100644 index 082ceb0..0000000 --- a/POJ/4327.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include -//еa,bٽͬa,bкϲٽ̰㷨䣻ÿ㿴һ㣻 -using namespace std; - -int n, m; -int MIN; - -struct data -{ - double x; - double y; - int label; -}; -data D[20]; - -struct ABxy -{ - double a; - double b; - int n1; //Aеڼγɵ - int n2; -}; -ABxy B[2000]; //ab -int b_xb; - -int a, b; -void cal(double x1, double x2, double y1, double y2) -{ - a = (x2 * y1 - x1 * y2) / (x1 * x2 * (x1 - x2)); - b = (x2 * x2 * y1 - x1 * x1 * y2) / (x1 * x2 * (x2 - x1)) ; -} -bool myCompare(ABxy A, ABxy B) -{ - if (A.a == B.a) return A.b < B.b; - return A.a < B.a; -} - -int FINAL[2000][20]; int f_xb; - -int FF[20]; - -void Dfs(int x, int y, int total) -{ - if (total == n) { MIN = min(MIN, total); return;} - - for (int i = 1; i <= n; i++) - if (FINAL[x][i]) FF[FINAL[x][i]] = -1; - for (int i = x; i <= f_xb; i++) - - for (int i = 1; i <= n; i++) - if (FINAL[x][i] == -1) FF[FINAL[x][i]] = 0; - return; -} - -int main() -{ - int T; cin >> T; - - - cin >> n >> m; - b_xb = 0; f_xb = 1; MIN = 1e9; - memset(FINAL, 0, sizeof(FINAL)); - memset(FF, 0, sizeof(FF)); - - for (int i = 1; i <= T; i++) - { - for (int j = 1; j <= n; j++) - { - cin >> D[j].x >> D[j].y; - D[j].label = j; - } - - for (int j = 1; j <= n; j++) - for (int k = j + 1; k <= n; k++) - { - ++b_xb; - cal(D[j].x, D[k].x, D[j].y, D[k].y); - B[b_xb].a = a; B[b_xb].b = b; - B[b_xb].n1 = j; B[b_xb].n2 = k; - } - - sort(B + 1, B + b_xb + 1, myCompare); - - FINAL[1][B[1].n1] = FINAL[1][B[1].n2] = 1; - for (int j = 2; j <= b_xb; j++) - { - if (B[j].a != B[j - 1].a || B[j].b != B[j - 1].b) ++f_xb; - - FINAL[f_xb][B[j].n1] = FINAL[f_xb][B[j].n2] = 1; - } //FINAL[i][j]ia,bֵǷܹǵj - - - } -} diff --git a/POJ/OPJ_01C.cpp b/POJ/OPJ_01C.cpp deleted file mode 100644 index bd7754f..0000000 --- a/POJ/OPJ_01C.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; - -int A[10][10]; -int B[10][10]; - -int T[10]; - -int main() -{ - int R, C; R = 5, C = 6; - - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - memset(T, 0, sizeof(T)); - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - scanf("%d", &A[i][j]); - - B[1][1] = -1; - for (int i = 1; i <= 64; i++) - { - B[1][1]++; - for (int k = 1; k <= C; k++) - if (B[1][k] == 2) {B[1][k] = 0; B[1][k + 1]++;} - else break; - - for (int j = 1; j <= R; j++) - { - for (int k = 1; k <= C; k++) - B[j + 1][k] = (A[j][k] + B[j - 1][k] + B[j][k - 1] + B[j][k + 1] + B[j][k]) % 2; - } - - int s; - for (s = 1; s <= C && B[R + 1][s] == 0; s++); - if (s > C) - { - for (int j = 1; j <= R; j++) - { - for (int k = 1; k <= C; k++) - printf("%d ", B[j][k]); - printf("\n"); - } - break; - } - } - - return 0; -} diff --git a/POJ/OPJ_01F.cpp b/POJ/OPJ_01F.cpp deleted file mode 100644 index bd7754f..0000000 --- a/POJ/OPJ_01F.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; - -int A[10][10]; -int B[10][10]; - -int T[10]; - -int main() -{ - int R, C; R = 5, C = 6; - - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - memset(T, 0, sizeof(T)); - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - scanf("%d", &A[i][j]); - - B[1][1] = -1; - for (int i = 1; i <= 64; i++) - { - B[1][1]++; - for (int k = 1; k <= C; k++) - if (B[1][k] == 2) {B[1][k] = 0; B[1][k + 1]++;} - else break; - - for (int j = 1; j <= R; j++) - { - for (int k = 1; k <= C; k++) - B[j + 1][k] = (A[j][k] + B[j - 1][k] + B[j][k - 1] + B[j][k + 1] + B[j][k]) % 2; - } - - int s; - for (s = 1; s <= C && B[R + 1][s] == 0; s++); - if (s > C) - { - for (int j = 1; j <= R; j++) - { - for (int k = 1; k <= C; k++) - printf("%d ", B[j][k]); - printf("\n"); - } - break; - } - } - - return 0; -} diff --git a/POJ/OPJ_02A.cpp b/POJ/OPJ_02A.cpp deleted file mode 100644 index cc7f9f3..0000000 --- a/POJ/OPJ_02A.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include - -using namespace std; - -int A[100]; -int B[100]; - -int main() -{ - int N, NA, NB; scanf("%d%d%d", &N, &NA, &NB); - - for (int i = 1; i <= NA; i++) scanf("%d", &A[i]); - for (int i = 1; i <= NB; i++) scanf("%d", &B[i]); - A[0] = A[NA]; B[0] = B[NB]; - - int a, b; - int winA = 0, winB = 0; - for (int i = 1; i <= N; i++) - { - a = A[i % NA]; - b = B[i % NB]; - if (a == 0) - { - if (b == 2) winA++; - else if (b == 5) winB++; - } - else if (a == 2) - { - if (b == 0) winB++; - else if (b == 5) winA++; - } - else if (a == 5) - { - if (b == 0) winA++; - else if (b == 2) winB++; - } - } - - if (winA > winB) printf("%c", 'A'); - else if (winA < winB) printf("%c", 'B'); - else if (winA == winB) printf("%s", "draw"); - - return 0; -} diff --git a/POJ/OPJ_02D.cpp b/POJ/OPJ_02D.cpp deleted file mode 100644 index 0390c2e..0000000 --- a/POJ/OPJ_02D.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -using namespace std; - -int f(int a, int b) //ʾaòbӽзֽʱķ -{ - if (a == 1) return 1; //һַֽ - if (b == 1) return 0; //ij - if (a % b == 0) return f(a / b, b) + f(a, b - 1); - return f(a, b - 1); -} - -int main() -{ - int n; scanf("%d", &n); - - int m; - while(n--) - { - scanf("%d", &m); - printf("%d\n", f(m, m)); - } - - return 0; -} diff --git a/POJ/OPJ_02E.cpp b/POJ/OPJ_02E.cpp deleted file mode 100644 index aad8cb5..0000000 --- a/POJ/OPJ_02E.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -using namespace std; - -double A[10]; -double l, r, m; -int N; - -bool is(double x) -{ - double fx = 0; - for (int i = 0; i <= N; i++) - fx += A[i] * pow(x, i); - - double t = 0; - for (int i = 0; i <= N; i++) - t += A[i] * pow(l, i); - - return fx * t > 0; -} - -int main() -{ - A[0] = -121; - A[1] = 274; - A[2] = -225; - A[3] = 85; - A[4] = -15; - A[5] = 1; - - l = 1.5, r = 2.4, N = 5; - - while(r - l > 1e-7) - { - m = (l + r) / 2; - if (is(m)) l = m; - else r = m; - } - printf("%.6f", m); - return 0; -} diff --git a/POJ/OPJ_02G_2.cpp b/POJ/OPJ_02G_2.cpp deleted file mode 100644 index 36e4f7e..0000000 --- a/POJ/OPJ_02G_2.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include - -using namespace std; - -int A[20] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768}; - -void f(int x) -{ - if (x == 0) return; - for (int i = 0; i < 20; i++) - if (x >= A[i] && x < A[i + 1]) - { - if (i == 0) - cout << "2(0)"; - else if (i == 1) - cout << "2"; - else if (i == 2) - cout << "2(2)"; - //else if (i == 2 || i == 4 || i == 8 || i == 16) - //cout << 2 << '(' << i << ')'; - else - { - cout << "2("; - f(i); - cout << ")"; - } - if (x != A[i]) - { - cout << '+'; - f(x - A[i]); - } - break; - } - return; -} - -int main() -{ - int N; cin >> N; - /*for (int i = 1; i < 20000; i++) - { - f(i); - cout << '\n'; - }*/ - f(N); - return 0; -} diff --git a/POJ/OPJ_02I.cpp b/POJ/OPJ_02I.cpp deleted file mode 100644 index bd7754f..0000000 --- a/POJ/OPJ_02I.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; - -int A[10][10]; -int B[10][10]; - -int T[10]; - -int main() -{ - int R, C; R = 5, C = 6; - - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - memset(T, 0, sizeof(T)); - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - scanf("%d", &A[i][j]); - - B[1][1] = -1; - for (int i = 1; i <= 64; i++) - { - B[1][1]++; - for (int k = 1; k <= C; k++) - if (B[1][k] == 2) {B[1][k] = 0; B[1][k + 1]++;} - else break; - - for (int j = 1; j <= R; j++) - { - for (int k = 1; k <= C; k++) - B[j + 1][k] = (A[j][k] + B[j - 1][k] + B[j][k - 1] + B[j][k + 1] + B[j][k]) % 2; - } - - int s; - for (s = 1; s <= C && B[R + 1][s] == 0; s++); - if (s > C) - { - for (int j = 1; j <= R; j++) - { - for (int k = 1; k <= C; k++) - printf("%d ", B[j][k]); - printf("\n"); - } - break; - } - } - - return 0; -} diff --git a/POJ/OPJ_03B.cpp b/POJ/OPJ_03B.cpp deleted file mode 100644 index 1920e8a..0000000 --- a/POJ/OPJ_03B.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -using namespace std; - -struct node -{ - int a; - int b; - int c; - int d; -}; - -node A[1000]; - -bool myCompare(node A, node B) -{ - if (A.a == B.a) - if (A.b == B.b) - if (A.c == B.c) - return A.d < B.d; - else - return A.c < B.c; - else - return A.b < B.b; - else - return A.a < B.a; -} - -int main() -{ - int N; cin >> N; - - int A_xb = 0; - - for (int i = 2; i <= N; i++) - for (int j = i; j <= N; j++) - for (int k = j; k <= N; k++) - { - int res = i * i * i + j * j * j + k * k * k; - - int s; - for (s = 2; s <= N && s * s * s < res; s++); - if (s <= N && s * s * s == res) - { - ++A_xb; - A[A_xb].a = s; - A[A_xb].b = i; - A[A_xb].c = j; - A[A_xb].d = k; - } - } - - sort(A + 1, A + A_xb + 1, myCompare); - for (int i = 1; i <= A_xb; i++) - cout << "Cube = " << A[i].a << ", Triple = (" << A[i].b - << "," << A[i].c << "," << A[i].d << ")\n"; - return 0; -} diff --git a/POJ/OPJ_1390.cpp b/POJ/OPJ_1390.cpp deleted file mode 100644 index 421f70c..0000000 --- a/POJ/OPJ_1390.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -using namespace std; - -int M; -int A[10010]; - -int divide(int l, int r) -{ - int mid = A[l]; - - do - { - while(l < r && A[r] >= mid) --r; - if (l < r) {A[l] = A[r]; ++l;}; - while(l < r && A[l] <= mid) ++l; - if (l < r) {A[r] = A[l]; --r;}; - }while(l < r); - - A[l] = mid; - return l; -} - -int quickSort(int l, int r) -{ - if (l == r) return A[l]; - - int mid = divide(l, r); - - if (mid == M) return A[mid]; - else if (mid > M) return quickSort(l, mid - 1); - else if (mid < M) return quickSort(mid + 1, r); -} - -int main() -{ - int N; scanf("%d", &N); - - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - - M = (N + 1) / 2; - - sort(A + 1, A + N + 1); - cout << A[M]; - //cout << quickSort(1, N); - - return 0; -} diff --git a/POJ/OPJ_1936.cpp b/POJ/OPJ_1936.cpp deleted file mode 100644 index 4bbe4f1..0000000 --- a/POJ/OPJ_1936.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -using namespace std; - -int main() -{ - string str; - char sstr[3]; - - while(cin >> str >> sstr[0] >> sstr[1] >> sstr[2]) - { - int xb = 0; - for (int i = 1; str[i] != '\0'; i++) - if (str[i] > str[xb]) xb = i; - - int i; - for (i = 0; i <= xb; i++) - printf("%c", str[i]); - printf("%c%c%c", sstr[0], sstr[1], sstr[2]); - for (; str[i] != '\0'; i++) - printf("%c", str[i]); - printf("\n"); - } - return 0; -} diff --git a/POJ/OPJ_19630.cpp b/POJ/OPJ_19630.cpp deleted file mode 100644 index e8ef9bd..0000000 --- a/POJ/OPJ_19630.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int x1, x2; - - int A_1 = 2, A_2 = 0; //㽶 - int B_1 = 250, B_2 = 200; // - int C_1 = 75, C_2 = 150; // - int D_1 = 100, D_2 = 150; // - int E_1 = 0, E_2 = 75; //ɿɷ - - int M_1 = 400, M_2 = 450; // - - int T_1 = 100, T_2 = 100; // - - int A, B, C, D, E; - scanf("%d%d%d%d%d", &B, &A, &C, &D, &E); - - T_1 = min(T_1, A / A_1); T_1 = min(T_1, B / B_1); - T_1 = min(T_1, C / C_1); T_1 = min(T_1, D / D_1); - T_2 = min(T_2, B / B_2); T_2 = min(T_2, C / C_2); T_2 = min(T_2, D / D_2); T_2 = min(T_2, E / E_2); - - int MAX = 0, i_max = 0, j_max = 0; - - for (int i = 0; i <= T_1; i++) - { - for (int j = T_2; j >= 0; j--) - { - if (A_1 * i + A_2 * j <= A && B_1 * i + B_2 * j <= B && - C_1 * i + C_2 * j <= C && D_1 * i + D_2 * j <= D && - E_1 * i + E_2 * j <= E) - { - if (i * M_1 + j * M_2 > MAX) - { - MAX = i * M_1 + j * M_2; - i_max = i, j_max = j; - } - break; - } - } - } - - printf("%d\n%d\n%d", MAX, i_max, j_max); - - return 0; -} diff --git a/POJ/OPJ_19895.cpp b/POJ/OPJ_19895.cpp deleted file mode 100644 index 572f2be..0000000 --- a/POJ/OPJ_19895.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -using namespace std; - -const int inf = 1e9; - -int A[12][2]; - -int B[12][12]; - -int main() -{ - int N; scanf("%d", &N); - - for (int i = 1; i <= N; i++) - for (int j = 1; j <= N; j++) - scanf("%d", &B[i][j]); - - for (int i = 1; i <= N; i++) - { - A[i][1] = B[1][i]; // - A[i][0] = 1; // - } - - for (int i = 1; i <= N; i++) - for (int j = i - 1; j > 1; j--) - { - if (B[i][j] + A[j][1] < A[i][1]) - { - A[i][1] = B[i][j] + A[j][1]; - A[i][0] = j; //ıһ· - } - } - - printf("%d\n", A[N][1]); - - stack s; - - int i = N; - while(i != 1) - { - s.push(i); - i = A[i][0]; - } - - printf("%d ", 1); - while(!s.empty()) - { - printf("%d ", s.top()); - s.pop(); - } - - - return 0; -} diff --git a/POJ/OPJ_20062.cpp b/POJ/OPJ_20062.cpp deleted file mode 100644 index 620e6be..0000000 --- a/POJ/OPJ_20062.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -using namespace std; - -int A[1010]; - -int main() -{ - int N, K; cin >> N >> K; - - for (int i = 1; i <= N; i++) scanf("%d", &A[i]); - A[0] = -1e9; - - sort(A + 1, A + N + 1); - - int MAX = -1; - int i, j(N); - for (i = 1; i < j; i++) - { - for (;j > i && A[i] + A[j] > K; j--); - MAX = max(MAX, A[i] + A[j]); - } - - printf("%d", MAX); - - return 0; -} diff --git a/POJ/OPJ_20063.cpp b/POJ/OPJ_20063.cpp deleted file mode 100644 index 8f77149..0000000 --- a/POJ/OPJ_20063.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[1010]; -struct node -{ - int weight; - int money; - double average; -}; - -bool myCompare(node A, node B){return A.average > B.average;}; - -int main() -{ - memset(A, 0, sizeof(A)); - - int N, C; cin >> N >> C; - - node* B = new node[N]; - - for (int i = 0; i < N; i++) scanf("%d", &B[i].weight); - for (int i = 0; i < N; i++) scanf("%d", &B[i].money); - for (int i = 0; i < N; i++) B[i].average = double(B[i].money) / B[i].weight; - - sort(B, B + N, myCompare); - - int sum = 0; - for (int i = 0; i < N; i++) - { - int b = C / B[i].weight; - sum += b * B[i].money; - C -= b * B[i].weight; - } - - printf("%d", sum); - return 0; -} diff --git a/POJ/OPJ_20064.cpp b/POJ/OPJ_20064.cpp deleted file mode 100644 index f9b01f6..0000000 --- a/POJ/OPJ_20064.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[110][110]; - -int main() -{ - memset(A, 0, sizeof(A)); - - int N, M; scanf("%d%d", &N, &M); - - for (int i = 1; i <= N; i++) scanf("%d", &A[i][1]); - A[0][1] = -1e9; - - for (int j = 2; j <= N; j++) - for (int i = j; i <= N; i++) - for (int k = 1; k < i; k++) - A[i][j] = max(A[i][j], A[i - k][j - 1] + A[k][1]); - - printf("%d", A[N][M]); - - return 0; -} diff --git a/POJ/OPJ_20065.cpp b/POJ/OPJ_20065.cpp deleted file mode 100644 index 4879533..0000000 --- a/POJ/OPJ_20065.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -using namespace std; - -const int inf = 1e9; - -int A[12]; -int B[12][12]; - -int main() -{ - int N, K; scanf("%d%d", &N, &K); - - for (int i = 1; i <= N; i++) A[i] = inf; - - for (int i = 1; i <= N; i++) - for (int j = 1; j <= N; j++) - scanf("%d", &B[i][j]); - - for (int i = 1; i <= N; i++) //ʼ1ľ - A[i] = B[1][i]; - - for (int i = 2; i <= N; i++) - { - for (int j = i - 1; j > 1; j--) - A[i] = min(A[i], B[i][j] + A[j]); - } - - for (int i = N; i >= 1; i--) - if (A[i] <= K) - { - printf("%d", i); - break; - } - - return 0; -} diff --git a/POJ/OPJ_2757.cpp b/POJ/OPJ_2757.cpp deleted file mode 100644 index 1e6a85c..0000000 --- a/POJ/OPJ_2757.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -using namespace std; -int A[1200]; -int B[1200]; - -int main() -{ - int N; cin >> N; - for (int i = 1; i <= N; i++) - { - cin >> A[i]; - B[i] = 1; - } - for (int i = 1; i <= N; i++) - for (int j = i - 1; j >= 0; j--) - if (A[j] < A[i]) - B[i] = max(B[i], B[j] + 1); - cout << *max_element(B + 1, B + N + 1); - return 0; -} diff --git a/POJ/OPJ_2792.cpp b/POJ/OPJ_2792.cpp deleted file mode 100644 index b2eb836..0000000 --- a/POJ/OPJ_2792.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -using namespace std; -int A[10001]; -int B[10001]; - -int main() -{ - int n; cin >> n; - int s, a, b, l, r, sum, tmp; - for (int i = 1; i <= n; i++) - { - cin >> s; - cin >> a; - for (int j = 1; j <= a; j++) - cin >> A[j]; - cin >> b; - for (int j = 1; j <= b; j++) - cin >> B[j]; - sort(A + 1, A + a + 1); - sort(B + 1, B + b + 1); - - sum = 0; r = b; - for (l = 1; l <= a; l++) - { - tmp = l; - for (; l < a && A[l + 1] == A[l]; l++); - tmp = l - tmp + 1; - while(r >= 1) - { - if (A[l] + B[r] == s) - sum += tmp; - else if (A[l] + B[r] < s) - break; - r--; - } - } - cout << sum << endl; - } - - return 0; -} diff --git a/POJ/OPJ_2815.cpp b/POJ/OPJ_2815.cpp deleted file mode 100644 index f0d8748..0000000 --- a/POJ/OPJ_2815.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -using namespace std; -int roomsNum[60][60]; -int roomsColor[60][60]; -int roomSum = 0; -int roomMax = 0; -int roomArea = 0; - -void Dfs(int i, int j) -{ - if (roomsColor[i][j] != 0) - return; - ++roomArea; roomsColor[i][j] = roomSum; - if ((roomsNum[i][j] & 1) == 0) Dfs(i, j - 1); - if ((roomsNum[i][j] & 2) == 0) Dfs(i - 1, j); - if ((roomsNum[i][j] & 4) == 0) Dfs(i, j + 1); - if ((roomsNum[i][j] & 8) == 0) Dfs(i + 1,j); -} -int main() -{ - int R, C; cin >> R >> C; - memset(roomsColor, 0, sizeof(roomsColor)); - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - cin >> roomsNum[i][j]; - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - { - if (roomsColor[i][j] == 0) - { - roomSum++; roomArea = 0; - Dfs(i, j); - roomMax = max(roomMax, roomArea); - } - } - cout << roomSum << endl << roomMax; - return 0; -} diff --git a/POJ/OPJ_3058.cpp b/POJ/OPJ_3058.cpp deleted file mode 100644 index dc916c0..0000000 --- a/POJ/OPJ_3058.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - long long int height; - long long int label; - node(long long int h, long long int l):height(h), label(l){}; - node(){}; -}; - -long long int A[80010]; - -int main() -{ - stack s; - int N; scanf("%d", &N); - - s.push(node(1000000000 + 7, 0)); //ǽ - - for (int i = 1; i <= N; i++) scanf("%lld", &A[i]); - - long long int tmp; - long long int sum = 0; - for (long long int i = 1; i <= N; i++) - { - tmp = A[N - i + 1]; - while(s.top().height < tmp) s.pop(); - sum += i - s.top().label - 1; - s.push(node(tmp, i)); - } - printf("%lld", sum); - return 0; -} diff --git a/POJ/OPJ_3248.cpp b/POJ/OPJ_3248.cpp deleted file mode 100644 index 99fce49..0000000 --- a/POJ/OPJ_3248.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -using namespace std; - -int main() -{ - int x, y; - int MAX, MIN, MID; - while(scanf("%d%d", &x, &y) != EOF) - { - MAX = max(x, y); - MIN = min(x, y); - while(MIN != 0) - { - MID = MAX % MIN; - MAX = MIN; - MIN = MID; - } - printf("%d\n", MAX); - } - return 0; -} diff --git a/POJ/OPJ_3866.cpp b/POJ/OPJ_3866.cpp deleted file mode 100644 index 1e5ba63..0000000 --- a/POJ/OPJ_3866.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -//int M[2][1000010]; -//int m[2][1000010]; - -vector v; -int M[1000010]; -int m[1000010]; - -int main() -{ - int n, k; scanf("%d%d", &n, &k); - - int d; - for (int i = 0; i < n; i++) - { - scanf("%d", &d); - v.push_back(d); - } - deque qmax; - deque qmin; - - for (int i = 0; i < n; i++) - { - while(!qmax.empty() && v[i] > v[qmax.back()]) - qmax.pop_back(); - if (!qmax.empty() && i - qmax.front() >= k) - qmax.pop_front(); - qmax.push_back(i); - - while(!qmin.empty() && v[i] < v[qmin.back()]) - qmin.pop_back(); - if (!qmin.empty() && i - qmin.front() >= k) - qmin.pop_front(); - qmin.push_back(i); - - M[i] = v[qmax.front()]; - m[i] = v[qmin.front()]; - } - - for (int i = k - 1; i < n; i++) - printf("%d ", m[i]); - printf("\n"); - for (int i = k - 1; i < n; i++) - printf("%d ", M[i]); - return 0; -} - - -/*int main() -{ - int n, k; cin >> n >> k; - - for (int j = 1; j <= n; j++) - { - scanf("%d", &M[0][j]); - m[0][j] = M[0][j]; - } - - for (int i = 2; i <= k; i++) - { - for (int j = 1; j <= n + 1 - i; j++) - { - M[1][j] = max(M[0][j], M[0][j + 1]); - m[1][j] = min(m[0][j], m[0][j + 1]); - } - for (int j = 1; j <= n + 1 - i; j++) - { - M[0][j] = M[1][j]; - m[0][j] = m[1][j]; - } - } - - for (int j = 1; j <= n + 1 - k; j++) - printf("%d ", m[0][j]); - printf("\n"); - for (int j = 1; j <= n + 1 - k; j++) - printf("%d ", M[0][j]); - - return 0; -}*/ diff --git a/POJ/OPJ_4110.cpp b/POJ/OPJ_4110.cpp deleted file mode 100644 index 923d584..0000000 --- a/POJ/OPJ_4110.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -using namespace std; -struct sweet -{ - int value; - int weight; - double average; -}; -sweet A[120]; - -bool myCompare(sweet A, sweet B){return A.average > B.average;}; -int main() -{ - int N, W; cin >> N >> W; - - for (int i = 1; i <= N; i++) - { - cin >> A[i].value >> A[i].weight; - A[i].average = double(A[i].value) / double(A[i].weight); - } - sort(A + 1, A + N + 1, myCompare); - - int total_w = 0; - double total_v = 0; - - for (int i = 1; i <= N; i++) - { - if (A[i].weight + total_w > W) - { - total_v += (W - total_w) * A[i].average; - break; - } - total_w += A[i].weight; - total_v += A[i].value; - } - printf("%.1f", total_v); - return 0; -} diff --git a/POJ/OPJ_4117.cpp b/POJ/OPJ_4117.cpp deleted file mode 100644 index 7aac7ff..0000000 --- a/POJ/OPJ_4117.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[60][60]; - -int main() -{ - int N; - memset(A, 0, sizeof(A)); - - for (int i = 1; i <= 50; i++) - for (int j = 1; j <= 50; j++) - if (i == 1 || j == 1) A[i][j] = 1; - else if (i == j) A[i][j] = A[i][j - 1] + 1; - else if (i > j) A[i][j] = A[i][j - 1] + A[i - j][j]; - else A[i][j] = A[i][i]; - while(scanf("%d", &N) != EOF) - printf("%d\n", A[N][N]); - - return 0; -} diff --git a/POJ/OPJ_4133.cpp b/POJ/OPJ_4133.cpp deleted file mode 100644 index 4f8ac77..0000000 --- a/POJ/OPJ_4133.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[1030][1030]; - -int main() -{ - int d, n; cin >> d >> n; - int x, y, t; - int x_t, x_b, y_t, y_b; - int MAX = 0; - int sum = 1; - - memset(A, 0, sizeof(A)); - - for (int i = 1; i <= n; i++) - { - scanf("%d%d%d", &x, &y, &t); - x_b = max(0, x - d); - x_t = min(1024, x + d); - y_b = max(0, y - d); - y_t = min(1024, y + d); - for (int j = x_b; j <= x_t; j++) - for (int k = y_b; k <= y_t; k++) - { - A[j][k] += t; - if (A[j][k] == MAX) ++sum; - if (A[j][k] > MAX) - { - sum = 1; - MAX = A[j][k]; - } - } - } - cout << sum << " " << MAX; - return 0; -} diff --git a/POJ/OPJ_5343.cpp b/POJ/OPJ_5343.cpp deleted file mode 100644 index 68d9fc4..0000000 --- a/POJ/OPJ_5343.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -using namespace std; - -struct node -{ - char ch; - int num; - node(char c, int n):ch(c), num(n){}; - node(){}; -}; - -queue B[10]; -queue C[4]; -queue res; - -int main() -{ - int N; scanf("%d", &N); - - char ch; - int num; - for (int i = 1; i <= N; i++) - { - cin >> ch >> num; - B[num].push(ch); - } - for (int i = 1; i <= 9; i++) - { - cout << "Queue" << i << ":"; - while(!B[i].empty()) - { - cout << B[i].front() << i << " "; - C[B[i].front() - 'A'].push(i); - B[i].pop(); - } - cout << endl; - } - - for (int i = 0; i < 4; i++) - { - char tmp = 'A' + i; - cout << "Queue" << tmp << ":"; - while(!C[i].empty()) - { - cout << tmp << C[i].front() << " "; - res.push(node(tmp, C[i].front())); - C[i].pop(); - } - cout << endl; - } - - while(!res.empty()) - { - cout << res.front().ch << res.front().num << " "; - res.pop(); - } - return 0; -} diff --git a/POJ/OPJ_5345.cpp b/POJ/OPJ_5345.cpp deleted file mode 100644 index 2c47246..0000000 --- a/POJ/OPJ_5345.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -using namespace std; - -int A[100010]; - -int main() -{ - int N, M; scanf("%d%d", &N, &M); - - for (int i = 0; i < N; i++) - scanf("%d", &A[i]); - - char ch; - int x; - for (int i = 1; i <= M; i++) - { - cin >> ch >> x; - if (ch == 'C') - { - int j = N; - while(j--) - { - A[j] += x; - if (A[j] > 65535) A[j] %= 65535; - } - } - else - { - int sum = 0; - int j = N; - while(j--) - if ((A[j] >> x) & 1) sum++; - printf("%d\n", sum); - } - } - return 0; -} diff --git a/POJ/OPJ_5467.cpp b/POJ/OPJ_5467.cpp deleted file mode 100644 index d40e823..0000000 --- a/POJ/OPJ_5467.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -using namespace std; - -struct node -{ - int a; - int b; -}; - -const int N = 1000; -node A[N + 1]; - -bool myCompare(node A, node B){return A.b > B.b;}; - -int main() -{ - int a, b; - int n; scanf("%d", &n); - - for (int i = 1; i <= n; i++) - { - memset(A, 0, sizeof(A)); - int A_xb = 0; - - for (int j = 1; j <= 2; j++) - { - scanf("%d%d", &a, &b); - while(b >= 0) - { - ++A_xb; - A[A_xb].a = a; - A[A_xb].b = b; - scanf("%d%d", &a, &b); - } - } - sort(A + 1, A + A_xb + 1, myCompare); - for (int j = 1; j <= A_xb; j++) - { - int tmp = A[j].a; - int k; - for (k = j + 1; k <= A_xb && A[j].b == A[k].b; k++) - tmp += A[k].a; - if (tmp != 0) printf("%c %d %d %c ", '[', tmp, A[j].b, ']'); - j = k - 1; - } - printf("\n"); - } - return 0; -} diff --git a/POJ/OPJ_5714.cpp b/POJ/OPJ_5714.cpp deleted file mode 100644 index 8ed8fd6..0000000 --- a/POJ/OPJ_5714.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -using namespace std; - -int main() -{ - int t; cin >> t; - - while(t--) - { - int n; cin >> n; - int type, val; - - stack s; //1 - queue q; //2 - - int res = 0; - while(n--) - { - cin >> type >> val; - if (!res) - { - if (type == 1) - { - s.push(val); - q.push(val); - } - else if (type == 2) - { - if (s.top() != val) - res = 2; - else s.pop(); - if (q.front() != val) - res = 1; - else q.pop(); - } - } - } - - if (res == 1) cout << "Stack\n"; - else if (res == 2) cout << "Queue\n"; - } - return 0; -} diff --git a/POJ/OPJ_5847.cpp b/POJ/OPJ_5847.cpp deleted file mode 100644 index 172669f..0000000 --- a/POJ/OPJ_5847.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int m; scanf("%d", &m); - - while(m--) - { - int n; scanf("%d", &n); - bool flag = true; - - stack s; - stack res; - - string str; - while(n--) - { - cin >> str; - if (str == "pop") - if (s.empty()) flag = 0; - else s.pop(); - else if (str == "push") - { - int tmp; - cin >> tmp; - s.push(tmp); - } - } - - if (!flag) cout << "error"; - else - { - while(!s.empty()) - { - res.push(s.top()); - s.pop(); - } - while(!res.empty()) - { - cout << res.top() << " "; - res.pop(); - } - } - cout << endl; - } - return 0; -} diff --git a/POJ/OPJ_5902.cpp b/POJ/OPJ_5902.cpp deleted file mode 100644 index c0e14db..0000000 --- a/POJ/OPJ_5902.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int t; cin >> t; - - while(t--) - { - deque v; - int n; cin >> n; - while(n--) - { - int type, val; - cin >> type >> val; - if (type == 1) - v.push_back(val); - else if (type == 2) - if (val == 0) - v.pop_front(); - else if (val == 1) - v.pop_back(); - } - if (v.empty()) cout << "NULL\n"; - else - { - while(!v.empty()) - { - cout << v.front() << " "; - v.pop_front(); - } - cout << endl; - } - } - return 0; -} diff --git a/POJ/OPJ_6364.cpp b/POJ/OPJ_6364.cpp deleted file mode 100644 index 00f77b0..0000000 --- a/POJ/OPJ_6364.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int A; - int B; - int label; -}; - -node A[50010]; - -bool myFirstCompare(node A, node B){return A.A > B.A;}; -bool mySecondCompare(node A, node B){return A.B > B.B;}; - -int main() -{ - int N, K; scanf("%d%d", &N, &K); - - for (int i = 1; i <= N; i++) - { - scanf("%d%d", &A[i].A, &A[i].B); - A[i].label = i; - } - sort(A + 1, A + N + 1, myFirstCompare); - sort(A + 1, A + K + 1, mySecondCompare); - cout << A[1].label; - return 0; -} diff --git a/POJ/OPJ_666.cpp b/POJ/OPJ_666.cpp deleted file mode 100644 index 531fd13..0000000 --- a/POJ/OPJ_666.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -using namespace std; - -int A[12][12]; - -int main() -{ - memset(A, 0, sizeof(A)); - - for (int i = 1; i <= 10; i++) - { - A[i][1] = 1; - for (int j = 1; j <= 10; j++) - { - A[0][j] = 1; - if (i < j) - A[i][j] = A[i][j - 1]; - else - A[i][j] = A[i][j - 1] + A[i - j][j]; - } - } - - int t, M, N; scanf("%d", &t); - while(t--) - { - scanf("%d%d", &M, &N); - printf("%d\n", A[M][N]); - } - - return 0; -} diff --git a/POJ/OPJ_7120.cpp b/POJ/OPJ_7120.cpp deleted file mode 100644 index 31f5781..0000000 --- a/POJ/OPJ_7120.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - string A, B; - cin >> A >> B; - - int len_A = A.length(); - int len_B = B.length(); - - int a[210], b[210]; - memset(a, 0, sizeof(a)); - memset(b, 0, sizeof(b)); - - for (int i = 0; i < len_A; i++) - a[i] = A[len_A - i - 1] - '0'; - for (int i = 0; i < len_B; i++) - b[i] = B[len_B - i - 1] - '0'; - - int res[510]; - memset(res, 0, sizeof(res)); - - int yushu = 0; - for (int i = 0; i <= len_A; i++) - { - for (int j = 0; j <= len_B; j++) - { - int tmp = a[i] * b[j]; - res[i + j] += yushu + tmp % 10; - yushu = tmp / 10; - if (res[i + j] >= 10) - { yushu += res[i + j] / 10; res[i + j] %= 10;}; - } - } - - int xb = 500; - for (; xb >= 0 && res[xb] == 0; xb--); - - for (int i = xb; i >= 0; i--) - printf("%d", res[i]); - - return 0; -} diff --git a/POJ/OPJ_7216.cpp b/POJ/OPJ_7216.cpp deleted file mode 100644 index dbefb89..0000000 --- a/POJ/OPJ_7216.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int N; cin >> N; - int tmp_N = N; - int M1 = pow(double(N), 0.3333) + 1; - int M2, M3; - int MIN = 10000000; - - for (int i = M1; i >= 1; i--) - if (N % i == 0) - { - M1 = i; - tmp_N = N / M1; - M2 = sqrt(tmp_N); - for (int j = M2; j >= 1; j--) - if (tmp_N % j == 0) - { - M2 = j; - M3 = tmp_N / j; - MIN = min(MIN, 2 * (M1 * M2 + M1 * M3 + M2 * M3)); - //cout << M1 << " " << M2 << " " << M3 << " " << MIN << endl; - } - } - cout << MIN; - return 0; -} diff --git a/POJ/OPJ_7217.cpp b/POJ/OPJ_7217.cpp deleted file mode 100644 index 6e2ed43..0000000 --- a/POJ/OPJ_7217.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -using namespace std; - -int A[10000]; - -int main() -{ - int N; cin >> N; - int i = 0, j = 1; - - while (i <= N) - { - A[1] = j * N + 1; - for (i = 2; i <= N && (A[i - 1] % (N - 1) == 0); i++) - A[i] = A[i - 1] * N / (N - 1) + 1; - ++j; - } - cout << A[N]; - return 0; -} diff --git a/POJ/OPJ_7218.cpp b/POJ/OPJ_7218.cpp deleted file mode 100644 index 459c7cc..0000000 --- a/POJ/OPJ_7218.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -char A[210][210]; -int MIN; - -void Dfs(int x, int y, int steps) -{ - if (steps >= MIN) return; //֧ - if (A[x][y] == 2) { MIN = min(MIN, steps); return;} - - A[x][y] = (-1) * A[x][y]; - if (A[x][y + 1] > 0) Dfs(x, y + 1, steps + 1); // - if (A[x + 1][y] > 0) Dfs(x + 1, y, steps + 1); // - if (A[x][y - 1] > 0) Dfs(x, y - 1, steps + 1); // - if (A[x - 1][y] > 0) Dfs(x - 1, y, steps + 1); // - - A[x][y] = (-1) * A[x][y]; - return; -} - -struct node -{ - int x; - int y; - int steps; - node(int the_x, int the_y, int the_steps) - :x(the_x), y(the_y), steps(the_steps){}; -}; -int Bfs(int x, int y) -{ - queue B; - B.push(node(x, y, 0)); - - node cur(-1, -1, '0'); - - while(!B.empty()) - { - - cur = B.front(); - B.pop(); - if (A[cur.x][cur.y] == 'E') return cur.steps; - - A[cur.x][cur.y] = '#'; - - if (A[cur.x - 1][cur.y] != '#') B.push(node(cur.x - 1, cur.y, cur.steps + 1)); - if (A[cur.x + 1][cur.y] != '#') B.push(node(cur.x + 1, cur.y, cur.steps + 1)); - if (A[cur.x][cur.y - 1] != '#') B.push(node(cur.x, cur.y - 1, cur.steps + 1)); - if (A[cur.x][cur.y + 1] != '#') B.push(node(cur.x, cur.y + 1, cur.steps + 1)); - } - return -1; -} -int main() -{ - int T; cin >> T; - - for (int k = 1; k <= T; k++) - { - char ch; - int R, C; cin >> R >> C; - int start_x, start_y; - - - MIN = 0; - - for (int i = 1; i <= R; i++) - A[i][0] = A[i][C + 1] = '#'; - for (int i = 1; i <= C; i++) - A[0][i] = A[R + 1][C] = '#'; - - for (int i = 1; i <= R; i++) - { - for (int j = 1; j <= C; j++) - { - cin >> A[i][j]; - if (A[i][j] == 'S') { start_x = i; start_y = j;} - /*if (ch == '#') A[i][j] = 0; - else if (ch == '.') A[i][j] = 1; - else if (ch == 'S') - { start_x = i; start_y = j;} - else if (ch == 'E') A[i][j] = 2;*/ - } - } - - /*Dfs(start_x, start_y, 0); - - if (MIN == 1e9) printf("%s\n", "oop!"); - else printf("%d\n", MIN); */ - - MIN = Bfs(start_x, start_y); - if (MIN == -1) cout << "oop!" << endl; - else cout << MIN << endl; - } - - return 0; -} diff --git a/POJ/OPJ_9198.cpp b/POJ/OPJ_9198.cpp deleted file mode 100644 index 1d4d95f..0000000 --- a/POJ/OPJ_9198.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - stack s; - char tmp; - - while(scanf("%c", &tmp) != EOF && tmp != '\n') - { - if (!s.empty()) - { - if (tmp == '}' && s.top() == '{') - s.pop(); - else if (tmp == ']' && s.top() == '[') - s.pop(); - else if (tmp == ')' && s.top() == '(') - s.pop(); - else s.push(tmp); - } - else s.push(tmp); - //cout << s.top(); - } - - if (s.empty()) printf("%s", "Yes"); - else printf("%s", "No"); - - return 0; -} diff --git a/POJ/POJ_02.cpp b/POJ/POJ_02.cpp deleted file mode 100644 index 1e9cd24..0000000 --- a/POJ/POJ_02.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include - -using namespace std; - -/*const int X = 3; -const int Y = 30; -int A[X + 2][Y + 2]; -int sum = 0; - -void Cover(int total, int n, int x, int y) -{ - if (2 * total == 3 * n) - { - bool flag = true; - for (int i = 1; i <= X && flag; i++) - for (int j = 1; j <= n; j++) - if (A[i][j] == 0) { flag = false; break;} - if (flag) sum++; - sum++; - return; - } - if (A[x][y] == 1) //õѾռ - { - if (x == 3) Cover(total , n, 1, y + 1); - else Cover(total, n , x + 1, y); - } - else - { - if (x == 3 && A[x][y + 1] == 0) - { - A[x][y] = A[x][y + 1] = 1; - Cover(total + 1, n, 1, y + 1); - A[x][y] = A[x][y + 1] = 0; - } - else - { - if (A[x + 1][y] == 0) - { - A[x][y] = A[x + 1][y] = 1; - Cover(total + 1, n, x + 1, y); - A[x][y] = A[x + 1][y] = 0; - } - if (A[x][y + 1] == 0) - { - A[x][y] = A[x][y + 1] = 1; - Cover(total + 1, n, x + 1, y); - A[x][y] = A[x][y + 1] = 0; - } - } - } -}*/ -int main() -{ - const int N = 100; - int n; cin >> n; - long long int *A = new long long int[N + 1]; int xb = 0; - long long int *S = new long long int[N + 1]; - for (int i = 0; i <= N; i++) S[i] = 0; - S[0] = 1; - S[2] = 3; - for (int i = 4; i <= N; i += 2) - S[i] = 4 * S[i - 2] - S[i - 4]; - S[0] = 0; - - - while(n != -1) - { - A[++xb] = S[n]; - cin >> n; - } - for (int i = 1; i <= xb; i++) - cout << A[i] << endl; - - - /*while(n != -1) - { - for (int i = 0; i <= X + 1; i++) - for (int j = 0; j <= n + 1; j++) - A[i][j] = 0; - for (int i = 0; i <= n + 1; i++) - A[0][i] = A[X + 1][i] = 1; - for (int i = 0; i <= X + 1; i++) - A[i][0] = A[i][n + 1] = 1; - - Cover(total, n, 1, 1); - cout << sum << endl; - total = sum = 0; - cin >> n; - };*/ - return 0; -} diff --git a/POJ/POJ_1042.cpp b/POJ/POJ_1042.cpp deleted file mode 100644 index bfcda18..0000000 --- a/POJ/POJ_1042.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -using namespace std; - -bool myCompare(int a, int b){return a > b;}; - -int first_profit[30]; -int decrease[30]; -int road_time[30]; -int tmp_stay[30]; -int true_stay[30]; -int i, j, k; - -int main() -{ - int n, h; scanf("%d", &n); - while(n != 0) - { - scanf("%d", &h); - - int sum_max = 0; - - for (int i = 1; i <= n; i++) - scanf("%d", &first_profit[i]); - for (int i = 1; i <= n; i++) - scanf("%d", &decrease[i]); - for (int i = 1; i < n; i++) - scanf("%d", &road_time[i]); - - memset(true_stay, 0, sizeof(true_stay)); - - for (int i = 1; i <= n; i++) - { - int c_profit[30]; - for (int i = 1; i <= n; i++) - c_profit[i] = first_profit[i]; //һ - - int tmp_sum = 0; - - int left_time = 12 * h; - for (int j = 1; j < i; j++) - left_time -= road_time[j]; //ʵʱ - - memset(tmp_stay, 0, sizeof(tmp_stay)); //ʼtmp_stay - - for (int k = 1; k <= left_time; k++) //ܵĵʱ - { - int tmp_xb = 1; //ѰǰֵԪ± - for (int s = 1; s <= i; s++) - if (c_profit[s] > c_profit[tmp_xb]) tmp_xb = s; - tmp_sum += c_profit[tmp_xb]; //ۼ - tmp_stay[tmp_xb]++; //ͣʱ - c_profit[tmp_xb] -= decrease[tmp_xb]; //õֵ½ - c_profit[tmp_xb] = max(0, c_profit[tmp_xb]); - } - if (tmp_sum > sum_max) //ֱֵӸ - { - for (int k = 1; k <= n; k++) - true_stay[k] = tmp_stay[k]; - sum_max = tmp_sum; - } - if (tmp_sum == sum_max) - { - for (j = 1; j <= n && tmp_stay[j] == true_stay[j]; j++); //Ѱһβͣʱ - if (tmp_stay[j] > true_stay[j]) - for (int k = 1; k <= n; k++) - true_stay[k] = tmp_stay[k]; - } - } - - for (int i = 1; i <= n; i++) true_stay[i] *= 5; - - printf("%d", true_stay[1]); - for (int i = 2; i <= n; i++) - printf("%c %d",',',true_stay[i]); - printf("\n%s%d\n\n", "Number of fish expected: ", sum_max); - - scanf("%d", &n); - } - return 0; -} diff --git a/POJ/POJ_1088.cpp b/POJ/POJ_1088.cpp deleted file mode 100644 index 8be4133..0000000 --- a/POJ/POJ_1088.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int x; - int y; - int sum; - int h; -}; -node A[12100]; //Aдֵ -int B[110][110]; //BдŸ߶ - -bool myCompare(node A, node B){return A.h < B.h;}; -int main() -{ - int R, C; cin >> R >> C; - int num, MAX = 0; - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - { - cin >> B[i][j]; - num = (i - 1) * C + j; - A[num].x = i; A[num].y = j; A[num].sum = 1; - A[num].h = B[i][j]; - } - for (int i = 0; i <= 101; i++) - B[0][i] = B[R + 1][i] = B[i][0] = B[i][C + 1] = -2e9; //Ϊ޵ - - sort(A + 1, A + R * C + 1, myCompare); //Ե - - for (int i = 1; i <= R * C; i++) - { - int cur_H = B[A[i].x][A[i].y]; //ǰĸ߶ - int cur_sum = A[(A[i].x - 1) * C + A[i].y].sum; //ǰֵ - if (B[A[i].x - 1][A[i].y] > cur_H) // - A[(A[i].x - 1 - 1) * C + A[i].y].sum = max(A[(A[i].x - 1 - 1) * C + A[i].y].sum, 1 + cur_sum); - if (B[A[i].x + 1][A[i].y] > cur_H) // - A[(A[i].x + 1 - 1) * C + A[i].y].sum = max(A[(A[i].x + 1 - 1) * C + A[i].y].sum, 1 + cur_sum); - if (B[A[i].x][A[i].y - 1] > cur_H) // - A[(A[i].x - 1) * C + A[i].y - 1].sum = max(A[(A[i].x - 1) * C + A[i].y - 1].sum, 1 + cur_sum); - if (B[A[i].x][A[i].y + 1] > cur_H) // - A[(A[i].x - 1) * C + A[i].y + 1].sum = max(A[(A[i].x - 1) * C + A[i].y + 1].sum, 1 + cur_sum); - } - for (int i = 1; i <= R * C; i++) - MAX = max(MAX, A[i].sum); - cout << MAX; - return 0; -} diff --git a/POJ/POJ_1163.cpp b/POJ/POJ_1163.cpp deleted file mode 100644 index fddf403..0000000 --- a/POJ/POJ_1163.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int N; cin >> N; - int Arr[101][101]; - int Brr[101][101]; - - for (int i = 1; i <= N ; i++) - for (int j = 1; j <= i; j++) - cin >> Arr[i][j]; - for (int i = 1; i <= N; i++) - Brr[N][i] = Arr[N][i]; - for (int i = N - 1; i >= 1; i--) - for(int j = 1; j <= i; j++) - Brr[i][j] = Arr[i][j] + max(Brr[i + 1][j], Brr[i + 1][j + 1]); - cout << Brr[1][1]; -} diff --git a/POJ/POJ_1166.cpp b/POJ/POJ_1166.cpp deleted file mode 100644 index 4b2c2ac..0000000 --- a/POJ/POJ_1166.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int* Arr = new int[10]; - int* Brr = new int[10]; - int* Crr= new int[10]; - - int i, j, k, m, tmp, sum = 200000; - for (i = 1; i < 10; i++) cin >> Arr[i]; - - for (i = 0; i <= 3; i++) - for (j = 0; j <= 3; j++) - for (k = 0; k <= 3; k++) - { - Brr[1] = i; Brr[2] = j; Brr[5] = k; // 1,2,5 - - Brr[3] = 4 - (Brr[1] + Brr[2] + Brr[5] + Arr[2]) % 4; - Brr[4] = 4 - (Brr[1] + Brr[2] + Arr[1]) % 4; - Brr[6] = 4 - (Brr[2] + Brr[3] + Arr[3]) % 4; - Brr[7] = 4 - (Brr[1] + Brr[4] + Brr[5] + Arr[4]) % 4; - Brr[8] = 4 - (Brr[4] + Brr[7] + Arr[7]) % 4; - Brr[9] = 4 - (Brr[1] + Brr[3] + Brr[5] + Brr[7] + Arr[5]) % 4; - - for (m = 1; m <= 9; m++) Brr[m] %= 4; - - if ((Brr[3] + Brr[5] + Brr[6] + Brr[9] + Arr[6]) % 4 != 0) continue; - if ((Brr[5] + Brr[7] + Brr[8] + Brr[9] + Arr[8]) % 4 != 0) continue; - if ((Brr[6] + Brr[8] + Brr[9] + Arr[9]) % 4 != 0) continue; - - tmp = 0; - for (m = 1; m <= 9; m++) tmp += Brr[m]; - if (tmp < sum) - { - for (m = 1; m <= 9; m++) Crr[m] = Brr[m]; - sum = tmp; - } - } - for (i = 1; i <= 9; i++) - for (j = 1; j <= Crr[i]; j++) - cout << i << " "; - return 0; -} diff --git a/POJ/POJ_1221.cpp b/POJ/POJ_1221.cpp deleted file mode 100644 index 47b62d7..0000000 --- a/POJ/POJ_1221.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -using namespace std; -const int N = 1200; -long long int A[N + 1][N + 1]; -int main() -{ - for (int i = 0; i <= N; i++) - for (int j = 0; j <= N; j++) - A[i][j] = 0; - for (int i = 0; i <= N; i++) A[i][i] = 1; - - for (int i = 1; i <= N; i++) - { - for (int j = 1; j < i; j++) - { - int x = i - 2 * j; - - if (x == 0) A[i][j]++; - else - for (int k = j; k <= x; k++) - A[i][j] += A[x][k]; - } - for (int j = 1; j <= i; j++) - A[i][0] += A[i][j]; - } - - int ch; cin >> ch; - while(ch != 0) - { - cout << ch << " " << A[ch][0] << endl; - cin >> ch; - } - return 0; -} diff --git a/POJ/POJ_1321.cpp b/POJ/POJ_1321.cpp deleted file mode 100644 index 73e0b69..0000000 --- a/POJ/POJ_1321.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -using namespace std; - -char A[10][10]; - -bool row[10]; //״̬ -bool colume[10]; //״̬ -int total; -int n, k; - -void Dfs(int x, int y, int sum) -{ - if (sum == k) {++total; return;}; - - row[x] = colume[y] = 1; - - for (int i = x + 1; i <= n; i++) - for (int j = 1; j <= n; j++) - if (A[i][j] == '#' && row[i] == 0 && colume[j] == 0) - { Dfs(i, j, sum + 1); row[i] = colume[j] = 0;}; - row[x] = colume[y] = 0; -} - -int main() -{ - cin >> n >> k; - - while(n != -1 || k != -1) - { - memset(row, 0, sizeof(row)); - memset(colume, 0, sizeof(colume)); - total = 0; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - cin >> A[i][j]; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - if (A[i][j] == '#') - { - Dfs(i, j, 1); - } - cout << total << endl; - cin >> n >> k; - } - return 0; -} diff --git a/POJ/POJ_1328.cpp b/POJ/POJ_1328.cpp deleted file mode 100644 index f909c86..0000000 --- a/POJ/POJ_1328.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include -using namespace std; - -struct line -{ - double left; - double right; -}; -line A[1010]; -bool myCompare(line A, line B){return A.left < B.left;}; -int main() -{ - int n, i = 0; - double d, x, y; cin >> n >> d; - - while(n != 0 || d != 0) - { - bool flag = true; - - for (int i = 1; i <= n; i++) - { - cin >> x >> y; - if (y > d) { flag = false; continue;} - A[i].left = x - sqrt(d * d - y * y); - A[i].right = x + sqrt(d * d - y * y); - } - if (!flag) cout << "Case " << ++i << ": " << -1 << endl; - else - { - int sum = 1; - - sort(A + 1, A + n + 1, myCompare); - x = A[1].left; y = A[1].right; - - for (int i = 2; i <= n; i++) - { - if (A[i].left > y) - { - x = A[i].left; - y = A[i].right; - ++sum; - } - else y = min(y, A[i].right); - } - cout << "Case " << ++i << ": " << sum << endl; - } - cin >> n >> d; - } - - return 0; -} diff --git a/POJ/POJ_1416.cpp b/POJ/POJ_1416.cpp deleted file mode 100644 index 3044f19..0000000 --- a/POJ/POJ_1416.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include -using namespace std; - -int have[20]; -int tar, num; -int len, MAX; -int pieces[100000], p_xb; -int true_pieces[100000], t_xb; - -bool Dfs(int pos, int sum) -{ - if (sum > tar) return false; - if (pos == len) { MAX = max(MAX, sum); return true;} - - bool flag = false; - for (int i = pos + 1; i <= len; i++) - { - int tmp = 0; - for (int j = pos + 1; j <= i; j++) tmp += have[j] * pow(10.0, double(j - pos - 1)); - if (Dfs(i, sum + tmp)) - { pieces[++p_xb] = tmp; flag = true;}; - } - return flag; -} -int main() -{ - cin >> tar >> num; - int i, j, k, tmp; - - while(tar != 0 || num != 0) - { - bool F = true; - if (tar == num) cout << num << " " << num << endl; - else if (tar >= num) cout << "error\n"; - else - { - int true_max = -1; - for (i = 1; num > 0; i++) // - { have[i] = num % 10; num /= 10;}; - len = i - 1; - - for (i = 1; i < len && F; i++) - { - p_xb = 0; - tmp = MAX = 0; - for (j = 1; j <= i; j++) - tmp += have[j] * pow(10.0, double(j - 1)); - if (Dfs(i, tmp)) - { - if (true_max == MAX) { cout << "rejected" << endl; F = false; break;} - else if (MAX > true_max) - { - pieces[++p_xb] = tmp; - t_xb = p_xb; - for (j = 1; j <= t_xb; j++) - true_pieces[j] = pieces[j]; - true_max = MAX; - } - } - } - if (F) - { - if (true_max == -1) cout << "error" << endl; - else - { - cout << true_max << " "; - for (j = 1; j <= t_xb; j++) cout << true_pieces[j] << " "; - cout << endl; - int x[10]; int x_xb = 0; int x_sum = 0; - for (j = t_xb; x_sum != len; j--) - { - x[++x_xb] = true_pieces[j]; - for (k = 1; true_pieces[j] > 0; k++) - true_pieces[j] /= 10; - x_sum += k - 1; - } - for (i = x_xb; i >= 1; i--) - cout << x[i] << " "; - cout << endl; - } - } - } - cin >> tar >> num; - } - return 0; -} diff --git a/POJ/POJ_1458.cpp b/POJ/POJ_1458.cpp deleted file mode 100644 index 8d46941..0000000 --- a/POJ/POJ_1458.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -using namespace std; - -int main() -{ - char A[1000], B[1000]; - - - - while(cin >> A >> B) - { - int lenA, lenB; - lenA = strlen(A); lenB = strlen(B); - - int **V = new int*[lenA + 1]; - for (int i = 0; i <= lenA; i++) - V[i] = new int[lenB + 1]; - for (int i = 0; i <= lenA; i++) - V[i][0] = 0; - for (int i = 0; i <= lenB; i++) - V[0][i] = 0; - - for (int i = 1; i <= lenA; i++) - for (int j = 1; j <= lenB; j++) - if (A[i - 1] == B[j - 1]) - V[i][j] = V[i - 1][j - 1] + 1; - else - V[i][j] = max(V[i - 1][j], V[i][j - 1]); - cout << V[lenA][lenB] << endl; - } - - return 0; -} diff --git a/POJ/POJ_1661.cpp b/POJ/POJ_1661.cpp deleted file mode 100644 index 5282cd8..0000000 --- a/POJ/POJ_1661.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -using namespace std; -struct node -{ - int x; - int y; - int h; -}; -bool myCompare(node A, node B){return A.h < B.h;}; -int main() -{ - int t, i, j, k, s; cin >> t; - int N; int MAX; - - for (i = 1; i <= t; i++) - { - cin >> N; - node* A = new node[N + 1]; - int *LeftMinTime = new int[N + 1]; - int *RightMinTime = new int[N + 1]; - - for (j = 0; j <= N; j++) - cin >> A[j].x >> A[j].y >> A[j].h; - MAX = A[0].h; A[0].h = A[0].y; A[0].y = A[0].x; - sort(A, A + N + 1, myCompare); - - for (j = 0; j <= N; j++) - { - for (k = j - 1; k >= 0; k--) - if (A[j].x >= A[k].x && A[j].x <= A[k].y) //ҵ˵ϵƽ̨ - break; - if (k == -1) //ûҵ - if (A[j].h > MAX) // - LeftMinTime[j] = 200000000; //ЧΪ - else LeftMinTime[j] = A[j].h; - else - if (A[j].h - A[k].h > MAX) - LeftMinTime[j] = 200000000; - else LeftMinTime[j] = A[j].h - A[k].h + min(LeftMinTime[k] + A[j].x - A[k].x, RightMinTime[k] + A[k].y - A[j].x); - - for (k = j - 1; k >= 0; k--) - if (A[j].y >= A[k].x && A[j].y <= A[k].y) //ҵҶ˵ϵƽ̨ - break; - if (k == -1) //ûҵ - if (A[j].h > MAX) // - RightMinTime[j] = 200000000; //ЧΪ - else RightMinTime[j] = A[j].h; - else - if (A[j].h - A[k].h > MAX) - RightMinTime[j] = 200000000; - else RightMinTime[j] = A[j].h - A[k].h + min(LeftMinTime[k] + A[j].y - A[k].x, RightMinTime[k] + A[k].y - A[j].y); - } - - cout << min(LeftMinTime[N], RightMinTime[N]) << endl; - } - return 0; -} diff --git a/POJ/POJ_1681.cpp b/POJ/POJ_1681.cpp deleted file mode 100644 index debdaf5..0000000 --- a/POJ/POJ_1681.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int t; cin >> t; - for (int i = 0; i < t; i++) - { - int N; cin >> N; - bool A[20][20]; //最大为15 * 15,扩容一行两列消除边界特殊情况; - int B[20][20]; - for (int j = 0; j <= N + 1; j++) B[0][j] = B[1][j] = B[j][0] = B[j][N + 1] = 0; //代表输入 - char tmp; - int min = 1000, sum = 0; - int pos = 1; - for (int i = 1; i <= N; i++) pos *= 2; - - for (int j = 0; j <= N + 1; j++) A[0][j] = A[j][0] = A[j][N + 1] = 0; //边界设置为0,代表白砖 - for (int i = 1; i <= N; i++) - for (int j = 1; j <= N; j++) - { - cin >> tmp; - if (tmp == 'w') A[i][j] = 0; - else A[i][j] = 1; - } - - for (int k = 1; k <= pos; k++) - { - for (int i = 2; i <= N + 1; i++) - { - for (int j = 1; j <= N; j++) - B[i][j] = (A[i - 1][j] + B[i - 1][j - 1] + B[i - 1][j + 1] + B[i - 1][j] + B[i - 2][j] + 1) % 2; - } - - int i; - for (i = 1; i <= N && B[N + 1][i] == 0; i++); - if (i > N) - { - sum = 0; - for (int i = 1; i <= N; i++) - for (int j = 1; j <= N; j++) - sum += B[i][j]; - if (sum < min) - { - /*for (int i = 1; i <= N; i++) - { - cout << endl; - for (int j = 1; j <= N; j++) - cout << B[i][j] << " "; - } */ - min = sum; - } - } - - B[1][1]++; - for (int i = 1; i < N && B[1][i] == 2; i++) - { - B[1][i] = 0; - B[1][i + 1] += 1; - } //产生第一行输入序列 - } - if (min != 1000) - cout << min << endl; - else - cout << "inf" << endl; - } - - return 0; -} \ No newline at end of file diff --git a/POJ/POJ_1753.cpp b/POJ/POJ_1753.cpp deleted file mode 100644 index d2e143d..0000000 --- a/POJ/POJ_1753.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -const int N = 4; -bool A[N + 2][N + 2]; -bool B[N + 2][N + 2]; -bool T[N + 2]; - -int main() -{ - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - char ch; int i, j, k, tmp; - - for (i = 1; i <= N; i++) - for (j = 1; j <= N; j++) - { - cin >> ch; - if (ch == 'b') A[i][j] = 1; //ɫ - else if (ch == 'w') A[i][j] = 0; //ɫ - } - - int MIN = 100000; - int M = pow(2.0, double(N)); - - //ȫ - for (i = 0; i < M; i++) - { - tmp = i; - for (j = 1; j <= N; j++) - { - B[1][j] = tmp % 2; - tmp /= 2; - } - for (j = 1; j <= N; j++) - T[j] = (A[1][j] + B[1][j - 1] + B[1][j] + B[1][j + 1]) % 2; - - for (j = 2; j <= N; j++) - { - for (k = 1; k <= N; k++) - B[j][k] = !T[k]; - for (k = 1; k <= N; k++) - T[k] = (A[j][k] + B[j - 1][k] + B[j][k] + B[j][k - 1] + B[j][k + 1]) % 2; - } - for (k = 1; k <= N && T[k] == 1; k++); - if (k > N) - { - tmp = 0; - for (j = 1; j <= N; j++) - for (k = 1; k <= N; k++) - tmp += B[j][k]; - MIN = min(MIN, tmp); - } - } - - //ȫ - for (i = 1; i <= N; i++) - for (j = 1; j <= N; j++) - A[i][j] = !A[i][j]; - - for (i = 0; i < M; i++) - { - tmp = i; - for (j = 1; j <= N; j++) - { - B[1][j] = tmp % 2; - tmp /= 2; - } - for (j = 1; j <= N; j++) - T[j] = (A[1][j] + B[1][j - 1] + B[1][j] + B[1][j + 1]) % 2; - - for (j = 2; j <= N; j++) - { - for (k = 1; k <= N; k++) - B[j][k] = !T[k]; - for (k = 1; k <= N; k++) - T[k] = (A[j][k] + B[j - 1][k] + B[j][k] + B[j][k - 1] + B[j][k + 1]) % 2; - } - for (k = 1; k <= N && T[k] == 1; k++); - if (k > N) - { - tmp = 0; - for (j = 1; j <= N; j++) - for (k = 1; k <= N; k++) - tmp += B[j][k]; - MIN = min(MIN, tmp); - } - } - - if (MIN != 100000) cout << MIN; - else cout << "Impossible"; - - return 0; -} diff --git a/POJ/POJ_2393.cpp b/POJ/POJ_2393.cpp deleted file mode 100644 index 85d622f..0000000 --- a/POJ/POJ_2393.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include - -using namespace std; - -int N, S; - -struct week -{ - int C; //λǮ - int Y; //Ҫ -}; -week A[10010]; - -int main() -{ - long long int money = 0; - int i, j; - - scanf("%d%d", &N, &S); - - for (i = 1; i <= N; i++) - scanf("%d%d", &A[i].C, &A[i].Y); - - for (i = 1; i <= N; i++) - { - money += A[i].C * A[i].Y; - for (j = i + 1; j <= N; j++) - { - if (A[i].C + (j - i) * S <= A[j].C) - money += (A[i].C + (j - i) * S) * A[j].Y; - else break; - } - i = j - 1; - } - cout << money; - return 0; -} diff --git a/POJ/POJ_2456.cpp b/POJ/POJ_2456.cpp deleted file mode 100644 index 0d47744..0000000 --- a/POJ/POJ_2456.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -using namespace std; - -int A[100010]; -int N, C; - -bool check(int ans) -{ - int sum = 1; - int last = A[1]; - - for (int i = 2; i <= N; i++) - { - if (A[i] - last >= ans) - { - ++sum; - last = A[i]; - } - if (sum >= C) return true; - } - return false; -} -int main() -{ - scanf("%d%d", &N, &C); - - A[0] = 0; - int l = 200000000, r = 0; - for (int i = 1; i <= N; i++) - { - scanf("%d", &A[i]); - l = min(l, A[i] - A[i - 1]); - } - sort(A + 1, A + N + 1); - r = A[N] - A[1]; - int mid; - - while(l <= r) - { - mid = (l + r) / 2; - if (check(mid)) l = mid + 1; - else r = mid - 1; - } - cout << r; - return 0; -} diff --git a/POJ/POJ_2488.cpp b/POJ/POJ_2488.cpp deleted file mode 100644 index 40ae4fc..0000000 --- a/POJ/POJ_2488.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -using namespace std; -int board[30][30]; -struct node -{ - char ch; - int num; -}; -node road[100]; -int xb = 0; -int N, p, q; - -bool Dfs(int x, int y, int total) -{ - if (x <= 0 || x > p || y <= 0 || y > q) return false; - if (board[x][y] == 1) return false; - if (total == N) return true; - - board[x][y] = 1; - - if (Dfs(x - 1, y - 2, total + 1)) {++xb; road[xb].ch = y - 2 + 'A' - 1; road[xb].num = x - 1; return true;} - if (Dfs(x + 1, y - 2, total + 1)) {++xb; road[xb].ch = y - 2 + 'A' - 1; road[xb].num = x + 1; return true;} - if (Dfs(x - 2, y - 1, total + 1)) {++xb; road[xb].ch = y - 1 + 'A' - 1; road[xb].num = x - 2; return true;} - if (Dfs(x + 2, y - 1, total + 1)) {++xb; road[xb].ch = y - 1 + 'A' - 1; road[xb].num = x + 2; return true;} - if (Dfs(x - 2, y + 1, total + 1)) {++xb; road[xb].ch = y + 1 + 'A' - 1; road[xb].num = x - 2; return true;} - if (Dfs(x + 2, y + 1, total + 1)) {++xb; road[xb].ch = y + 1 + 'A' - 1; road[xb].num = x + 2; return true;} - if (Dfs(x - 1, y + 2, total + 1)) {++xb; road[xb].ch = y + 2 + 'A' - 1; road[xb].num = x - 1; return true;} - if (Dfs(x + 1, y + 2, total + 1)) {++xb; road[xb].ch = y + 2 + 'A' - 1; road[xb].num = x + 1; return true;} - - board[x][y] = 0; - return false; -} - -int main() -{ - int t; cin >> t; - int r_xb = 0; - for (int k = 1; k <= t; k++) - { - cin >> p >> q; - N = p * q; //ܹҪ߹ٸ - - cout << "Scenario #" << k << ":" << endl; - bool flag = true; - - for (int i = 1; i <= p && flag; i++) - for (int j = 1; j <= q; j++) - { - memset(board, 0, sizeof(board)); - xb = 1; - road[xb].ch = i + 'A' - 1; - road[xb].num = j; - - if (Dfs(i, j, 1)) - { - - cout << road[1].ch << road[i].num; - for (int i = xb; i > 1; i--) - cout << road[i].ch << road[i].num; - cout << endl; - flag = false; - break; - } - } - if (flag) cout << "impossible" << endl; - cout << endl; - } - - return 0; -} diff --git a/POJ/POJ_3104.cpp b/POJ/POJ_3104.cpp deleted file mode 100644 index 8d39f1b..0000000 --- a/POJ/POJ_3104.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[100010]; -long long int n, k; -bool myCompare(long long int A, long long int B){return A > B;}; -bool check(long long int mid) -{ - long long int sum = 0; - for (int i = 1; i <= n && A[i] > mid; i++) - { - sum += (A[i] - mid - 1) / (k - 1) + 1; - if (sum > mid) return false; - } - return true; -} -int main() -{ - cin >> n; - long long int l = 1, r = 1; - for (int i = 1; i <= n; i++) - { - scanf("%lld", &A[i]); - if (A[i] > r) r = A[i]; - } - cin >> k; - - if (k == 1) { cout << r; return 0;} - - sort(A + 1, A + n + 1, myCompare); - - long long int mid = 0; - while(l <= r) - { - mid = (l + r) / 2; - if (check(mid)) r = mid - 1; - else l = mid + 1; - } - cout << l; - return 0; -} diff --git a/POJ/POJ_3278.cpp b/POJ/POJ_3278.cpp deleted file mode 100644 index b7acac1..0000000 --- a/POJ/POJ_3278.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -using namespace std; - -bool whether[100010]; -struct node -{ - int x; // - int steps; //ĿǰߵIJ - node(int xx, int s):x(xx), steps(s){}; -}; -queue A; - -int main() -{ - int N, K; cin >> N >> K; - int tmp_x, tmp_steps; - memset(whether, 0, sizeof(whether)); - - A.push(node(N, 0)); whether[N] = 1; - - while(!A.empty()) - { - tmp_x = A.front().x; - tmp_steps = A.front().steps; - - if (tmp_x == K) - { cout << tmp_steps; return 0;} - if (tmp_x - 1 >= 0 && !whether[tmp_x - 1]) - { A.push(node(tmp_x - 1, tmp_steps + 1)); whether[tmp_x - 1] = 1;} - if (tmp_x + 1 <= 100000 && !whether[tmp_x + 1]) - { A.push(node(tmp_x + 1, tmp_steps + 1)); whether[tmp_x + 1] = 1;} - if (2 * tmp_x <= 100000 && !whether[2 * tmp_x]) - { A.push(node(2 * tmp_x, tmp_steps + 1)); whether[2 * tmp_x] = 1;} - A.pop(); - } - return 0; -} diff --git a/POJ/POJ_3624.cpp b/POJ/POJ_3624.cpp deleted file mode 100644 index 6c96237..0000000 --- a/POJ/POJ_3624.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int W; //Ȩֵ - int D; // -}; -node A[3500]; -int B[15200]; -bool myCompare(node A, node B){return A.W < B.W;}; - -int main() -{ - int N, M; cin >> N >> M; - int i, j; - - for (i = 1; i <= N; i++) - cin >> A[i].W >> A[i].D; - sort(A + 1, A + N + 1, myCompare); - for (i = 1; i <= 15000; i++) B[i] = 0; - - for (int i = 1; i <= N; i++) - { - int x = A[i].W; - if (B[x] != 0 && x < 7000) B[2 * x] = max(B[2 * x], B[x] + A[i].D); - if (B[x] > A[i].D) continue; - B[x] = A[i].D; - for (int j = 1; j <= x - 1 && x + j < 13000; j++) - B[x + j] = max(B[x + j], B[x] + B[j]); - } - cout << *max_element(B + 1, B + M + 1); - return 0; -} diff --git a/POJ/POJ_3984.cpp b/POJ/POJ_3984.cpp deleted file mode 100644 index 16a0bb9..0000000 --- a/POJ/POJ_3984.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int x; - int y; -}; -int maze[5][5]; -node A[50]; -int xb = 0; - -bool Dfs(int x, int y) -{ - if (x == 4 && y == 4) return true; - if (x < 0 || x >= 5 || y < 0 || y >= 5) return false; - if (maze[x][y] == 1) return false; - - if (Dfs(x, y + 1)) { xb++; A[xb].x = x; A[xb].y = y + 1; return true;} - if (Dfs(x + 1, y)) { xb++; A[xb].x = x + 1; A[xb].y = y; return true;} - if (Dfs(x - 1, y)) { xb++; A[xb].x = x - 1; A[xb].y = y; return true;} - if (Dfs(x, y - 1)) { xb++; A[xb].x = x; A[xb].y = y - 1; return true;} - -} -int main() -{ - for (int i = 0; i < 5; i++) - for (int j = 0; j < 5; j++) - cin >> maze[i][j]; - - Dfs(0, 0); xb++; A[xb].x = 0; A[xb].y = 0; - - for (int i = xb; i >= 1; i--) - cout << "(" << A[i].x << ", " << A[i].y << ")" << endl; - return 0; -} diff --git a/README.md b/README.md index 802b483..6178284 100644 --- a/README.md +++ b/README.md @@ -797,6 +797,10 @@ | 698 | [使每位学生都有座位的最少移动次数 - Minimum Number of Moves to Seat Everyone](https://leetcode.cn/problems/minimum-number-of-moves-to-seat-everyone/) | [C++](https://github.com/WilliamX1/leetcode/blob/main/Solutions/Minimum-Number-of-Moves-to-Seat-Everyone.cpp) | Easy | 2022.5.19 | | 699 | [网络空闲的时刻 - The Time When the Network Becomes Idle](https://leetcode.cn/problems/the-time-when-the-network-becomes-idle/) | [C++](https://github.com/WilliamX1/leetcode/blob/main/Solutions/The-Time-When-the-Network-Becomes-Idle.cpp) | Middle | 2022.5.19 | | 700 | [两个有序数组的第 K 小乘积 - Kth Smallest Product of Two Sorted Arrays](https://leetcode.cn/problems/kth-smallest-product-of-two-sorted-arrays/comments/) | [C++](https://github.com/WilliamX1/leetcode/blob/main/Solutions/Kth-Smallest-Product-of-Two-Sorted-Arrays.cpp) | Hard | 2022.5.19 | +| 701 | [前 K 个高频元素 - Top K Frequent Elements](https://leetcode.cn/problems/top-k-frequent-elements/) | [C++](https://github.com/WilliamX1/leetcode/blob/main/Solutions/Top-K-Frequent-Elements.cpp) | Middle | 2022.5.20 | +| 702 | [最长递增子序列 - Longest Increasing Subsequence](https://leetcode.cn/problems/longest-increasing-subsequence/) | [C++](https://github.com/WilliamX1/leetcode/blob/main/Solutions/Longest-Increasing-Subsequence.cpp) | Middle | 2022.5.20 | +| 703 | [打家劫舍 III - House Robber III](https://leetcode.cn/problems/house-robber-iii/) | [C++](https://github.com/WilliamX1/leetcode/blob/main/Solutions/House-Robber-III.cpp) | Middle | 2022.5.20 | +| 704 | [零钱兑换 - Coin Change](https://leetcode.cn/problems/coin-change/) | [C++](https://github.com/WilliamX1/leetcode/blob/main/Solutions/Coin-Change.cpp) | Middle | 2022.5.20 | diff --git a/SJTUOJ/1000.cpp b/SJTUOJ/1000.cpp deleted file mode 100644 index a4025ae..0000000 --- a/SJTUOJ/1000.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n1, n2; cin >> n1 >> n2; - cout << n1 + n2; - return 0; -} diff --git a/SJTUOJ/1001.cpp b/SJTUOJ/1001.cpp deleted file mode 100644 index 57ba07f..0000000 --- a/SJTUOJ/1001.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n1, n2, n3; cin >> n1 >> n2 >> n3; - int sum = 0; - n1 += n2; - - for (int i = 1; i <= n3; i++) - { - cin >> n2; - if (n2 <= n1) ++sum; - } - cout << sum; - return 0; -} diff --git a/SJTUOJ/1002.cpp b/SJTUOJ/1002.cpp deleted file mode 100644 index a2f2d36..0000000 --- a/SJTUOJ/1002.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -using namespace std; -int A[1010][1010]; - -int B[1010][1010]; -int C[1010][1010]; - -int main() -{ - int L, W; scanf("%d%d", &L, &W); - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - memset(C, 0, sizeof(C)); - - for (int i = 1; i <= L; i++) - for (int j = 1; j <= W; j++) - scanf("%d", &A[i][j]); - int n1, n2; scanf("%d%d", &n1, &n2); - int MAX = 0; - - for (int i = 1; i <= L; i++) - { - B[i][1] = 0; - for (int j = 1; j <= n2; j++) - B[i][1] += A[i][j]; - } - - for (int i = 1; i <= L; i++) - for (int j = 2; j <= W; j++) - B[i][j] = B[i][j - 1] - A[i][j - 1] + A[i][j + n2 - 1]; - - for (int j = 1; j <= W; j++) - { - C[1][j] = 0; - for (int i = 1; i <= n1; i++) - C[1][j] += B[i][j]; - } - - for (int j = 1; j <= W; j++) - for (int i = 2; i <= W; i++) - C[i][j] = C[i - 1][j] - B[i - 1][j] + B[i + n1 - 1][j]; - - for (int i = 1; i <= L; i++) - for (int j = 1; j <= W; j++) - MAX = max(MAX, C[i][j]); - - cout << MAX; - return 0; -} diff --git a/SJTUOJ/1003.cpp b/SJTUOJ/1003.cpp deleted file mode 100644 index 2ab3f5a..0000000 --- a/SJTUOJ/1003.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[110][110]; -struct node -{ - int x; - int y; - int label; - node(int t_x, int t_y, int t_l) - :x(t_x), y(t_y), label(t_l){}; - node(){}; -}; - -int main() -{ - int L; cin >> L; - int need = 0; - - queue q; - - //ʼ - for (int i = 0; i <= L + 1; i++) - A[0][i] = A[L + 1][i] = A[i][0] = A[i][L + 1] = 1; - - for (int i = 1; i <= L; i++) - for (int j = 1; j <= L; j++) - { - cin >> A[i][j]; - if (A[i][j] == 0) ++need; - else if (A[i][j] == 1) q.push(node(i, j, 1));; - } - - // - node cur; - while(need > 0) - { - cur = q.front(); - q.pop(); - if (A[cur.x - 1][cur.y] == 0) - { - q.push(node(cur.x - 1, cur.y, cur.label + 1)); - A[cur.x - 1][cur.y] = 1; - need--; - } - if (A[cur.x + 1][cur.y] == 0) - { - q.push(node(cur.x + 1, cur.y, cur.label + 1)); - A[cur.x + 1][cur.y] = 1; - need--; - } - if (A[cur.x][cur.y - 1] == 0) - { - q.push(node(cur.x, cur.y - 1, cur.label + 1)); - A[cur.x][cur.y - 1] = 1; - need--; - } - if (A[cur.x][cur.y + 1] == 0) - { - q.push(node(cur.x, cur.y + 1, cur.label + 1)); - A[cur.x][cur.y + 1] = 1; - need--; - } - } - cout << cur.label; - - return 0; -} diff --git a/SJTUOJ/1004.cpp b/SJTUOJ/1004.cpp deleted file mode 100644 index ae5c5b2..0000000 --- a/SJTUOJ/1004.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -using namespace std; - -int main() -{ - int M, T, U, F, D; cin >> M >> T >> U >> F >> D; - char* A = new char[T + 1]; - int sum = 0; - for (int i = 1; i <= T; i++) - cin >> A[i]; - for (int i = 1; i <= T; i++) - { - if (A[i] == 'u' || A[i] == 'd') - sum += U + D; - else if (A[i] == 'f') - sum += 2 * F; - if (sum > M) - { - cout << i - 1; - break; - } - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1005.cpp b/SJTUOJ/1005.cpp deleted file mode 100644 index 597b296..0000000 --- a/SJTUOJ/1005.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -using namespace std; - -int A[10][10]; -int B[10]; - -int main() -{ - int n; cin >> n; - - while(n-- > 0) - { - - bool flag = true; - - for (int i = 1; i <= 9; i++) - for (int j = 1; j <= 9; j++) - scanf("%d", &A[i][j]); - - //֤ - for (int i = 1; i <= 9 && flag; i++) - { - memset(B, 0, sizeof(B)); - for (int j = 1; j <= 9; j++) - if (B[A[i][j]] == 1) - { - flag = false; - break; - } - else B[A[i][j]] = 1; - } - - //֤ - for (int j = 1; j <= 9 && flag; j++) - { - memset(B, 0, sizeof(B)); - for (int i = 1; i <= 9; i++) - if (B[A[i][j]] == 1) - { - flag = false; - break; - } - else B[A[i][j]] = 1; - } - - //֤ - for (int i = 1; i <= 9 && flag; i += 3) - { - for (int j = 1; j <= 9 && flag; j += 3) - { - memset(B, 0, sizeof(B)); - for (int k = 0; k < 3; k++) - for (int s = 0; s < 3; s++) - if (B[A[i + k][j + s]] == 1) - { - flag = false; - break; - } - else B[A[i + k][j + s]] = 1; - - } - } - - if (flag) cout << "Right" << endl; - else cout << "Wrong" << endl; - - } - return 0; -} diff --git a/SJTUOJ/1006.cpp b/SJTUOJ/1006.cpp deleted file mode 100644 index 6c62824..0000000 --- a/SJTUOJ/1006.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -using namespace std; -int A[4010000]; - -int main() -{ - - int n; - - while(scanf("%d",&n) != EOF) - { - for (int i = 1; i <= n; i++) - cin >> A[i]; - if (n == 1 || n == 0 || n == 2) cout << "Game Over"; - - else - { - int MAX = A[1]; - - for (int i = 2; i <= n; i++) - if (A[i - 1] > 0) - { - A[i] += A[i - 1]; - if (A[i] > MAX) MAX = A[i]; - } - if (MAX <= 0) cout << "Game Over"; - else cout << MAX << endl; - } - } - - return 0; -} diff --git a/SJTUOJ/1007.cpp b/SJTUOJ/1007.cpp deleted file mode 100644 index 86262e1..0000000 --- a/SJTUOJ/1007.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -using namespace std; - - -int main() -{ - string a, b; - int result[210]; - cin >> a >> b; - - int len_A = a.length(); - int len_B = b.length(); - - int A[210], B[210]; - for (int i = 0; i < len_A; i++) - A[i] = a[len_A - i - 1] - '0'; - for (int i = 0; i < len_B; i++) - B[i] = b[len_B - i - 1] - '0'; - - int M = max(len_A, len_B); - int m = min(len_A, len_B); - - for (int i = len_A; i < M; i++) - A[i] = 0; - for (int i = len_B; i < M; i++) - B[i] = 0; - - int yushu = 0; - - for (int i = 0; i < M; i++) - { - if (i == 2) continue; - - result[i] = A[i] + B[i] + yushu; - if (result[i] >= 10) - { - yushu = 1; - result[i] -= 10; - } else yushu = 0; - } - - if (yushu == 1) - cout << 1; - for (int i = M - 1; i >= 0; i--) - { - if (i == 2) cout << '.'; - else cout << result[i]; - } - return 0; -} diff --git a/SJTUOJ/1010.cpp b/SJTUOJ/1010.cpp deleted file mode 100644 index f53a94e..0000000 --- a/SJTUOJ/1010.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int Month[13]; - for (int i = 1; i <= 12; i++) cin >> Month[i]; - - int remain = 0; - int res = 0; - for (int i = 1; i <= 12; i++){ - remain += 300; - if (remain < Month[i]){ - cout << '-' << i; - return 0; - } - res += (remain - Month[i]) / 100; - remain = (remain - Month[i]) % 100; - } - cout << res * 100 * (1 + 0.2) + remain; - return 0; -} diff --git a/SJTUOJ/1011.cpp b/SJTUOJ/1011.cpp deleted file mode 100644 index c64a002..0000000 --- a/SJTUOJ/1011.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include - -using namespace std; - -class MyComplex -{ -private: - double x, y; -public: - MyComplex(double t_x, double t_y):x(t_x), y(t_y){}; - MyComplex(){}; - friend MyComplex operator+(const MyComplex z1, const MyComplex z2) - { - double x = z1.x + z2.x; - double y = z1.y + z2.y; - return MyComplex(x, y); - }; - friend MyComplex operator-(const MyComplex z1, const MyComplex z2) - { - double x = z1.x - z2.x; - double y = z1.y - z2.y; - return MyComplex(x, y); - }; - friend MyComplex operator*(const MyComplex z1, const MyComplex z2) - { - double x = z1.x * z2.x - z1.y * z2.y; - double y = z1.x * z2.y + z1.y * z2.x; - return MyComplex(x, y); - }; - friend MyComplex operator/(const MyComplex z1, const MyComplex z2) - { - double c2d2 = z2.x * z2.x + z2.y * z2.y; - double x = z1.x * z2.x + z1.y * z2.y; x /= c2d2; - double y = z1.y * z2.x - z1.x * z2.y; y /= c2d2; - return MyComplex(x, y); - }; - MyComplex operator+=(const MyComplex z2) - { - x += z2.x; - y += z2.y; - return *this; - }; - MyComplex operator-=(const MyComplex z2) - { - x -= z2.x; - y -= z2.y; - return *this; - }; - MyComplex operator*=(const MyComplex z2) - { - double t_x = x * z2.x - y * z2.y; - double t_y = x * z2.y + y * z2.x; - x = t_x, y = t_y; - return *this; - }; - MyComplex operator/=(const MyComplex z2) - { - double c2d2 = z2.x * z2.x + z2.y * z2.y; - double t_x = (x * z2.x + y * z2.y) / c2d2; - double t_y = (y * z2.x - x * z2.y) / c2d2; - x = t_x, y = t_y; - return *this; - }; - friend ostream& operator<<(ostream& out, const MyComplex z) - { - printf("%.2f %.2f", z.x, z.y); - return out; - }; - friend istream& operator>>(istream& in, MyComplex& z) - { - in >> z.x >> z.y; - return in; - }; -}; - -int main() -{ - MyComplex z1; - MyComplex z2; - - cin >> z1 >> z2; - - cout << z1 + z2 << endl; - cout << z1 - z2 << endl; - cout << z1 * z2 << endl; - cout << z1 / z2 << endl; - cout << (z1 += z2) << endl; - cout << (z1 -= z2) << endl; - cout << (z1 *= z2) << endl; - cout << (z1 /= z2) << endl; - - return 0; -} diff --git a/SJTUOJ/1013.cpp b/SJTUOJ/1013.cpp deleted file mode 100644 index 6eaae8f..0000000 --- a/SJTUOJ/1013.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -using namespace std; - -long long C[100024]; -long long W[100024]; -long long dp[10010]; - -int main() -{ - int V, N; scanf("%d%d", &V, &N); - for (int i = 1; i <= N; i++) - scanf("%lld%lld", &C[i], &W[i]); - - int index = N; - long long cifang[20]; cifang[0] = 1; - for (int i = 1; i < 18; i++) cifang[i] = cifang[i - 1] * 2; - for (int i = 1; i <= N; i++) - for (int j = 1; C[i] * cifang[j] <= V; j++) - { - ++index; - C[index] = C[i] * cifang[j]; - W[index] = W[i] * cifang[j]; - } - - memset(dp, 0, sizeof(dp)); - - for (int i = 1; i <= index; i++) - for (int j = C[i]; j <= V; j++) - dp[j] = max(dp[j], dp[j - C[i]] + W[i]); - cout << dp[V]; - - return 0; -} diff --git a/SJTUOJ/1014.cpp b/SJTUOJ/1014.cpp deleted file mode 100644 index d0010f4..0000000 --- a/SJTUOJ/1014.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int A[100010], B[100010], result[100010]; - string a, b; cin >> a >> b; - int len_A = a.length(); - int len_B = b.length(); - - int M = max(len_A, len_B); - - for (int i = 0; i < len_A; i++) - A[i] = a[len_A - i - 1] - '0'; - for (int i = 0; i < len_B; i++) - B[i] = b[len_B - i - 1] - '0'; - for (int i = len_A; i < M; i++) - A[i] = 0; - for (int i = len_B; i < M; i++) - B[i] = 0; - - int yushu = 0; - for (int i = 0; i < M; i++) - { - result[i] = A[i] + B[i] + yushu; - if (result[i] >= 10) - { - result[i] -= 10; - yushu = 1; - }else yushu = 0; - } - - if (yushu == 1) cout << 1; - for (int i = M - 1; i >= 0; i--) - cout << result[i]; - - return 0; -} diff --git a/SJTUOJ/1015.cpp b/SJTUOJ/1015.cpp deleted file mode 100644 index 325ee82..0000000 --- a/SJTUOJ/1015.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - string a, b; cin >> a >> b; - int lenA = a.length(), lenB = b.length(); - int A[1024], B[1024]; - for (int i = 0; i < lenA; i++) A[i] = a[lenA - i - 1] - '0'; - for (int i = 0; i < lenB; i++) B[i] = b[lenB - i - 1] - '0'; - - int res[1024]; - memset(res, 0, sizeof(res)); - - for (int i = 0; i < lenA; i++) - for (int j = 0; j < lenB; j++) - res[i + j] += A[i] * B[j]; - - int yushu = 0; - for (int i = 0; i < lenA + lenB; i++) - { - res[i] += yushu; - yushu = res[i] / 10; - res[i] %= 10; - } - int cur = lenA + lenB; - while(cur > 0 && !res[cur]) cur--; - - for (int i = cur; i >= 0; i--) - printf("%d", res[i]); - - return 0; -} diff --git a/SJTUOJ/1018.cpp b/SJTUOJ/1018.cpp deleted file mode 100644 index 07974a2..0000000 --- a/SJTUOJ/1018.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int a, b; - while (cin >> a >> b) cout << a + b << endl; - return 0; -} diff --git a/SJTUOJ/1019.cpp b/SJTUOJ/1019.cpp deleted file mode 100644 index ddfe6b2..0000000 --- a/SJTUOJ/1019.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int T; cin >> T; - - string str; - - for (int i = 0; i < T; i++) - { - stack q; - - cin >> str; - - for (int j = 0; str[j] != '\0'; ++j) - { - if (q.empty()) q.push(str[j]); - else - if (q.top() == '(' && str[j] == ')') - q.pop(); - else - q.push(str[j]); - } - if (q.empty()) cout << "YES" << endl; - else cout << "NO" << endl; - } - return 0; -} diff --git a/SJTUOJ/1020.cpp b/SJTUOJ/1020.cpp deleted file mode 100644 index 54e63e5..0000000 --- a/SJTUOJ/1020.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -int A[100010]; - -int main() -{ - int A_xb = -1; - A[++A_xb] = 2; - - int i, j; - int N; cin >> N; - - for (i = 3; i <= sqrt(N) + 2; i++) - { - for (j = 0; j <= A_xb && (i % A[j]) != 0; j++); - if (j > A_xb) A[++A_xb] = i; - } - - - int sum = 0; cout << N << "="; - - for (int i = 0; i <= A_xb; i++) - { - if (N % A[i] == 0) - { - if (sum == 0) - cout << A[i]; - sum++; - N /= A[i]; - i--; - } - else if (sum != 0) - { - cout << "(" << sum << ")"; - sum = 0; - } - } - - if (N != 1) cout << N << "(1)"; - return 0; -} diff --git a/SJTUOJ/1021.cpp b/SJTUOJ/1021.cpp deleted file mode 100644 index df1c018..0000000 --- a/SJTUOJ/1021.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int n; cin >> n; - int **A = new int*[n + 1]; - for (int i = 0; i <= n; i++) - A[i] = new int[n + 1]; - A[1][1] = 1; - int x_min = 1, x_max = n, y_min = 1, y_max = n; - int dir = 1; //0上 1左 2下 3右 - int xcur = 1, ycur = 2; - for (int i = 2; i <= n*n; i++) - { - if (xcur == x_min && ycur == y_min && dir == 0) - { - y_min++; dir = (++dir) % 4; - } - else if (xcur == x_min && ycur == y_max && dir == 1) - { - x_min++; dir = (++dir) % 4; - } - else if (xcur == x_max && ycur == y_min && dir == 3) - { - x_max--; dir = (++dir) % 4; - } - else if (xcur == x_max && ycur == y_max && dir == 2) - { - y_max--; dir = (++dir) % 4; - }; - A[xcur][ycur] = i; - switch (dir) - { - case 0:xcur--; break; - case 1:ycur++; break; - case 2:xcur++; break; - case 3:ycur--; break; - } - } - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - cout << setw(6) << A[i][j]; - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1022.cpp b/SJTUOJ/1022.cpp deleted file mode 100644 index 304a0ed..0000000 --- a/SJTUOJ/1022.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include - -using namespace std; - -const long long Mod = 2010; -long long base[3][3]; -long long res[3]; -void matrix_self_mul(long long A[][3]) -{ - long long A11 = (A[1][1] * A[1][1] + A[1][2] * A[2][1]) % Mod; - long long A12 = (A[1][1] * A[1][2] + A[1][2] * A[2][2]) % Mod; - long long A21 = (A[2][1] * A[1][1] + A[2][2] * A[2][1]) % Mod; - long long A22 = (A[2][1] * A[1][2] + A[2][2] * A[2][2]) % Mod; - A[1][1] = A11; A[1][2] = A12; A[2][1] = A21; A[2][2] = A22; - return; -} -void matrix_mul(long long A[][3], long long B[]) -{ - long long B1 = (A[1][1] * B[1] + A[1][2] * B[2]) % Mod; - long long B2 = (A[2][1] * B[1] + A[2][2] * B[2]) % Mod; - B[1] = B1; - B[2] = B2; - return; -} -long long fastPower(long long n) -{ - if (n <= 2) return 1; - - res[1] = res[2] = 1; - base[1][1] = base[1][2] = base[2][1] = 1; base[2][2] = 0; - - n -= 2; - while(n > 0) - { - if (n & 1) - matrix_mul(base, res); - matrix_self_mul(base); - n = n >> 1; - } - return res[1]; -} -int main() -{ - long long n; scanf("%lld", &n); - printf("%lld", fastPower(n)); - return 0; -} diff --git a/SJTUOJ/1023.cpp b/SJTUOJ/1023.cpp deleted file mode 100644 index bebc5c3..0000000 --- a/SJTUOJ/1023.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; -int A[610][610]; -int main() -{ - int n; cin >> n; - int a, b; - for (int i = 1; i <= n; i++) - { - scanf("%d%d", &a, &b); - for (int j = 1; j <= a; j++) - for (int k = 1; k <= a; k++) - scanf("%d", &A[j][k]); - if (b == 0) - for (int j = 1; j <= a; j++) - { - for (int k = a; k >= 1; k--) - printf("%d ", A[j][k]); - printf("\n"); - } - else if (b == 1) - for (int j = a; j >= 1; j--) - { - for (int k = 1; k <= a; k++) - printf("%d ", A[j][k]); - printf("\n"); - } - else if (b == 2) - for (int j = 1; j <= a; j++) - { - for (int k = 1; k <= a; k++) - printf("%d ", A[k][j]); - printf("\n"); - } - - - - } - return 0; -} diff --git a/SJTUOJ/1024.cpp b/SJTUOJ/1024.cpp deleted file mode 100644 index 0024bdc..0000000 --- a/SJTUOJ/1024.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -using namespace std; -int A[10010]; - -int main() -{ - int n; cin >> n; - for (int i = 0; i < n; i++) - scanf("%d", &A[i]); - sort(A, A + n); - for (int i = 0; i < n; i++) - printf("%d ", A[i]); - return 0; -} diff --git a/SJTUOJ/1025.cpp b/SJTUOJ/1025.cpp deleted file mode 100644 index cde40ca..0000000 --- a/SJTUOJ/1025.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int x1; - int x2; -}; -node A[20010]; -bool myCompare(node A, node B){return A.x1 < B.x1;}; - -int main() -{ - int N; cin >> N; - - for (int i = 0; i < N; i++) - scanf("%d%d", &A[i].x1, &A[i].x2); - - sort(A, A + N, myCompare); - int l = A[0].x1, r = A[0].x2; - int sum = 0; - for (int i = 1; i < N; i++) - if (A[i].x1 <= r) - { - if (A[i].x2 > r) - r = A[i].x2; - } - else - { - sum += r - l; - l = A[i].x1; - r = A[i].x2; - } - cout << sum + r - l; - return 0; -} diff --git a/SJTUOJ/1028.cpp b/SJTUOJ/1028.cpp deleted file mode 100644 index ba46aae..0000000 --- a/SJTUOJ/1028.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -using namespace std; - -int to(string A) -{ - if (A == "begin") return 0; - if (A == "end") return 1; - if (A == "if") return 2; - if (A == "then") return 3; - if (A == "else") return 4; -} -int main() -{ - string tmp; - stack q; - - int N; cin >> N; - int ch; - bool flag = true; - - for (int i = 0; i < N; i++) - { - cin >> tmp; - ch = to(tmp); - - if (q.empty()) q.push(ch); - else - { - if (ch == 0) - { - if (q.top() == 2) {flag = false; break;} - q.push(ch); - } - else if (ch == 1) - { - if (!q.empty() && q.top() == 3) {q.pop(); q.pop();} - if (!q.empty() && q.top() == 0) q.pop(); - else {flag = false; break;} - } - else if (ch == 2) - q.push(ch); - else if (ch == 3) - { - if (q.top() != 2) {flag = false; break;}; - q.push(ch); - } - else if (ch == 4) - if (q.top() == 3) {q.pop(); q.pop();} - else {flag = false;break;} - } - } - while(!q.empty() && q.top() == 3) - { - q.pop(); - if (!q.empty() && q.top() == 2) - q.pop(); - else{ - flag = false; - break; - } - } - - if (flag && q.empty()) cout << "YES"; - else cout << "NO"; - - return 0; -} diff --git a/SJTUOJ/1032.cpp b/SJTUOJ/1032.cpp deleted file mode 100644 index c9b0b1b..0000000 --- a/SJTUOJ/1032.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -using namespace std; - -int A(int m, int n) -{ - if (m == 0) - return ++n; - else if (n == 0) - return A(m - 1, 1); - else - return A(m - 1, A(m, n - 1)); -} -int main() -{ - int m, n;cin >> m >> n; - //if (m == 0) - // cout << n + 1; - // else if (m == 1) - // cout << n + 2; - // else if (m == 2) - // cout << n + 3; - // else if (m == 3) - cout << A(m,n); - return 0; -} diff --git a/SJTUOJ/1034.cpp b/SJTUOJ/1034.cpp deleted file mode 100644 index ce62257..0000000 --- a/SJTUOJ/1034.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - -using namespace std; - -int A[200010]; -int main() -{ - int N, K; scanf("%d%d", &N, &K); - - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - for (int i = 1; i < K; i++) - A[N + i] = A[i]; - - int last = 0; - for (int i = 1; i <= K; i++) - if (A[i] > last) last = A[i]; - - int MIN = last; - for (int i = 1; i < N; i++) - { - if (last != A[i]) - { - if (A[i + K] > last) last = A[i + K]; - if (last < MIN) MIN = last; - } - else - { - last = A[i + 1]; - for (int j = 1; j < K; j++) - if (A[j + i + 1] > last) last = A[j + i + 1]; - if (last < MIN) MIN = last; - } - } - cout << MIN; - /*for (int i = 2; i <= K; i++) - for (int j = 1; j <= N + K - i; j++) - if (A[j] < A[j + 1]) A[j] = A[j + 1]; - - int MIN = 1e9; - for (int i = 1; i <= N; i++) - if (A[i] < MIN) MIN = A[i]; - printf("%d", MIN);*/ - - return 0; -} diff --git a/SJTUOJ/1035.cpp b/SJTUOJ/1035.cpp deleted file mode 100644 index 5bc75ec..0000000 --- a/SJTUOJ/1035.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int num; - int x; -}; - -node A[20010]; -int B[20010]; -bool myCompare(node A, node B) -{ - if (A.x == B.x) return A.num < B.num; - return A.x > B.x; -}; -int main() -{ - int N; scanf("%d", &N); - for (int i = 1; i <= N; i++) - scanf("%d", &B[i]); - - int K, tmp, x, y, i, j; cin >> K; - char ch; - for (i = 1; i <= K; i++) - { - cin >> ch; - - if (ch == 'Q') - { - for (j = 1; j <= N; j++) - { A[j].num = j; A[j].x = B[j];} - - sort(A + 1, A + N + 1, myCompare); - scanf("%d", &tmp); - for (j = 1; j <= tmp; j++) - { - scanf("%d", &x); - printf("%d ", A[x].num); - } - printf("\n"); - } - else - { - scanf("%d%d", &x, &y); - B[x] = y; - } - } - - return 0; -} diff --git a/SJTUOJ/1037.cpp b/SJTUOJ/1037.cpp deleted file mode 100644 index 42ba9c1..0000000 --- a/SJTUOJ/1037.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -using namespace std; - -int A[10010]; -int B[10010]; -bool myCompare(int A, int B){return A > B;}; -int main() -{ - int N, M; cin >> N >> M; - for (int i = 1; i <= N; i++) - cin >> A[i]; - for (int i = 1; i <= M; i++) - cin >> B[i]; - - sort(A + 1, A + N + 1, myCompare); - sort(B + 1, B + M + 1, myCompare); - - int i, j; - int sum = N; - for (i = 1; i <= N; i++) - { - for (j = 1; j <= M && B[j] >= A[i]; j++); - if (j <= M) {B[j] = 1e9; sum++;}; - } - cout << sum; - return 0; -} diff --git a/SJTUOJ/1038.cpp b/SJTUOJ/1038.cpp deleted file mode 100644 index 5722d5b..0000000 --- a/SJTUOJ/1038.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include - -using namespace std; - -int M, j; - -class linkList -{ -private: - struct node - { - int num; - node* next; - node* pre; - node(int n, node* p = NULL, node* N = NULL):num(n),pre(p),next(N){}; - }; - node* head; -public: - linkList(int M) - { - head = new node(1); head->pre = head->next = head; - node* tmp = head; - for (int i = 2; i <= M; i++) - tmp = tmp->next = new node(i, tmp); - tmp->next = head; - head->pre = tmp; - } - int Ysf(int K) - { - K--; - K %= M - j; - for (int i = 1; i <= K; i++) - head = head->next; - head->pre->next = head->next; - head->next->pre = head->pre; - head = head->next; - - return head->num; - } - -}; -int main() -{ - cin >> M; - linkList L(M); - - int tmp; - - for (j = 0; j < M - 1; j++) - { - cin >> tmp; - L.Ysf(tmp); - } - cout << L.Ysf(0); - return 0; -} diff --git a/SJTUOJ/1039.cpp b/SJTUOJ/1039.cpp deleted file mode 100644 index 6911139..0000000 --- a/SJTUOJ/1039.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int l; - int r; -}; -node A[30010]; - -void traverse(int s) -{ - if (s == -1) return; - - traverse(A[s].l); - traverse(A[s].r); - cout << s << " "; - -} - -int main() -{ - int N; cin >> N; - int s, l, r; - - for (int i = 1; i <= N; i++) - { - cin >> s >> l >> r; - A[s].l = l; - A[s].r = r; - } - - int B[30010]; - queue q; - q.push(1); - - int sum = 0; - int num = 0; - - while(num < N) - { - if (q.front() == -1) - { - ++sum; - q.pop(); - q.push(-1); - q.push(-1); - continue; - }; - - num++; - B[q.front()] = ++sum; - q.push(A[q.front()].l); - q.push(A[q.front()].r); - q.pop(); - } - - for (int i = 1; i <= N; i++) - cout << B[i] << " "; - - cout << endl; - traverse(1); - - return 0; -} diff --git a/SJTUOJ/1040.cpp b/SJTUOJ/1040.cpp deleted file mode 100644 index 060911b..0000000 --- a/SJTUOJ/1040.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int l; - int r; - node():l(-1), r(-1){}; -}; -node A[1000010]; - -int main() -{ - int N; cin >> N; - int tmp; - for (int i = 1; i < N; i++) - { - cin >> tmp; - if (A[tmp].l == -1) A[tmp].l = i; - else if (A[tmp].l < i) A[tmp].r = i; - else { A[tmp].r = A[tmp].l; A[tmp].l = i;}; - } - - queue q; - q.push(0); - while(!q.empty()) - { - tmp = q.front(); - if (A[tmp].l != -1) q.push(A[tmp].l); - if (A[tmp].r != -1) q.push(A[tmp].r); - cout << tmp << " "; - q.pop(); - } - return 0; -} diff --git a/SJTUOJ/1042.cpp b/SJTUOJ/1042.cpp deleted file mode 100644 index f3dfd5c..0000000 --- a/SJTUOJ/1042.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include -using namespace std; - -class childBrotherTree -{ -public: - struct CBNode - { - int key; - int left; - int bro; - }; - class linkQueue - { - public: - struct Node - { - Node* next; - int data; - Node() :data(0), next(NULL) {}; - Node(int x, Node* t = NULL) :data(x), next(t) {}; - }; - Node* root; - Node* rear; - linkQueue() { root = rear = NULL; }; - ~linkQueue() {}; - void enQueue(const int& x) { - if (root == NULL) - { - rear = root = new Node(x); - return; - } - rear = rear->next = new Node(x); - } - int deQueue() - { - if (root == NULL) return -1; - Node* tmp = root; - int thedata = tmp->data; - root = root->next; - delete tmp; - return thedata; - } - bool isEmpty() { return root == NULL; } - }; - int length; //数组长度 - int head; - CBNode* array; - linkQueue preQueue; - linkQueue postQueue; - void preOrder(const CBNode& x) - { - cout << x.key << " "; - if (x.left) preOrder(array[x.left]); - if (x.bro) preOrder(array[x.bro]); - return; - } - void preOrder() - { - preOrder(array[head]); - }; - void postOrder(const CBNode& x) - { - if (x.left) postOrder(array[x.left]); - cout << x.key << " "; - if (x.bro) postOrder(array[x.bro]); - return; - } - void postOrder() - { - postOrder(array[head]); - } - void levelOrder() - { - linkQueue QUE; - QUE.enQueue(head); - for (int i = 1; i <= length; ++i) - { - int tmpNum = QUE.deQueue(); - cout << array[tmpNum].key << " "; - if (array[tmpNum].left) - { - int theleft = array[tmpNum].left; - QUE.enQueue(theleft); - int thebro = array[theleft].bro; - while (thebro) //左儿子的兄弟全部进队 - { - QUE.enQueue(thebro); - thebro = array[thebro].bro; - } - }; - } - }; - childBrotherTree() - { - array = NULL; - int N = 0, i = 0, cur, left, bro; - cin >> N; - length = N; - array = new CBNode[N + 1]; - for (i = 1; i <= N; ++i) { - cin >> cur >> left >> bro; - array[cur].key = cur; - array[cur].left = left; - array[cur].bro = bro; - }; - findHead(); - } - void findHead() - { - int i = 0; - bool* flag = new bool[length + 1]; - for (i = 1; i <= length; ++i) { flag[i] = true; }; - for (i = 1; i <= length; ++i) - { - flag[array[i].bro] = false; - flag[array[i].left] = false; - } - for (i = 1; i <= length; ++i) - { - if (flag[i] == true) - { - head = i; - return; - } - } - } - ~childBrotherTree() {}; -}; - -int main() -{ - - childBrotherTree TREE; - TREE.preOrder(); - cout << endl; - TREE.postOrder(); - cout << endl; - TREE.levelOrder(); -} \ No newline at end of file diff --git a/SJTUOJ/1043.cpp b/SJTUOJ/1043.cpp deleted file mode 100644 index 214b33a..0000000 --- a/SJTUOJ/1043.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -using namespace std; - -struct Node -{ - int left, right, parent; - Node* next; - Node() :next(NULL), left(-1), right(-1),parent(-1) {}; -}; -class linkQueue -{ -private: - Node* rear; - Node* head; -public: - linkQueue(Node& t) { head = rear = &t; }; - void enQueue(Node& t) { - if (head == NULL) - head = rear = &t; - else - rear = rear->next = &t; - } - Node* deQueue() { - Node* tmp = head; - head = head->next; - return tmp; - } -}; -int main() -{ - int N; cin >> N; - int parent; - if (N == 1) - { - cout << "true"; - return 0; - } - Node* array = new Node[N]; - for (int i = 1; i < N; i++) - { - cin >> parent; - array[i].parent = parent; - if (array[parent].left == -1) - array[parent].left = i; - else - array[parent].right = i; - } - - linkQueue tree(array[0]); - Node* tmp; - int cur = 0;; - while (true) - { - tmp = tree.deQueue(); - cur += 1; - if (tmp->left != -1) - tree.enQueue(array[tmp->left]); - else - { - if (2 * cur == N - 1) - cout << "true"; - else - cout << "false"; - break; - } - if (tmp->right != -1) - tree.enQueue(array[tmp->right]); - else - { - if (2 * cur == N) - cout << "true"; - else - cout << "false"; - break; - } - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1045.cpp b/SJTUOJ/1045.cpp deleted file mode 100644 index c8c26a2..0000000 --- a/SJTUOJ/1045.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -using namespace std; - - -struct node -{ - int lchild; - int brother; - bool cur; //״̬ǻ - bool isRoot; //ǷǸ - node():lchild(-1), brother(-1), cur(0),isRoot(0){}; -}; - -int main() -{ - int N; scanf("%d", &N); - char ch; - int x, y, tmp, sum = 1; - - node* A = new node[N + 1]; - - A[1].cur = A[1].isRoot = 1; - - for (int i = 1; i <= N; i++) - { - scanf("%c%c", &ch, &ch); - if (ch == 'B') - { - scanf("%d%d", &x, &y); - A[y].cur = 1; //ȫ - - if (A[x].lchild == -1) A[x].lchild = y; - else - { - tmp = A[x].lchild; - while(A[tmp].brother != -1) - tmp = A[tmp].brother; - A[tmp].brother = y; - } - } - else - { - scanf("%d", &x); - A[x].cur = 0; - - tmp = A[x].lchild; - // - while(tmp != -1) - { - A[tmp].isRoot = 1; - if (A[tmp].cur == 1) sum++; - - tmp = A[tmp].brother; - } - if (A[x].isRoot == 1) sum--; - printf("%d\n", sum); - } - } - return 0; -} diff --git a/SJTUOJ/1046.cpp b/SJTUOJ/1046.cpp deleted file mode 100644 index f2562a3..0000000 --- a/SJTUOJ/1046.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int l; - int r; - bool flag; //ɫ - node():flag(0){}; //ȫǰɫ -}; -node A[100010]; - -int B[100010]; -int B_xb; - -int traverse(int t) -{ - int l, r; - - if (A[t].l != 0) - l = traverse(A[t].l); - else l = 0; - - B[++B_xb] = t; - - if (A[t].r != 0) - r = traverse(A[t].r); - else r = 0; - - return l + r + 1; -} - -int color(int x) -{ - int l, r; - - if (A[x].l != 0) - l = color(A[x].l); - else l = 0; - - if (A[x].r != 0) - r = color(A[x].r); - else r = 0; - - if (A[x].flag == 1) return l + r + 1; - else return l + r; -} - -int main() -{ - int N, P, Q; scanf("%d%d%d", &N, &P, &Q); - - int x, y, z, t; - - for (int i = 1; i <= N; i++) - { - scanf("%d%d%d", &x, &y, &z); - A[x].l = y; - A[x].r = z; - } - - - for (int i = 1; i <= P; i++) - { - B_xb = 0; - - scanf("%d%d", &t, &x); - y = traverse(t); - x = x % y + 1; - - A[B[x]].flag = 1; - } - - for (int i = 1; i <= Q; i++) - { - scanf("%d", &x); - printf("%d\n", color(x)); - } - - - return 0; -} diff --git a/SJTUOJ/1047.cpp b/SJTUOJ/1047.cpp deleted file mode 100644 index 171b10e..0000000 --- a/SJTUOJ/1047.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int* Arr = new int[10]; - int* Brr = new int[10]; - int* Crr= new int[10]; - - int i, j, k, m, tmp, sum = 200000; - for (i = 1; i < 10; i++) cin >> Arr[i]; - for (i = 1; i < 10; i++) Arr[i] /= 3; - - for (i = 0; i <= 3; i++) - for (j = 0; j <= 3; j++) - for (k = 0; k <= 3; k++) - { - Brr[1] = i; Brr[2] = j; Brr[5] = k; // 1,2,5 - - Brr[3] = 4 - (Brr[1] + Brr[2] + Brr[5] + Arr[2]) % 4; - Brr[4] = 4 - (Brr[1] + Brr[2] + Arr[1]) % 4; - Brr[6] = 4 - (Brr[2] + Brr[3] + Arr[3]) % 4; - Brr[7] = 4 - (Brr[1] + Brr[4] + Brr[5] + Arr[4]) % 4; - Brr[8] = 4 - (Brr[4] + Brr[7] + Arr[7]) % 4; - Brr[9] = 4 - (Brr[1] + Brr[3] + Brr[5] + Brr[7] + Arr[5]) % 4; - - for (m = 1; m <= 9; m++) Brr[m] %= 4; - - if ((Brr[3] + Brr[5] + Brr[6] + Brr[9] + Arr[6]) % 4 != 0) continue; - if ((Brr[5] + Brr[7] + Brr[8] + Brr[9] + Arr[8]) % 4 != 0) continue; - if ((Brr[6] + Brr[8] + Brr[9] + Arr[9]) % 4 != 0) continue; - - tmp = 0; - for (m = 1; m <= 9; m++) tmp += Brr[m]; - if (tmp < sum) - { - for (m = 1; m <= 9; m++) Crr[m] = Brr[m]; - sum = tmp; - } - } - for (i = 1; i <= 9; i++) - for (j = 1; j <= Crr[i]; j++) - cout << i << " "; - return 0; -} diff --git a/SJTUOJ/1048.cpp b/SJTUOJ/1048.cpp deleted file mode 100644 index 7a4e3c0..0000000 --- a/SJTUOJ/1048.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -using namespace std; - -bool A[1024]; - -struct node -{ - int l; - int r; - node():l(0),r(0){}; -}; -node B[1024]; -int main() -{ - int N; cin >> N; - int x, y, z; - - memset(A, 0, sizeof(A)); - while(cin >> x >> y >> z) - { - B[x].l = y; - B[x].r = z; - A[y] = A[z] = 1; - } - - int root; - for (int i = 1; i <= N; i++) - if (A[i] == 0) { root = i; break;}; - - queue q; - q.push(root); - - while(!q.empty()) - { - cout << q.front() << endl; - if (B[q.front()].l) q.push(B[q.front()].l); - if (B[q.front()].r) q.push(B[q.front()].r); - q.pop(); - } - - return 0; -} diff --git a/SJTUOJ/1049.cpp b/SJTUOJ/1049.cpp deleted file mode 100644 index 1c0bcea..0000000 --- a/SJTUOJ/1049.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -using namespace std; - -int A[1010]; - -int main() -{ - int T; cin >> T; - int N, M; - int A_xb; - bool flag; - - for (int i = 1; i <= T; i++) - { - cin >> N >> M; - for (int j = 1; j <= N; j++) - cin >> A[j]; - - stack q; - - flag = true; - A_xb = 1; - for (int k = 0; k < N; k++) - { - if (k == A[A_xb]) - A_xb++; - else - { - while (!q.empty() && q.top() == A[A_xb]) - { - A_xb++; - q.pop(); - } - if (q.size() < M) - q.push(k); - else {flag = false; break;}; - } - } - while (!q.empty() && q.top() == A[A_xb]) - { - A_xb++; - q.pop(); - } - if (flag && q.empty()) cout << "YES" << endl; - else cout << "NO" << endl; - } - return 0; -} diff --git a/SJTUOJ/1075.cpp b/SJTUOJ/1075.cpp deleted file mode 100644 index c7916a1..0000000 --- a/SJTUOJ/1075.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -using namespace std; - -long long int A[3340]; -const int Mod = 19301; -int main() -{ - int N; cin >> N; - A[0] = A[1] = 1; - - for (int i = 2; i <= N; i++) - { - A[i] += A[i - 1]; - for (int j = 1; j < i; j++) - { - A[i] += (A[j - 1] * A[i - j - 1]); - A[i] %= Mod; - } - } - cout << A[N]; - return 0; -} diff --git a/SJTUOJ/1202.cpp b/SJTUOJ/1202.cpp deleted file mode 100644 index 7fa43c4..0000000 --- a/SJTUOJ/1202.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -int A[1000010]; -int B[1000010]; -int C[1000100]; -int main() -{ - string a, b; cin >> a >> b; - - int len_A = a.length(); - int len_B = b.length(); - - for (int i = 0; i < len_A; i++) - A[i] = a[len_A - i - 1] - '0'; - for (int i = 0; i < len_B; i++) - B[i] = b[len_B - i - 1] - '0'; - int M = max(len_A, len_B); - int m = min(len_A, len_B); - for (int i = len_A; i < M; i++) - A[i] = 0; - for (int i = len_B; i < M; i++) - B[i] = 0; - - - int yushu = 0; - for (int i = 0; i < M; i++) - { - C[i] = yushu + A[i] + B[i]; - if (C[i] >= 10) - { - C[i] -= 10; - yushu = 1; - }else yushu = 0; - } - - if (yushu == 1) cout << 1; - for (int i = M - 1; i >= 0; i--) - cout << C[i]; - - return 0; -} diff --git a/SJTUOJ/1203.cpp b/SJTUOJ/1203.cpp deleted file mode 100644 index d84f46b..0000000 --- a/SJTUOJ/1203.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include - -using namespace std; - -template -class linklist -{ -public: - struct node - { - T data; - node* next; - node(T thedata, node* n = NULL):data(thedata),next(n){}; - node():next(NULL){}; - }; - int maxSize; - node* head; - node* tail; - linklist(){head = tail = new node();}; - void enQueue() - { - T data; cin >> data; - tail = tail->next = new node(data); - }; - void traverse() - { - node* tmp = head->next; - while(tmp != NULL) - { - cout << tmp->data << " "; - tmp = tmp->next; - } - } -}; - -int main() -{ - string cho; cin >> cho; - if(cho == "int") - { - linklist A, B; - int An, Bn; cin >> An >> Bn; - for (int i = 0; i < An; i++) - A.enQueue(); - for (int i = 0; i < Bn; i++) - B.enQueue(); - A.tail->next = B.head->next; - A.traverse(); - } - else if (cho == "char") - { - linklist A, B; - int An, Bn; cin >> An >> Bn; - for (int i = 0; i < An; i++) - A.enQueue(); - for (int i = 0; i < Bn; i++) - B.enQueue(); - A.tail->next = B.head->next; - A.traverse(); - } - else if (cho == "double") - { - linklist A, B; - int An, Bn; cin >> An >> Bn; - for (int i = 0; i < An; i++) - A.enQueue(); - for (int i = 0; i < Bn; i++) - B.enQueue(); - A.tail->next = B.head->next; - A.traverse(); - } - return 0; -} diff --git a/SJTUOJ/1208.cpp b/SJTUOJ/1208.cpp deleted file mode 100644 index aec977f..0000000 --- a/SJTUOJ/1208.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -using namespace std; - -int main() -{ - double r, a; - double square, res = 0; - double angel; - while(cin >> r >> a){ - angel = acos(a / r); - square = r * r * angel - 0.5 * r * r * sin(2 * angel); - res = max(res, square); - } - printf("%.2f", res); - return 0; -} diff --git a/SJTUOJ/1209.cpp b/SJTUOJ/1209.cpp deleted file mode 100644 index 9fcee3f..0000000 --- a/SJTUOJ/1209.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int n; scanf("%d", &n); - int a, sum = 0; - while(n--){ - scanf("%d", &a); - while(a) - { - if (a & 1) - sum++; - a >>= 1; - } - } - - return 0; -} diff --git a/SJTUOJ/1211.cpp b/SJTUOJ/1211.cpp deleted file mode 100644 index 43de14f..0000000 --- a/SJTUOJ/1211.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include - -using namespace std; - -class bTree -{ - struct node - { - int left; - int right; - int parent; - node(int p = 0):parent(p){}; - }; - node* A; //Ž - int root; //ͷλ - int length; //鳤 -public: - bTree(); - bool isCBT(); -}; -bTree::bTree() -{ - scanf("%d",&length); - A = new node[length + 1]; - for (int i = 1; i <= length; i++) - { - scanf("%d%d",&A[i].left,&A[i].right); - if (A[i].left) A[A[i].left].parent = i; - if (A[i].right) A[A[i].right].parent = i; - } - root = 1; - while(A[root].parent != 0) root = A[root].parent; //ѰҸ -} -bool bTree::isCBT() -{ - int *B = new int[2 * length + 1]; //ģһջ - int cur_out = 1; B[1] = root; - int cur_in = 1; - while(B[cur_out] != 0) - { - B[++cur_in] = A[B[cur_out]].left; - B[++cur_in] = A[B[cur_out]].right; - cur_out++; - }; - for (int i = cur_out; i <= cur_in; i++) - if (B[i] != 0) return false; - return true; -} -int main() -{ - bTree T; - if (T.isCBT()) printf("%c",'Y'); - else printf("%c",'N'); - return 0; -} diff --git a/SJTUOJ/1214.cpp b/SJTUOJ/1214.cpp deleted file mode 100644 index 3f1cbf5..0000000 --- a/SJTUOJ/1214.cpp +++ /dev/null @@ -1,140 +0,0 @@ - -#include -using namespace std; - -class childBrotherTree -{ -public: - struct CBNode - { - int key; - int left; - int bro; - }; - class linkQueue - { - public: - struct Node - { - Node* next; - int data; - Node() :data(0), next(NULL) {}; - Node(int x, Node* t = NULL) :data(x), next(t) {}; - }; - Node* root; - Node* rear; - linkQueue() { root = rear = NULL; }; - ~linkQueue() {}; - void enQueue(const int& x) { - if (root == NULL) - { - rear = root = new Node(x); - return; - } - rear = rear->next = new Node(x); - } - int deQueue() - { - if (root == NULL) return -1; - Node* tmp = root; - int thedata = tmp->data; - root = root->next; - delete tmp; - return thedata; - } - bool isEmpty() { return root == NULL; } - }; - int length; //数组长度 - int head; - CBNode* array; - linkQueue preQueue; - linkQueue postQueue; - void preOrder(const CBNode& x) - { - cout << x.key << " "; - if (x.left) preOrder(array[x.left]); - if (x.bro) preOrder(array[x.bro]); - return; - } - void preOrder() - { - preOrder(array[head]); - }; - void postOrder(const CBNode& x) - { - if (x.left) postOrder(array[x.left]); - cout << x.key << " "; - if (x.bro) postOrder(array[x.bro]); - return; - } - void postOrder() - { - postOrder(array[head]); - } - void levelOrder() - { - linkQueue QUE; - QUE.enQueue(head); - for (int i = 1; i <= length; ++i) - { - int tmpNum = QUE.deQueue(); - cout << array[tmpNum].key << " "; - if (array[tmpNum].left) - { - int theleft = array[tmpNum].left; - QUE.enQueue(theleft); - int thebro = array[theleft].bro; - while (thebro) //左儿子的兄弟全部进队 - { - QUE.enQueue(thebro); - thebro = array[thebro].bro; - } - }; - } - }; - childBrotherTree() - { - array = NULL; - int N = 0, i = 0, left, brother, thekey; - cin >> N; - length = N; - array = new CBNode[N + 1]; - for (i = 1; i <= N; ++i) { - cin >> left >> brother >> thekey; - array[i].left = left; - array[i].bro = brother; - array[i].key = thekey; - }; - findHead(); - }; - void findHead() - { - int i = 0; - bool* flag = new bool[length + 1]; - for (i = 1; i <= length; ++i) { flag[i] = true; }; - for (i = 1; i <= length; ++i) - { - flag[array[i].bro] = false; - flag[array[i].left] = false; - } - for (i = 1; i <= length; ++i) - { - if (flag[i] == true) - { - head = i; - return; - } - } - } - ~childBrotherTree() {}; -}; - -int main() -{ - childBrotherTree TREE; - TREE.preOrder(); - cout << endl; - TREE.postOrder(); - cout << endl; - TREE.levelOrder(); -} \ No newline at end of file diff --git a/SJTUOJ/1215.cpp b/SJTUOJ/1215.cpp deleted file mode 100644 index 3a5a4bd..0000000 --- a/SJTUOJ/1215.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include -using namespace std; - -class linkQueue -{ -private: - struct Node - { - Node* next; - int data; - Node(int thedata = 0, Node* thenext = NULL) :data(thedata), next(thenext) {}; - }; - Node* head; - Node* rear; -public: - linkQueue() { head = rear = NULL; }; - void enQueue(const int& x) - { - if (head == NULL) - rear = head = new Node(x); - else - rear = rear->next = new Node(x); - } - int deQueue() - { - Node* tmp = head; - int thedata = tmp->data; - head = head->next; - delete tmp; - return thedata; - } - bool isEmpty() { return head == NULL; }; -}; -class bernolli -{ -private: - int* array; - int maxSize; - int currentSize; -public: - bernolli(int capacity = 100) - { - array = new int[capacity + 1]; - maxSize = capacity; - currentSize = 0; - } - ~bernolli() {}; - void enQueue(const int& x) - { - int hole = ++currentSize; - for (; hole > 1 && x < array[hole / 2]; hole /= 2) - array[hole] = array[hole / 2]; - array[hole] = x; - } - int deQueue() - { - int minItem = array[1]; - array[1] = array[currentSize--]; - percolateDown(1); - return minItem; - } - void percolateDown(int hole) - { - int child; - int tmp = array[hole]; - - for (; hole * 2 <= currentSize; hole = child) - { - child = hole * 2; - if (child != currentSize && array[child + 1] < array[child]) - child++; - if (array[child] < tmp) array[hole] = array[child]; - else break; - } - array[hole] = tmp; - } - int getHead() { return array[1]; }; -}; -int main() -{ - int N = 0; - cin >> N; - string str; int tmp; - linkQueue STORE; - bernolli TREE(N); - for (int i = 0; i < N; ++i) - { - cin >> str; - if (str == "insert") - { - cin >> tmp; - TREE.enQueue(tmp); - } - else if (str == "delete") - TREE.deQueue(); - else if (str == "min") - STORE.enQueue(TREE.getHead()); - } - while (!STORE.isEmpty()) - { - cout << STORE.deQueue() << endl; - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1216.cpp b/SJTUOJ/1216.cpp deleted file mode 100644 index 28d0d4d..0000000 --- a/SJTUOJ/1216.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include -using namespace std; - -class heap -{ -private: - int* array; - int currentSize; - int maxSize; -public: - heap(int N = 100) - { - maxSize = N; - array = new int[N]; - currentSize = 0; - } - void doubleSpace() - { - int* tmp = array; - array = new int[3 * maxSize]; - for (int i = 1; i <= currentSize; i++) - array[i] = tmp[i]; - maxSize *= 3; - } - void enQueue(const int& x) - { - if (currentSize == maxSize - 1) - doubleSpace(); - - array[++currentSize] = x; - int tmp = x; - int hole = currentSize; - for (; hole > 1; hole /= 2) - { - if (tmp < array[hole / 2]) - array[hole] = array[hole / 2]; - else - break; - } - array[hole] = tmp; - } - void find(const int& x, int cur_xb, int &max_min, int &tar_xb) - { - if (array[cur_xb] <= x) - { - if (2 * cur_xb <= currentSize) - find(x, 2 * cur_xb, max_min, tar_xb); - if (2 * cur_xb + 1 <= currentSize) - find(x, 2 * cur_xb + 1, max_min, tar_xb); - } - else if (array[cur_xb] > x) - { - if (array[cur_xb] < max_min) //如果比大于x的较小值小 - { - max_min = array[cur_xb]; - tar_xb = cur_xb; - } - else if (array[cur_xb] == max_min) //如果等于大于x的较小值 - { - if (cur_xb < tar_xb) //比较下标大小 - tar_xb = cur_xb; - } - } - } - int findfind(int x) - { - int max_min = 500000000; - int tar_xb = -1; - for (int i = 1; i <= currentSize; i++) - { - if (array[i] > x && array[i] < max_min) - { - max_min = array[i]; - tar_xb = i; - } - } - return tar_xb; - } - void decrease(int i, int v) - { - array[i] -= v; - int tmp = array[i]; - - int hole = i; - for (; hole > 1; hole /= 2) - { - if (tmp < array[hole / 2]) - array[hole] = array[hole / 2]; - else - break; - } - array[hole] = tmp; - } -}; - -int main() -{ - heap T(2); - string choice; - int x, y, max_min , tar_xb = -1; - int M; cin >> M; - for (int i = 1; i <= M; i++) - { - cin >> choice; - if (choice == "insert") - { - cin >> x; - T.enQueue(x); - } - else if (choice == "find") - { - cin >> x; - //max_min = 100000000; - //tar_xb = -1; - //T.find(x, 1, max_min, tar_xb); - //cout << tar_xb << endl; - cout << T.findfind(x) << endl; - } - else if (choice == "decrease") - { - cin >> x >> y; - T.decrease(x, y); - } - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1225.cpp b/SJTUOJ/1225.cpp deleted file mode 100644 index 6cee917..0000000 --- a/SJTUOJ/1225.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -using namespace std; - -int qSort(int* A, int left, int right); -void quickSort(); -void quickSort(int* A, int left, int right); - -int qSort(int* A, int left, int right) -{ - int k = A[left]; - do - { - while (left < right && A[right] >= k) right--; - if (left < right) { A[left] = A[right]; left++; }; - while (left < right && A[left] <= k) left++; - if (left < right) { A[right] = A[left]; right--; }; - } while (left != right); - A[left] = k; - return left; -} -void quickSort() -{ - int N; cin >> N; - int* A = new int[N]; - for (int i = 0; i < N; i++) - cin >> A[i]; - quickSort(A, 0, N - 1); - - int cur = A[0]; //当前值 - int sum = 1; - for (int i = 0; i < N; i++) - { - if (A[i] > cur) - { - cur = A[i]; - sum++; - } - } - cout << sum; - return; -} -void quickSort(int* A, int left, int right) -{ - int mid; - if (left >= right) return; - mid = qSort(A, left, right); - quickSort(A, left, mid - 1); - quickSort(A, mid + 1, right); - return; -} -int main() -{ - quickSort(); - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1226.cpp b/SJTUOJ/1226.cpp deleted file mode 100644 index 4f66bfc..0000000 --- a/SJTUOJ/1226.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -using namespace std; - -int qSort(int* A, int left, int right); -void quickSort(); -void quickSort(int* A, int left, int right); -int qSort(int* A, int left, int right) -{ - int k = A[left]; - do - { - while (left < right && A[right] >= k) --right; - if (left < right) { A[left] = A[right]; ++left; }; - while (left < right && A[left] <= k) ++left; - if (left < right) { A[right] = A[left]; --right; }; - } while (left != right); - A[left] = k; - return left; -} -void quickSort() -{ - int N; cin >> N; - int* A = new int[N]; - for (int i = 0; i < N; i++) - scanf("%d",&A[i]); - quickSort(A, 0, N - 1); - for (int i = 0; i < N; i++) - printf("%d ",A[i]); -} -void quickSort(int *A, int left, int right) -{ - int mid; - if (left >= right) return; - mid = qSort(A, left, right); - quickSort(A, left, mid - 1); - quickSort(A, mid + 1, right); -} -int main() -{ - quickSort(); - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1233.cpp b/SJTUOJ/1233.cpp deleted file mode 100644 index a4a215e..0000000 --- a/SJTUOJ/1233.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include - -using namespace std; - -int main() -{ - double salary; cin >> salary; - double sum = 0; - - if (salary <= 3500) - { - cout << floor(sum); - return 0; - }else salary -= 3500; - - if (salary <= 1500) - { - sum += 0.03 * salary; - cout << floor(sum); - return 0; - }else sum += 45; - - if (salary <= 4500) - { - sum += 0.10 * (salary - 1500); - cout << floor(sum); - return 0; - }else sum += 300; - - if (salary <= 9000) - { - sum += 0.20 * (salary - 4500); - cout << floor(sum); - return 0; - }else sum += 900; - - if (salary <= 35000) - { - sum += 0.25 * (salary - 9000); - cout << floor(sum); - return 0; - }else sum += 6500; - - if (salary <= 55000) - { - sum += 0.30 * (salary - 35000); - cout << floor(sum); - return 0; - }else sum += 6000; - - if (salary <= 80000) - { - sum += 0.35 * (salary - 55000); - cout << floor(sum); - return 0; - }else sum += 8750; - - if (salary > 80000) - { - sum += 0.45 * (salary - 80000); - cout << floor(sum); - return 0; - } - return 0; -} diff --git a/SJTUOJ/1239.cpp b/SJTUOJ/1239.cpp deleted file mode 100644 index a4a215e..0000000 --- a/SJTUOJ/1239.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include - -using namespace std; - -int main() -{ - double salary; cin >> salary; - double sum = 0; - - if (salary <= 3500) - { - cout << floor(sum); - return 0; - }else salary -= 3500; - - if (salary <= 1500) - { - sum += 0.03 * salary; - cout << floor(sum); - return 0; - }else sum += 45; - - if (salary <= 4500) - { - sum += 0.10 * (salary - 1500); - cout << floor(sum); - return 0; - }else sum += 300; - - if (salary <= 9000) - { - sum += 0.20 * (salary - 4500); - cout << floor(sum); - return 0; - }else sum += 900; - - if (salary <= 35000) - { - sum += 0.25 * (salary - 9000); - cout << floor(sum); - return 0; - }else sum += 6500; - - if (salary <= 55000) - { - sum += 0.30 * (salary - 35000); - cout << floor(sum); - return 0; - }else sum += 6000; - - if (salary <= 80000) - { - sum += 0.35 * (salary - 55000); - cout << floor(sum); - return 0; - }else sum += 8750; - - if (salary > 80000) - { - sum += 0.45 * (salary - 80000); - cout << floor(sum); - return 0; - } - return 0; -} diff --git a/SJTUOJ/1266.cpp b/SJTUOJ/1266.cpp deleted file mode 100644 index 4f66bfc..0000000 --- a/SJTUOJ/1266.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -using namespace std; - -int qSort(int* A, int left, int right); -void quickSort(); -void quickSort(int* A, int left, int right); -int qSort(int* A, int left, int right) -{ - int k = A[left]; - do - { - while (left < right && A[right] >= k) --right; - if (left < right) { A[left] = A[right]; ++left; }; - while (left < right && A[left] <= k) ++left; - if (left < right) { A[right] = A[left]; --right; }; - } while (left != right); - A[left] = k; - return left; -} -void quickSort() -{ - int N; cin >> N; - int* A = new int[N]; - for (int i = 0; i < N; i++) - scanf("%d",&A[i]); - quickSort(A, 0, N - 1); - for (int i = 0; i < N; i++) - printf("%d ",A[i]); -} -void quickSort(int *A, int left, int right) -{ - int mid; - if (left >= right) return; - mid = qSort(A, left, right); - quickSort(A, left, mid - 1); - quickSort(A, mid + 1, right); -} -int main() -{ - quickSort(); - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1299.cpp b/SJTUOJ/1299.cpp deleted file mode 100644 index e0c5008..0000000 --- a/SJTUOJ/1299.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace std; - -vector> xsort_arr; -vector> ysort_arr; - -int64_t getDistance2(int64_t x1, int64_t y1, int64_t x2, int64_t y2) { - return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); -}; - -int64_t find(vector>& arr, int l, int r) { - if (r - l == 1) return getDistance2(arr[l][0], arr[l][1], arr[r][0], arr[r][1]); - - int m = (l + r) >> 1; - - int64_t l_min = m > l ? find(arr, l, m) : 0x7fffffffffffffff, r_min = r > m + 1 ? find(arr, m + 1, r) : 0x7fffffffffffffff; - int64_t ans = l_min < r_min ? l_min : r_min; - int l_board = m - sqrt(ans) - 1, r_board = m + sqrt(ans) + 1; - - vector> tmp_arr; - for (auto ele : ysort_arr) { - if (l_board <= ele[0] && ele[0] <= r_board) - tmp_arr.push_back(ele); - }; - int n = tmp_arr.size(); - for (int i = 0; i < n; i++) { - for (int j = 1; j <= 7; j++) - if (i + j >= n) break; - else { - int64_t tmp_dis = getDistance2(tmp_arr[i][0], tmp_arr[i][1], tmp_arr[i + j][0], tmp_arr[i + j][1]); - ans = tmp_dis < ans ? tmp_dis : ans; - }; - }; - return ans; -}; - -int main() -{ - int n = 0; - std::cin >> n; - vector> ori_arr(n, vector(2, 0)); - for (int i = 0; i < n; i++) { - std::cin >> ori_arr[i][0] >> ori_arr[i][1]; - ori_arr[i][2] = i; /* 下标 */ - } - - xsort_arr.assign(ori_arr.begin(), ori_arr.end()); - ysort_arr.assign(ori_arr.begin(), ori_arr.end()); - /* 分别按照 x 轴和 y 轴排序 */ - sort(xsort_arr.begin(), xsort_arr.end(), [](const vector& a, const vector& b) { - return a[0] < b[0]; - }); - sort(ysort_arr.begin(), ysort_arr.end(), [](const vector& a, const vector& b) { - return a[1] < b[1]; - }); - - std::cout << find(xsort_arr, 0, n - 1) << std::endl; - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1300.cpp b/SJTUOJ/1300.cpp deleted file mode 100644 index da4218d..0000000 --- a/SJTUOJ/1300.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include - -using namespace std; - -const int N = 4e7 + 1; -int n, k; -vector a(N + 1, 0); -void read_input_data() { - int m; - // n = 5; k = 5; m = 3; - // a[1] = 2; a[2] = 3; a[3] = 5, a[4] = 1, a[5] = 4; - // n = 5; k = 4; m = 1; - // a[1] = 1919810; - cin >> n >> k >> m; - for (int i = 1; i <= m; i++) { - scanf("%d", &a[i]); - } - unsigned int z = a[m]; - for (int i = m + 1; i <= n; i++) { - z ^= z << 13; - z ^= z >> 17; - z ^= z << 5; - a[i] = z & 0x7fffffff; - } -}; - -int partition(vector& v, int left_idx, int right_idx) { - int x = rand() % (right_idx - left_idx + 1) + left_idx; - swap(v[x], v[right_idx]); - - int ele = v[right_idx]; - - int idx = left_idx - 1; - for (int i = left_idx; i < right_idx; i++) - if (v[i] < ele) swap(v[++idx], v[i]); - swap(v[++idx], v[right_idx]); - return idx; -} -int get_nthelement(vector& v, const int k, int left_idx, int right_idx) { - int q = partition(v, left_idx, right_idx); - if (q == k) return v[q]; - else return q < k ? get_nthelement(v, k, q + 1, right_idx) : get_nthelement(v, k, left_idx, q - 1); -} - -int main() -{ - read_input_data(); - int ANS = get_nthelement(a, k, 1, n); - std::cout << get_nthelement(a, k, 1, n) << std::endl; - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1301.cpp b/SJTUOJ/1301.cpp deleted file mode 100644 index 9bed925..0000000 --- a/SJTUOJ/1301.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int n; cin >> n; - vector arr(n, 0); - for (int i = 0; i < n; i++) cin >> arr[i]; -} \ No newline at end of file diff --git a/SJTUOJ/1304.cpp b/SJTUOJ/1304.cpp deleted file mode 100644 index bad55a3..0000000 --- a/SJTUOJ/1304.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int M = 0, m = 0x3fffffff; - int N, L, x; scanf("%d%d", &N, &L); - - for (int i = 1; i <= N; i++){ - scanf("%d", &x); - if (i & 1){ - if (L - x > M) M = L - x; - if (L - x < m) m = L - x; - } - else{ - if (x > M) M = x; - if (x < m) m = x; - } - } - cout << m << " " << M; - return 0; -} diff --git a/SJTUOJ/1312.cpp b/SJTUOJ/1312.cpp deleted file mode 100644 index fe74ebf..0000000 --- a/SJTUOJ/1312.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int N; cin >> N; - int n, k; - for (int i = 0; i < N; i++) - { - cin >> n >> k; - if (k == 1) - { - if (n % 2 == 0) cout << "Yeah!" << endl; - else cout << "5555" << endl; - } - else - { - if (n <= k) cout << "5555" << endl; - else cout << "Yeah!" << endl; - } - } - return 0; -} diff --git a/SJTUOJ/1315.cpp b/SJTUOJ/1315.cpp deleted file mode 100644 index 7f011a7..0000000 --- a/SJTUOJ/1315.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -using namespace std; - -struct nodeff //定义结构体 -{ - int data1, data2; //存储分母,分子 - double num; //存储数值大小 - nodeff(const int& d1, const int& d2, const double& n) :data1(d1), data2(d2), num(n) {}; - nodeff() {}; - friend bool operator < (nodeff a,nodeff b) - { - return a.num > b.num; - } //重新定义比较函数 - -}; -int gcd(int m, int n) -{ - while (m > 0) - { - int c = n % m; - n = m; - m = c; - } - return n; -}//最大公约数n为1时两数互质 -int main() -{ - priority_queue q; - int N; cin >> N; - nodeff tmp(0,1,0); - q.push(tmp); - tmp.data1 = tmp.data2 = tmp.num = 1; - q.push(tmp); - for (int i = 1; i <= N; i++) - for (int j = i + 1; j <= N; j++) - if (gcd(j, i) == 1) //如果不互质,则跳过 - { - tmp.data1 = i; - tmp.data2 = j; - tmp.num = double(i) / j; - q.push(tmp); - } - while (!q.empty()) - { - cout << q.top().data1 << "/" << q.top().data2 << endl; - q.pop(); - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1338.cpp b/SJTUOJ/1338.cpp deleted file mode 100644 index fddc096..0000000 --- a/SJTUOJ/1338.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int Start; - int End; -}; - -node A[100010]; - -bool myCompare(node A, node B){return A.End < B.End;}; - -int main() -{ - - int N; cin >> N; - - for (int i = 1; i <= N; i++) - scanf("%d%d", &A[i].Start, &A[i].End); - A[0].Start = A[0].End = 0; - - sort(A + 1, A + N + 1, myCompare); - - int sum = 0; - - int i = 0, last; - while(i <= N) - { - last = i; - i++; - while(i <= N && A[i].Start < A[last].End) i++; - if (i <= N) sum++; - } - cout << sum; - return 0; -} diff --git a/SJTUOJ/1359.cpp b/SJTUOJ/1359.cpp deleted file mode 100644 index fddc096..0000000 --- a/SJTUOJ/1359.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int Start; - int End; -}; - -node A[100010]; - -bool myCompare(node A, node B){return A.End < B.End;}; - -int main() -{ - - int N; cin >> N; - - for (int i = 1; i <= N; i++) - scanf("%d%d", &A[i].Start, &A[i].End); - A[0].Start = A[0].End = 0; - - sort(A + 1, A + N + 1, myCompare); - - int sum = 0; - - int i = 0, last; - while(i <= N) - { - last = i; - i++; - while(i <= N && A[i].Start < A[last].End) i++; - if (i <= N) sum++; - } - cout << sum; - return 0; -} diff --git a/SJTUOJ/1360.cpp b/SJTUOJ/1360.cpp deleted file mode 100644 index fddc096..0000000 --- a/SJTUOJ/1360.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int Start; - int End; -}; - -node A[100010]; - -bool myCompare(node A, node B){return A.End < B.End;}; - -int main() -{ - - int N; cin >> N; - - for (int i = 1; i <= N; i++) - scanf("%d%d", &A[i].Start, &A[i].End); - A[0].Start = A[0].End = 0; - - sort(A + 1, A + N + 1, myCompare); - - int sum = 0; - - int i = 0, last; - while(i <= N) - { - last = i; - i++; - while(i <= N && A[i].Start < A[last].End) i++; - if (i <= N) sum++; - } - cout << sum; - return 0; -} diff --git a/SJTUOJ/1371.cpp b/SJTUOJ/1371.cpp deleted file mode 100644 index 0a3c68d..0000000 --- a/SJTUOJ/1371.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -using namespace std; -/*const int N = 2000; -int sum[N + 1][N + 1]; -int main() -{ - int n, m; scanf("%d%d",&n,&m); - int tmp, x, y; - - for (int i = 0; i <= N; i++) - for (int j = 0; j <= N; j++) - sum[i][j] = 0; - - for (int i = 0; i < n; i++) - { - scanf("%d", &tmp); - for (int j = 0; j <= tmp; j++) - for (int k = tmp; k <= N; k++) - sum[j][k] += 1; - } - - for (int i = 0; i < m; i++) - { - scanf("%d%d", &x, &y); - printf("%d\n", sum[x][y]); - } - return 0; -}*/ - -int main() -{ - int N, M, tmp, x, y; cin >> N >> M; - const int K = 1000000; - int* arr = new int[K + 1]; - for (int i = 0; i <= K; i++) - arr[i] = 0; - for (int i = 1; i <= N; i++) - { - scanf("%d", tmp); - arr[tmp] += 1; - } - for (int i = 0; i < N; i++) - arr[i + 1] += arr[i]; - for (int i = 1; i <= M; i++) - { - scanf("%d%d", &x, &y); - printf("%d\n",arr[y] - arr[x - 1]); - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1384.cpp b/SJTUOJ/1384.cpp deleted file mode 100644 index 6f279ab..0000000 --- a/SJTUOJ/1384.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include -#include -using namespace std; - -int main() -{ - char str[10000000 + 1]; - scanf("%s", &str); - int len = strlen(str); - int v_pre_0 = 0, v_pre_1 = 0, v_cur_0 = 0, v_cur_1 = 0, v_next_0 = -1, v_next_1 = -1; - for (int i = 0; i < len; i++) - { - if ('a' <= str[i] && str[i] <= 'z') { - v_next_0 = min(v_cur_0, v_cur_1); - v_next_1 = v_cur_1 + 1; - } else { - v_next_0 = min(v_cur_0, v_cur_1) + 1; - v_next_1 = v_cur_1; - }; - v_pre_0 = v_cur_0; v_pre_1 = v_cur_1; - v_cur_0 = v_next_0; v_cur_1 = v_next_1; - }; - std::cout << min(v_cur_0, v_cur_1); - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1397.cpp b/SJTUOJ/1397.cpp deleted file mode 100644 index b13fd05..0000000 --- a/SJTUOJ/1397.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -using namespace std; - -long long int A[100010]; -long long int B[100010]; - -int main() -{ - int n; scanf("%d",&n); - for (int i = 0; i < n; i++) - scanf("%lld",&A[i]); - - sort(A, A + n); - - for (int i = 1; i < n; i++) - B[i] = A[i] - A[i - 1]; - - long long int sum = 0; - for (int i = 1; i < n; i++) - sum += B[i] * (n - i) * i; - - sum %= 1000000007; - cout << sum; - return 0; -} diff --git a/SJTUOJ/1541.cpp b/SJTUOJ/1541.cpp deleted file mode 100644 index 3691360..0000000 --- a/SJTUOJ/1541.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; - -int main() -{ - int k, n; cin >> k >> n; - int* arr = new int[n + 1]; - for (int i = 1; i <= n; i++) - cin >> arr[i]; - for (int i = 1; i < k; i++) - for (int j = 1; j <= n - i; j++) - arr[j] = arr[j] > arr[j + 1] ? arr[j] : arr[j + 1]; - for (int i = 1; i <= n - k + 1; i++) - cout << arr[i] << " "; - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1550.cpp b/SJTUOJ/1550.cpp deleted file mode 100644 index 1aecfc7..0000000 --- a/SJTUOJ/1550.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include - -using namespace std; - -int A[1010]; -int main() -{ - char tmp; - int N; cin >> N; - int M = 0, M_xb; - for (int i = 1; i <= N; i++) - { - cin >> tmp >> A[i]; - if (A[i] >= M) {M = A[i]; M_xb = i;}; - //ҵұߵֵ± - }cin >> tmp; - - int i; - int sum = 0, tmp_sum = 0; - - for (i = 2; i <= M_xb && A[i - 1] <= A[i]; i++); - int Lmax = A[i - 1]; - - for (; i <= M_xb; i++) - { - if (A[i] >= Lmax) - { - Lmax = A[i]; - sum += tmp_sum; - tmp_sum = 0; - } - else tmp_sum += Lmax - A[i]; - } - - for (i = N - 1; i >= M_xb && A[i] >= A[i + 1]; i--); - int Rmax = A[i + 1]; - tmp_sum = 0; - for (; i >= M_xb; i--) - { - if (A[i] >= Rmax) - { - Rmax = A[i]; - sum += tmp_sum; - tmp_sum = 0; - } - else tmp_sum += Rmax - A[i]; - } - - cout << sum; - return 0; -} diff --git a/SJTUOJ/1560.cpp b/SJTUOJ/1560.cpp deleted file mode 100644 index 38e4c09..0000000 --- a/SJTUOJ/1560.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -using namespace std; -int A[105]; -int dpL[105]; -int dpR[105]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - for (int i = 1; i <= n; i++) dpL[i] = 1; - for (int i = 2; i <= n; i++) - for (int j = i - 1; j >= 1; j--) - if (A[i] > A[j]) - dpL[i] = max(dpL[i], dpL[j] + 1); - - for (int i = 1; i <= n; i++) dpR[i] = 1; - for (int i = n - 1; i >= 1; i--) - for (int j = i + 1; j <= n; j++) - if (A[i] > A[j]) - dpR[i] = max(dpR[i], dpR[j] + 1); - - int res = 0; - for (int i = 1; i <= n; i++) - res = max(res, dpL[i] + dpR[i] - 1); - printf("%d", n - res); - return 0; -} diff --git a/SJTUOJ/1564.cpp b/SJTUOJ/1564.cpp deleted file mode 100644 index 9d60f60..0000000 --- a/SJTUOJ/1564.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include - -using namespace std; -const int N = 6; -int A[N][N]; -bool T[N][N]; -int res; -int start_x, start_y, end_x, end_y; - -void Dfs(int x, int y, int state, int ans) -{ - int pay = A[x][y] * state; - state = (pay % 4) + 1; - - ans += pay; - if (ans >= res) return; - if (x == end_x && y == end_y){ - res = min(res, ans); - return; - } - T[x][y] = true; - - if (x > 0 && !T[x - 1][y]) Dfs(x - 1, y, state, ans); - if (x < N - 1 && !T[x + 1][y]) Dfs(x + 1, y, state, ans); - if (y > 0 && !T[x][y - 1]) Dfs(x, y - 1, state, ans); - if (y < N - 1 && !T[x][y + 1]) Dfs(x, y + 1, state, ans); - - T[x][y] = false; - return; -}; - -int main() -{ - int t; scanf("%d", &t); - while(t--){ - memset(T, 0, sizeof(T)); - res = 0x7fffffff; - for (int i = 0; i < N; i++) - for (int j = 0; j < N; j++) - scanf("%d", &A[i][j]); - scanf("%d%d%d%d", &start_x, &start_y, &end_x, &end_y); - Dfs(start_x, start_y, 0, 0); - - printf("%d\n", res); - } - - return 0; -} diff --git a/SJTUOJ/1567.cpp b/SJTUOJ/1567.cpp deleted file mode 100644 index a35150b..0000000 --- a/SJTUOJ/1567.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include - -using namespace std; - -int main() -{ - char ch; - int n, line; - cin >> ch >> n; - - for (int i = 1; i <= n; i++) - { - line = min(i, n + 1 - i); - for (int j = 1; j <= (n + 1) / 2 - line; j++) printf(" "); - for (int j = 1; j <= 2 * line - 1; j++) printf("%c", ch); - printf("\n"); - } - return 0; -} diff --git a/SJTUOJ/1593.cpp b/SJTUOJ/1593.cpp deleted file mode 100644 index 5851d4b..0000000 --- a/SJTUOJ/1593.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include -using namespace std; - -struct M -{ - int score; //分数 - int Mus; //力量 - int data; //编号 -}; -int divide(M* A, int left, int right) -{ - M k = A[right]; - do - { - while (left < right && A[left].score > k.score) ++left; - while (left < right && A[left].score == k.score && A[left].data < k.data) ++left; - if (left < right) { A[right] = A[left]; right--; }; - while (left < right && A[right].score < k.score) --right; - while (left < right && A[right].score == k.score && A[right].data > k.data) --right; - if (left < right) { A[left] = A[right]; left++; }; - } while (left != right); - A[right] = k; - return right; -} -void quickSort(M* A, int left, int right) -{ - if (left >= right) return; - int mid = divide(A, left, right); - quickSort(A, left, mid - 1); - quickSort(A, mid + 1, right); -} - -int main() -{ - int N, R; cin >> N >> R; - N = 2 * N; - M* A = new M[N + 1]; - for (int i = 1; i <= N; i++) - A[i].data = i; - for (int i = 1; i <= N; i++) - cin >> A[i].score; - for (int i = 1; i <= N; i++) - cin >> A[i].Mus; - quickSort(A, 1, N); - //for (int i = 1; i <= N; i++) - //cout << A[i].score << " "; - for (int i = 0; i < R; i++) - { - for (int i = 1; i <= N; i += 2) - if (A[i].Mus > A[i + 1].Mus) - A[i].score += 2; - else if (A[i].Mus < A[i + 1].Mus) - A[i + 1].score += 2; - else - { - A[i].score++; - A[i + 1].score++; - } - quickSort(A, 1, N); - /*for (int i = 1; i <= N; i++) - cout << A[i].score << " "; - cout << endl;*/ - } - for (int i = 1; i <= N; i++) - printf("%d ",A[i].data); - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/1599.cpp b/SJTUOJ/1599.cpp deleted file mode 100644 index 2fdafaf..0000000 --- a/SJTUOJ/1599.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include - -using namespace std; - -class Stack -{ - struct node - { - char ch; - int data; - }; - node* A; - int cur; -public: - Stack(const int N){A = new node[N];cur = -1;}; - void push() - { - getchar(); - scanf("%c",&A[++cur].ch); - if (cur == 0) - A[cur].data = 0; - else - { - int tmp = A[cur - 1].data; - if (tmp == -1) A[cur].data = cur; // - else if (A[cur].ch == ')' && A[tmp].ch == '(' - || A[cur].ch == ']' && A[tmp].ch == '[' - || A[cur].ch == '}' && A[tmp].ch == '{') - A[cur].data = tmp == 0 ? -1 : A[tmp - 1].data; // - else - A[cur].data = cur; - } - } - void pop() - { - if (cur != -1) - cur--; - return; - } - void top() - { - if (cur == -1) return; - printf("%c\n",A[cur].ch); - } - bool pipei() - { - if (cur == -1) return true; - return A[cur].data == -1; - } - - -}; -int main() -{ - int n; scanf("%d",&n); - Stack S(n); - int choice; char ch; - for (int i = 0; i < n; i++) - { - scanf("%d",&choice); - switch(choice) - { - case 1: - S.push();break; - case 2: - S.pop();break; - case 3: - S.top();break; - case 4: - if (S.pipei()) - printf("%s\n","YES"); - else - printf("%s\n","NO"); - break; - } - } - return 0; -} diff --git a/SJTUOJ/1994.cpp b/SJTUOJ/1994.cpp deleted file mode 100644 index 92502ed..0000000 --- a/SJTUOJ/1994.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -using namespace std; -int A[512][512]; -int ans[512][512]; -int N, M; - -void Dfs(int x, int y, int state) -{ - ans[x][y] = state; - if (x > 0 && !ans[x - 1][y]) Dfs(x - 1, y, state); - if (x < N - 1 && !ans[x + 1][y]) Dfs(x + 1, y, state); - if (y > 0 && !ans[x][y - 1]) Dfs(x, y - 1, state); - if (y < N - 1 && !ans[x][y + 1]) Dfs(x, y + 1, state); - return; -} -int main() -{ - scanf("%d%d", &N, &M); - for (int i = 0; i < N; i++) - for (int j = 0; j < M; j++) - { - scanf("%d", &A[i][j]); - ans[i][j] = A[i][j]; - } - - int res = 0; - for (int i = 0; i < N; i++) - for (int j = 0; j < M; j++) - if (!ans[i][j]) - Dfs(i, j, ++res); - printf("%d", res); - - return 0; -} diff --git a/SJTUOJ/2105.cpp b/SJTUOJ/2105.cpp deleted file mode 100644 index 8638cc1..0000000 --- a/SJTUOJ/2105.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// 2105.最大矩形.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 -// - -#include -using namespace std; -struct node -{ - long long int xb; - long long int num; -}; -int main() -{ - int N; cin >> N; - long long int max = 0; - int cur_xb = 0; - int x, y; - node* array = new node[N + 1]; array[0].xb = 0; - - for (int i = 1; i < N + 1; i++) - { - cin >> x; - y = array[cur_xb].xb; - for (int j = cur_xb; j > 0 && array[j].num > x; j--) - { - max = max > array[j].num * (y - array[j - 1].xb) ? max : array[j].num * (y - array[j - 1].xb); - cur_xb--; - } - cur_xb++; - array[cur_xb].xb = i; - array[cur_xb].num = x; - } - - y = array[cur_xb].xb; - for (int j = cur_xb; j > 0 && array[j].num > -1; j--) - { - max = max > array[j].num * (y - array[j - 1].xb) ? max : array[j].num * (y - array[j - 1].xb); - cur_xb--; - } - - cout << max; - return 0; -} diff --git a/SJTUOJ/2109.cpp b/SJTUOJ/2109.cpp deleted file mode 100644 index 3bac50a..0000000 --- a/SJTUOJ/2109.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -using namespace std; - -int main() -{ - int N; cin >> N; - int* A = new int[N]; - for (int i = 0; i < N; i++) - cin >> A[i]; - - int k; cin >> k; - double b, c, D; - int sum = 0; - for (int i = 0; i < k; i++) - { - cin >> b >> c; - D = b * b / 4 / c; - /*for (int j = 0; j < N; j++) - sum += D >= A[j] ? 1 : 0; - cout << sum << endl; - */ - if (A[0] > D) - { - cout << 0 << endl; - continue; - } - if (A[N - 1] <= D) - { - cout << N << endl; - continue; - } - int left = 0; - int right = N; - int mid = (left + right) / 2; - while (A[mid] > D || A[mid + 1] <= D) - { - if (A[mid] > D) - { - right = mid; - mid = (left + right) / 2; - } - else if (A[mid] <= D) - { - left = mid; - mid = (left + right) / 2; - } - } - cout << mid + 1 << endl; - } - - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/3024.cpp b/SJTUOJ/3024.cpp deleted file mode 100644 index a061fb0..0000000 --- a/SJTUOJ/3024.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -using namespace std; -long long w[128]; -long long v[128]; -long long dp[1024]; - -int main() -{ - int T, M; scanf("%d%d", &T, &M); - for (int i = 1; i <= M; i++) - scanf("%lld%lld", &w[i], &v[i]); - - memset(dp, 0, sizeof(dp)); - for (int i = 1; i <= M; i++) - for (int j = T; j >= w[i]; j--) - dp[j] = max(dp[j], dp[j - w[i]] + v[i]); - printf("%lld\n", dp[T]); - - return 0; -} diff --git a/SJTUOJ/3030.cpp b/SJTUOJ/3030.cpp deleted file mode 100644 index a061fb0..0000000 --- a/SJTUOJ/3030.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -using namespace std; -long long w[128]; -long long v[128]; -long long dp[1024]; - -int main() -{ - int T, M; scanf("%d%d", &T, &M); - for (int i = 1; i <= M; i++) - scanf("%lld%lld", &w[i], &v[i]); - - memset(dp, 0, sizeof(dp)); - for (int i = 1; i <= M; i++) - for (int j = T; j >= w[i]; j--) - dp[j] = max(dp[j], dp[j - w[i]] + v[i]); - printf("%lld\n", dp[T]); - - return 0; -} diff --git a/SJTUOJ/3034.cpp b/SJTUOJ/3034.cpp deleted file mode 100644 index 58c80c3..0000000 --- a/SJTUOJ/3034.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -using namespace std; -const int N = 101000; -bool flag[N + 1]; -int prime[N + 1]; -int num = 0; - -void getPrime(){ - memset(flag, 0, sizeof(flag)); - - flag[2] = true; - prime[++num] = 2; - - for (int i = 3; i <= N; i++){ - if (!flag[i]) - prime[++num] = i; - for (int j = 1; j <= num && i * prime[j] <= N; j++) - { - flag[i * prime[j]] = true; - if (i % prime[j] == 0) - break; - } - } -} -int main() -{ - getPrime(); - int k; cin >> k; - - int left = 1, right = num, mid; - while(left <= right){ - mid = (left + right) / 2; - if (k == prime[mid]){ - left = right = mid; - break; - } - else if (k < prime[mid]) - right = mid - 1; - else left = mid + 1; - } - cout << prime[left] - prime[right]; - return 0; -} diff --git a/SJTUOJ/3044.cpp b/SJTUOJ/3044.cpp deleted file mode 100644 index 3eba67d..0000000 --- a/SJTUOJ/3044.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include - -using namespace std; - -long long int A[1010]; -long long int Mod = 1000000000 + 7; -int main() -{ - int N; cin >> N; - - A[0] = 1; - A[1] = 1; - - for (int i = 2; i <= N; i++) - { - int x = i; - while(x >= 0) - { - if (x % 2 == 0) - { - A[i] += A[x / 2]; - x -= 2; - } - else - { - A[i] += A[(x - 1) / 2]; - x -= 2; - } - } - A[i] %= Mod; - } - cout << A[N]; - return 0; -} diff --git a/SJTUOJ/4009.cpp b/SJTUOJ/4009.cpp deleted file mode 100644 index 4f889a3..0000000 --- a/SJTUOJ/4009.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; - -char C[110]; -int main() -{ - string A, B; //A B C - - cin >> A >> B; - - int len = A.length(); - int boom; - int C_xb = 0; - int i, j, k; - - for (i = 2; i <= len; i++) - if (len % i == 0) - { - C_xb = -1; - boom = len / i; - for (j = 0; j < i; j++) - for (k = 0; k < boom; k++) - C[++C_xb] = A[j + k * i]; - for (j = 0; j < len && C[j] == B[j]; j++); - if (j == len) {cout << i; return 0;}; - } - cout << "No Solution"; - return 0; -} diff --git a/SJTUOJ/4012.cpp b/SJTUOJ/4012.cpp deleted file mode 100644 index 9e63b88..0000000 --- a/SJTUOJ/4012.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include - -using namespace std; -int divide(int *A, int left, int right) -{ - int k = A[left]; - do - { - while (left < right && A[right] >= k) right--; - if (left < right){A[left] = A[right]; left++;}; - while (left < right && A[left] <= k) left++; - if (left < right){A[right] = A[left]; right--;}; - }while(left != right); - A[left] = k; - return left; -} -void quickSort(int *A, int left, int right) -{ - if (left >= right) return; - int mid = divide(A,left,right); - quickSort(A,left,mid - 1); - quickSort(A,mid + 1,right); -} -int main() -{ - int n; scanf("%d",&n); - int *A = new int[n]; - for (int i = 0; i < n; i++) - scanf("%d",&A[i]); - quickSort(A,0,n - 1); - - long long int sum = 0; - int i,j,tmp; - for (i = 0; i < n - 1; i++) - { - tmp = A[i] + A[i + 1]; - sum += tmp; - for (j = i + 2; j < n && A[j] < tmp; j++) - A[j - 1] = A[j]; - A[j - 1] = tmp; - } - cout << sum; - return 0; -} diff --git a/SJTUOJ/4016.cpp b/SJTUOJ/4016.cpp deleted file mode 100644 index 01c9127..0000000 --- a/SJTUOJ/4016.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include - -using namespace std; - -bool cal(int ch, int &x, int y) -{ - if (ch == 1) { x += y; return true;}; - if (ch == 2) { x -= y; return true;}; - if (ch == 3) { x *= y; return true;}; - if (ch == 4) - if (y != 0 && (x % y) == 0) {x /= y; return true;} - else return false; -} - -int main() -{ - int t; cin >> t; - - int A[5]; //4 - //1ӷ23˷4 - - while(t--) - { - scanf("%d%d%d%d", &A[1], &A[2], &A[3], &A[4]); - - int MAX = -100; - - for (int i = 1; i <= 4; i++) - for (int j = 1; j <= 4; j++) - if (j == i) continue; - else - for (int k = 1; k <= 4; k++) - if (k == j || k == i) continue; - else - for (int s = 1; s <= 4; s++) - if (s == i || s == j || s == k) continue; - else - for (int a = 1; a <= 4; a++) - for (int b = 1; b <= 4; b++) - for (int c = 1; c <= 4; c++) - { - while (1) - { - int res_1 = A[i]; - if (!cal(a, res_1, A[j])) break; - if (!cal(b, res_1, A[k])) break; - if (!cal(c, res_1, A[s])) break; - if (res_1 <= 24 && res_1 > MAX) MAX = res_1; - break; - //cout << res << endl; - } - while (1) - { - int res_1 = A[i]; - if (!cal(a, res_1, A[j])) break; - int res_2 = A[k]; - if (!cal(c, res_2, A[s])) break; - if (!cal(b, res_1, res_2)) break; - if (res_1 <= 24 && res_1 > MAX) MAX = res_1; - break; - } - } - printf("%d\n", MAX); - } - - return 0; -} diff --git a/SJTUOJ/4023.cpp b/SJTUOJ/4023.cpp deleted file mode 100644 index 1e8499c..0000000 --- a/SJTUOJ/4023.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -using namespace std; -int A[128]; - -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) scanf("%d", &A[i]); - - for (int i = 1; i <= n; i++) - { - int res = 0; - for (int j = 1; j < i; j++) - if (A[j] < A[i]) res++; - printf("%d ", res); - } - return 0; -} diff --git a/SJTUOJ/4025.cpp b/SJTUOJ/4025.cpp deleted file mode 100644 index 49af86d..0000000 --- a/SJTUOJ/4025.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -using namespace std; - -int divide(long long int* A, int left, int right) -{ - int k = A[left]; - do - { - while (left < right && A[right] >= k) --right; - if (left < right) { A[left] = A[right]; ++left; }; - while (left < right && A[left] <= k) ++left; - if (left < right) { A[right] = A[left]; --right; }; - } while (left != right); - A [left] = k; - return left; -} -void quickSort(long long int* A, int left, int right) -{ - if (left >= right) - return; - int mid = divide(A, left, right); - quickSort(A, left, mid - 1); - quickSort(A, mid + 1, right); -} - -int main() -{ - int X, Y; cin >> X >> Y; - int N = X * Y; - long long int* A = new long long int[N]; - - - for (int i = 0; i < N; i++) - cin >> A[i]; - quickSort(A, 0, N - 1); - - long long int S; cin >> S; - double result = 0; - double k = 0; - for (int i = 1; i < N; i++) - { - if (A[i] * i - A[i - 1] >= S) - { - result = double((A[i - 1] + S)) / i; - k = double(100 * i) / N; - break; - } - A[i] += A[i - 1]; - } - if (result == 0) - { - result = double((A[N - 1] + S)) / N; - k = 100.00; - } - printf("%.2f\n%.2f", result, k); - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/4029.cpp b/SJTUOJ/4029.cpp deleted file mode 100644 index c938891..0000000 --- a/SJTUOJ/4029.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -using namespace std; - -bool A[20010]; - -int main() -{ - memset(A, 0, sizeof(A)); - - int N; scanf("%d", &N); - int tmp; - - while(N--) - { - scanf("%d", &tmp); - A[tmp] = 1; - } - - for (int i = 1; i <= 20000; i++) - if (A[i] == 0) - { - for (int j = i - 1; j >= i / 2; j--) - if (A[j] == 1 && A[i - j] == 1) - { A[i] = 1; break;} - } - A[0] = 1; - - int B[20010]; - int B_xb = 0; - for (int i = 1; i <= 20000; i++) - if (A[i] == 1) B[++B_xb] = i; - - int M; scanf("%d", &M); - while(M--) - { - scanf("%d", &tmp); - - int i; - for (i = 1; i <= B_xb; i++) - if (A[tmp % B[i]] == 1) - { printf("YES\n"); break;} - if (i > B_xb) printf("NO\n"); - } - - return 0; -} diff --git a/SJTUOJ/4030.cpp b/SJTUOJ/4030.cpp deleted file mode 100644 index c129e64..0000000 --- a/SJTUOJ/4030.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -double A[1000010]; -double B[1000010]; -double C[1000010]; - -struct node -{ - int num; //ڼǹ - int ses; // - double pro; //и - node(int n, int s, double p):num(n),ses(s),pro(p){}; -}; -int main() -{ - int N; scanf("%d", &N); - - memset(A, 0, sizeof(A)); - for (int i = 1; i <= N; i++) cin >> A[i]; - - /*queue q; - q.push(node(1, 1, A[1])); - q.push(node(1, 0, 1 - A[1])); - - int num, ses; - double sum = 0; - while(!q.empty()) - { - num = q.front().num; if (num > N) { q.pop(); continue;}; - - ses = q.front().ses; - - q.push(node(num + 1, ses + 1, A[num + 1] * q.front().pro)); //һǹ - q.push(node(num + 1, 0, (1 - A[num + 1]) * q.front().pro)); //һǹûл - - if (q.front().ses != 0) - sum += (2 * q.front().ses - 1) * q.front().pro; - q.pop(); - } - printf("%.6f ", sum);*/ - - B[0] = C[0] = 0; - for (int i = 1; i <= N; i++) - { - B[i] = (B[i - 1] + 1) * A[i - 1] + 1; - C[i] = C[i - 1] + B[i] * A[i]; - } - - printf("%.6f", C[N]); - - return 0; -} diff --git a/SJTUOJ/4035.cpp b/SJTUOJ/4035.cpp deleted file mode 100644 index e806f81..0000000 --- a/SJTUOJ/4035.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -using namespace std; -const int M = 100001; -int Des[M]; //总目的地记录 - -int main() -{ - queue Place; //用来存储地方 - int N, k; cin >> N; //t为到达时间,k为车上旅客数量 - long long int t; - int i, j, s = 1, m; - int tmp; //临时输入用 - int curTotal = 0; //记录当前车次后的总目的地到达广度 - long long int* Time = new long long int[N + 1]; //对应车次的到达时间 - int* Num = new int[N + 1]; //对应车上的人数 - for (i = 0; i <= N; i++) - Time[i] = Num[i] = 0; - for (i = 0; i < M; i++) - Des[i] = 0; - - for (i = 1; i <= N; i++) - { - cin >> t >> k; - Time[i] = t; - Num[i] = k; - for (j = 1; j <= k; j++) - { - cin >> tmp; - Place.push(tmp); - if (Des[tmp] == 0) curTotal += 1; //如果还没有人到达过次目的地,则总到达广度+1 - Des[tmp] += 1; //对应目的地到达次数到达加1 - } - for (; s < i; s++) - { - if (t - Time[s] >= 86400) //如果相差24小时 - for (m = 1; m <= Num[s]; m++) //将所有该班次到达目的地出队 - { - tmp = Place.front(); - Des[tmp] -= 1; - if (Des[tmp] == 0) curTotal -= 1; - Place.pop(); - } - if (t - Time[s] < 86400) - break; - } - cout << curTotal << endl; - } - return 0; -} diff --git a/SJTUOJ/4040.cpp b/SJTUOJ/4040.cpp deleted file mode 100644 index 212372e..0000000 --- a/SJTUOJ/4040.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int a, b; cin >> a >> b; - if (a <= 0 || b <= 0){ - cout << "error"; - return 0; - } - - int res = 0; - for (int i = a; i <= b; i++) - { - int tmp = i; - int sum = 0; - while(tmp){ - sum += (tmp % 10) * (tmp % 10) * (tmp % 10); - tmp /= 10; - } - if (i == sum) - { - res++; - cout << i << endl; - } - } - if (!res) cout << "no"; - return 0; -} diff --git a/SJTUOJ/4062.cpp b/SJTUOJ/4062.cpp deleted file mode 100644 index 9d0a149..0000000 --- a/SJTUOJ/4062.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; - -int main() -{ - long long int x, y; cin >> x >> y; - long long int max, min; - if (x == y) - { - cout << 4 * x; - return 0; - } - long long int sum = 0; - - do - { - max = x > y ? x : y; - min = x < y ? x : y; - sum += 4 * min; - x = min; - y = max - min; - } while (x != y); - sum += 4 * x; - cout << sum; - return 0; -} diff --git a/SJTUOJ/4071.cpp b/SJTUOJ/4071.cpp deleted file mode 100644 index 90d8912..0000000 --- a/SJTUOJ/4071.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include - -using namespace std; - -long long int Mod = 1000000000 + 7; -long long int tempA, tempB, tempC, tempD; -void func(long long int n, long long int &a, long long int &b, long long int &c, long long int &d) -{ - if (n == 1){ - a = 0; - b = c = d = 1; - return; - } - if (n % 2 == 0) - { - func(n/2, a, b, c, d); - tempA = a * a + b * c; - tempB = b * (a + d); - tempC = c * (a + d); - tempD = c * b + d * d; - a = tempA % Mod; - b = tempB % Mod; - c = tempC % Mod; - d = tempD % Mod; - return; - } - else - { - func(n/2, a, b, c, d); - tempA = b * (a + d); - tempB = a * a + b * (a + c + d); - tempC = c * b + d * d; - tempD = c * (a + b + d) + d * d; - a = tempA % Mod; - b = tempB % Mod; - c = tempC % Mod; - d = tempD % Mod; - return; - } -} -int main() -{ - long long int n; cin >> n; n++; - long long int a, b, c, d; - - if (n <= 2) { cout << 1; return 0;} - - n -= 2; - func(n, a, b, c, d); - cout << (b + d) % Mod << endl; - return 0; -} diff --git a/SJTUOJ/4075.cpp b/SJTUOJ/4075.cpp deleted file mode 100644 index 61ddbdb..0000000 --- a/SJTUOJ/4075.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - string A, B; - cin >> A >> B; - int len_A = A.length(), len_B = B.length(); - int minus_len = len_A - len_B; - for (int i = 0; i <= minus_len; ++i) - { - if (A[i] != B[0] || A[len_B + i - 1] != B[len_B - 1]) - continue; - else - { - int j = i + 1; - int out = i + len_B / 2 ; - while (A[j] == B[j - i] && A[len_B - j + 2*i - 1] == B[len_B + i - j - 1] && ++j && j <= out); - if (j == out + 1) - { - cout << i; - break; - } - } - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/4094.cpp b/SJTUOJ/4094.cpp deleted file mode 100644 index 477f061..0000000 --- a/SJTUOJ/4094.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int N, tmp, ofServers, totalWait, i; - int *cur = new int[26]; - cin >> N; - while (N) - { - ofServers = N; //空闲服务台数量 - totalWait = 0; //总共离开人数 - for (i = 0; i < 26; i++) { cur[i] = 0; }; //初始化 - - string store; cin >> store; //输入一堆顾客 - i = 0; - while(store[i] != '\0') - { - tmp = store[i] - 'A'; //存入相应标号 - if (ofServers == 0) //无空闲台子 - { - if (cur[tmp] == 2) //没有晒到离开时 - totalWait++; - else if (cur[tmp] == 0) //进来时晒不到 - cur[tmp] = 2; - else //晒到了离开时 - ofServers++; - } - else - switch (cur[tmp]) - { - case 0:ofServers--; cur[tmp] = 1; break; - case 1:ofServers++; cur[tmp] = 0; break; - case 2:totalWait++; - } - i++; - } - if (totalWait == 0) - cout << "All customers tanned successfully." << endl; - else - cout << totalWait << " customer(s) walked away." << endl; - cin >> N; - } - return 0; -} diff --git a/SJTUOJ/4097.cpp b/SJTUOJ/4097.cpp deleted file mode 100644 index c594d6e..0000000 --- a/SJTUOJ/4097.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -using namespace std; - -class linkList -{ - struct node - { - node* next; - int data; - node(int d, node* n = NULL) :data(d),next(n) {}; - }; - node* head; - int maxSize; -public: - linkList(int N, int* array) - { - head = new node(-1); //head为哨兵 - node* cur = head; - for (int i = 1; i <= N; i++) - cur = cur->next = new node(array[i]); - maxSize = N; - } - void insert(int x, int y) - { - node* tmp_cur = head; - for (int i = 0; i < x; i++) - tmp_cur = tmp_cur->next; - tmp_cur->next = new node(y,tmp_cur->next); - maxSize += 1; - } - void deQueue(int x) - { - node* tmp_pre = head; - node* delt; - for (int i = 0; i < x - 1; i++) - tmp_pre = tmp_pre->next; - delt = tmp_pre->next; - tmp_pre->next = delt->next; - delete delt; - maxSize -= 1; - } - void traverse() - { - node* cur = head; - for (int i = 1; i <= maxSize; i++) - { - cur = cur->next; - cout << cur->data << " "; - } - } -}; - -int main() -{ - int N, M; cin >> N >> M; - int choice, x, y; - int* array = new int[N + 1]; - for (int i = 1; i <= N; i++) - cin >> array[i]; - linkList L(N, array); - for (int i = 1; i <= M; i++) - { - cin >> choice; - if (choice == 1) - { - cin >> x >> y; - L.insert(x, y); - } - else if (choice == 2) - { - cin >> x; - L.deQueue(x); - } - } - L.traverse(); - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/4145.cpp b/SJTUOJ/4145.cpp deleted file mode 100644 index 3f90ab9..0000000 --- a/SJTUOJ/4145.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include - -using namespace std; - -int A[300010]; -long long A_index = -1; - -int main() -{ - long long n, x, y; cin >> n >> x >> y; - - char str[300010]; - cin >> str; - str[n] = '1'; - - int tmp = 0; - for (int i = 0; i <= n; i++) - { - if (str[i] == '1') - if (tmp) - A[++A_index] = tmp, tmp = 0; - else continue; - else - tmp++; - } - //for (int i = 0; i <= A_index; i++) cout << A[i] << " "; - - if (A_index == -1) cout << 0; - else if (x < y) - cout << x * A_index + y; - else cout << y * (A_index + 1); - return 0; -} diff --git a/SJTUOJ/4146.cpp b/SJTUOJ/4146.cpp deleted file mode 100644 index a123aff..0000000 --- a/SJTUOJ/4146.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int n, B; scanf("%d%d", &n, &B); - int A[128]; - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - int ans[128]; - int cur = 0, ans_index = 0; - for (int i = 1; i < n; i++) - { - if (A[i] & 1) cur++; - if (cur == i - cur) - ans[++ans_index] = abs(A[i] - A[i + 1]); - } - sort(ans + 1, ans + ans_index + 1, less()); - - //for (int i = 1; i <= ans_index; i++) cout << ans[i] << " "; - - int res = 0; - for (int i = 1; i <= ans_index; i++) - if (B >= ans[i]) - res++, B -= ans[i]; - cout << res; - - return 0; -} diff --git a/SJTUOJ/4147.cpp b/SJTUOJ/4147.cpp deleted file mode 100644 index 51af746..0000000 --- a/SJTUOJ/4147.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -using namespace std; -int L[100010]; // -int H[100010]; // - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d%d", &L[i], &H[i]); - - int cur = max(L[1], H[1]); - for (int i = 2; i <= n; i++) - { - if (max(L[i], H[i]) <= cur) - cur = max(L[i], H[i]); - else if (min(L[i], H[i]) <= cur) - cur = min(L[i], H[i]); - else { - cout << "NO"; - return 0; - } - } - cout << "YES"; - return 0; -} diff --git a/SJTUOJ/4148.cpp b/SJTUOJ/4148.cpp deleted file mode 100644 index ab8a724..0000000 --- a/SJTUOJ/4148.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include -using namespace std; - -int A[1010][1010]; - -int main() -{ - int n, m, p; scanf("%d%d%d", &n, &m, &p); - memset(A, 0, sizeof(A)); - for (int i = 0; i <= n + 1; i++) - A[i][0] = A[i][m + 1] = 1; - for (int j = 0; j <= m + 1; j++) - A[0][j] = A[n + 1][j] = 1; - - if (p) - { - int dir = 0; //0123 - - A[1][1] = 1; - int x = 1, y = 1; - for (int i = 2; i <= m * n; i++) - { - if (dir == 0) // - if (A[x][y + 1] == 0) - A[x][++y] = i; - else - { - dir++; - A[++x][y] = i; - } - else if (dir == 1) // - if (A[x + 1][y] == 0) - A[++x][y] = i; - else - { - dir++; - A[x][--y] = i; - } - else if (dir == 2) // - if (A[x][y - 1] == 0) - A[x][--y] = i; - else - { - dir++; - A[--x][y] = i; - } - else if (dir == 3) // - if (A[x - 1][y] == 0) - A[--x][y] = i; - else - { - dir = 0; - A[x][++y] = i; - } - } - } - else if (!p) - { - int dir = 0; //0123 - - A[1][1] = 1; - int x = 1, y = 1; - for (int i = 2; i <= m * n; i++) - { - if (dir == 0) // - if (A[x + 1][y] == 0) - A[++x][y] = i; - else - { - dir++; - A[x][++y] = i; - } - else if (dir == 1) // - if (A[x][y + 1] == 0) - A[x][++y] = i; - else - { - dir++; - A[--x][y] = i; - } - else if (dir == 2) // - if (A[x - 1][y] == 0) - A[--x][y] = i; - else - { - dir++; - A[x][--y] = i; - } - else if (dir == 3) // - if (A[x][y - 1] == 0) - A[x][--y] = i; - else - { - dir = 0; - A[++x][y] = i; - } - } - - } - - - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= m; j++) - printf("%d ", A[i][j]); - printf("\n"); - } - return 0; -} diff --git a/SJTUOJ/4165.cpp b/SJTUOJ/4165.cpp deleted file mode 100644 index 1e0166c..0000000 --- a/SJTUOJ/4165.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include -using namespace std; - -long long int A[100010]; - -int main() -{ - int N; scanf("%d", &N); - - A[0] = 0; A[N + 1] = 0; - for (int i = 1; i <= N; i++) scanf("%lld", &A[i]); - - long long int tmp; - for (int i = 1; i <= N; i++) - { - scanf("%lld", &tmp); - A[i] -= tmp; - } - - long long int sum = 0; - for (int i = 0; i <= N; i++) - { - if (A[i] * A[i - 1] <= 0) - sum += abs(A[i]); - else - { - if (A[i] > 0 && A[i - 1] > 0) - sum += A[i] > A[i - 1] ? A[i] - A[i - 1] : 0; - else if (A[i] < 0 && A[i - 1] < 0) - sum += A[i] < A[i - 1] ? A[i - 1] - A[i] : 0; - } - } - cout << sum; - return 0; -} diff --git a/SJTUOJ/4204.cpp b/SJTUOJ/4204.cpp deleted file mode 100644 index 58a2ca7..0000000 --- a/SJTUOJ/4204.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int N; cin >> N; - - long long int V, a, b; - - while(N-- > 0) - { - cin >> V >> a >> b; - if (b >= 2 * a) - cout << a * V << endl; - else - if (V % 2 == 0) - cout << b * V / 2 << endl; - else - cout << V / 2 * b + a << endl; - } - return 0; -} diff --git a/SJTUOJ/4232.cpp b/SJTUOJ/4232.cpp deleted file mode 100644 index 8af003f..0000000 --- a/SJTUOJ/4232.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -using namespace std; - -int main() -{ - int N, M; cin >> N >> M; - int* array = new int[N + 1]; - int* store = new int[N + 1]; int num = 0; - char tmp; - int A, B; - for (int i = 1; i <= N; i++) { cin >> array[i]; }; - for (int i = 0; i < M; i++) - { - cin >> tmp; - if (tmp == 'Q') - { - cin >> A >> B; - int max = -1; - for (int j = A; j <= B; j++) - if (array[j] >= max) - max = array[j]; - store[++num] = max; - } - else if (tmp == 'U') - { - cin >> A >> B; - array[A] = B; - } - } - for (int i = 1; i <= num; i++) - cout << store[i] << endl; - - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/4255.cpp b/SJTUOJ/4255.cpp deleted file mode 100644 index 581fbee..0000000 --- a/SJTUOJ/4255.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -using namespace std; - -int B[128]; - -int main() -{ - int N; scanf("%d", &N); - for (int i = 1; i < N; i++) - scanf("%d", &B[i]); - int sum = 0; - sum += B[1] + B[N - 1]; - - for (int i = 1; i < N; i++) - sum += min(B[i], B[i + 1]); - printf("%d", sum); - return 0; -} diff --git a/SJTUOJ/4257.cpp b/SJTUOJ/4257.cpp deleted file mode 100644 index d36fdab..0000000 --- a/SJTUOJ/4257.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include - -using namespace std; - -int main() -{ - long long n, k, A, B; cin >> n >> k >> A >> B; - long long res = 0; - if (k == 1){ - cout << (n - 1) * A; - return 0; - } - while(n != 1){ - if (n < k) res += A * (n - 1), n = 1; - else if(n % k != 0) - res += A * (n - (n / k) * k), n = (n / k) * k; - else{ - res += min(B, A * (n - n / k)); - n /= k; - } - } - cout << res; - return 0; -} diff --git a/SJTUOJ/4258.cpp b/SJTUOJ/4258.cpp deleted file mode 100644 index 1e3887e..0000000 --- a/SJTUOJ/4258.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -using namespace std; -const int mod = 2019; -int fastPower(int base, int k){ - int res = 1; - - while(k){ - if (k & 1) - res = (res * base) % mod; - base = (base * base) % mod; - k >>= 1; - } - return res % mod; -} -int main() -{ - int a, n; cin >> a >> n; - cout << fastPower(a, n); - return 0; -} diff --git a/SJTUOJ/4261.cpp b/SJTUOJ/4261.cpp deleted file mode 100644 index 7f741c3..0000000 --- a/SJTUOJ/4261.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include - -using namespace std; -long long A[1000010]; - -int main() -{ - int n, m, tmp; cin >> n >> m; - char ch; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= m; j++) - { - cin >> ch; - if ('a' <= ch && ch <= 'z') tmp = ch - 'a' + 1; - else tmp = ch - 'A' + 1; - - if (i & 1) A[m * (i - 1) + j] = tmp; - else A[m * i - j + 1] = tmp; - } - //for (int i = 1; i <= n * m; i++) - //cout << A[i] << " "; - - int steps[1000010], x = 0, len = n * m; - steps[1] = 1; - for (int i = 2; steps[i - 1] <= len; i++) - x++, steps[i] = steps[i - 1] + x; - - long long res = 1, mod = 1e9 + 7; - for (int i = 1; steps[i] <= len; i++) - res = (A[steps[i]] * res) % mod; - cout << res; - return 0; -} diff --git a/SJTUOJ/4265.cpp b/SJTUOJ/4265.cpp deleted file mode 100644 index cdd412b..0000000 --- a/SJTUOJ/4265.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -using namespace std; - -int A[10010]; - -int main() -{ - int N, M, K; scanf("%d%d", &N, &M); - A[0] = 0; - for (int i = 1; i <= N; i++) scanf("%d", &A[i]); - for (int i = 1; i <= N; i++) A[i] += A[i - 1]; - - while(M--){ - scanf("%d", &K); - int res = 0; - for (int cur = N; cur - K >= 0; cur--) - res = max(res, A[cur] - A[cur - K]); - printf("%d\n", res); - } - return 0; -} diff --git a/SJTUOJ/4266.cpp b/SJTUOJ/4266.cpp deleted file mode 100644 index 607b1cc..0000000 --- a/SJTUOJ/4266.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -using namespace std; - -int A[100010]; -int n, m, b; -int bsearch(int b){ - int left = 1, right = n, mid; - while(left <= right){ - mid = (left + right) >> 1; - if (A[mid] < b) left = mid + 1; - else right = mid - 1; - } - if (left > n) - return -1; - else return A[left]; -} -int main() -{ - scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) scanf("%d", &A[i]); - - while(m--){ - scanf("%d", &b); - printf("%d ", bsearch(b)); - } - - return 0; -} diff --git a/SJTUOJ/4267.cpp b/SJTUOJ/4267.cpp deleted file mode 100644 index b12da45..0000000 --- a/SJTUOJ/4267.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -using namespace std; -int A[100010]; - -int main() -{ - int n, m, k; scanf("%d%d", &n, &m); - - A[0] = 0; - for (int i = 1; i <= n; i++) scanf("%d", &A[i]); - for (int i = 1; i <= n; i++) A[i] += A[i - 1]; - - while(m--){ - scanf("%d", &k); - int left = 1, right = n, mid; - - while(left <= right){ - mid = (left + right) >> 1; - if (A[mid] < k) left = mid + 1; - else right = mid - 1; - } - printf("%d %d\n", left, k - A[left - 1]); - } - return 0; -} diff --git a/SJTUOJ/4300.cpp b/SJTUOJ/4300.cpp deleted file mode 100644 index 60677d0..0000000 --- a/SJTUOJ/4300.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include -using namespace std; - -struct Node -{ - int data; - int weight; - Node() :weight(0), data(0) {}; -}; -int main() -{ - int N = 0, tmp = 0; - cin >> N; - Node* COW = new Node[N]; - for (int i = 0; i < N; ++i) - { - cin >> tmp; - COW[i].data = tmp; - for (int j = i; j >= 0; --j) - { - if (tmp < COW[j].data) - COW[j].weight += 1; - else if (tmp > COW[j].data) - COW[i].weight += 1; - } - } - for (int i = 0; i < N; ++i) - if (COW[i].weight == N / 2) - { - cout << COW[i].data; - return 0; - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/4307.cpp b/SJTUOJ/4307.cpp deleted file mode 100644 index eb83798..0000000 --- a/SJTUOJ/4307.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -using namespace std; -int divide(int *A, int left, int right) -{ - int k = A[left]; - do - { - while(left < right && A[right] > k) right--; - if (left < right) {A[left] = A[right]; left++;}; - while (left < right && A[left] < k) left++; - if (left < right) {A[right] = A[left]; right--;}; - }while(left != right); - A[left] = k; - return left; -} -void quickSort(int *A, int left, int right) -{ - if (left >= right) return; - int mid = divide(A,left,right); - quickSort(A,left,mid - 1); - quickSort(A,mid + 1, right); -} -int main() -{ - int k, l; scanf("%d%d",&k,&l); - int N = k * l; - int *A = new int [N]; - for (int i = 0; i < N; i++) - scanf("%d",&A[i]); - quickSort(A,0,N - 1); - for (int i = 0; i < N; i++) - printf("%d ",A[i]); - return 0; -} diff --git a/SJTUOJ/4308.cpp b/SJTUOJ/4308.cpp deleted file mode 100644 index 146b764..0000000 --- a/SJTUOJ/4308.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include - -using namespace std; -/* -int main() -{ - const int Y =15; - int n, k; scanf("%d%d",&n,&k); - int tmp, cur; - bool flag; - int B[10001]; - int **A = new int*[n + 1]; A[1][1] = -1; - for (int i = 1; i <= n; i++) - A[i] = new int[Y + 1]; - - for (int i = 1; i <= n; i++) - scanf("%d",&A[i][1]); - for (int i = 2; i <= n; i++) - { - tmp = A[i][1]; - cur = 1; - while(tmp != 1) - tmp = A[i][++cur] = A[tmp][0]; - A[i][0] = cur; - } - for (int i = 1; i <= k; i++) - { - scanf("%d",&tmp); - for (int i = 1; i <= tmp; i++) - scanf("%d",&B[i]); - - } - return 0; -}*/ - -struct node -{ - int data; - node* left; - node* right; - node(int d, node* l, node* r) - :data(d),left(l),right(r){}; -}; - -int main() -{ - node* head = new node(1, NULL, NULL); - //headҺָʱֱΪ - node* cur = *&head->left; - cur = new node(2, NULL, NULL); - //cur = *&cur->left; //ָhead - - //Ϊhead->leftѾ洢2 - //ʵϣhead->leftΪָ - cout << head->left; - return 0; -} diff --git a/SJTUOJ/4309.cpp b/SJTUOJ/4309.cpp deleted file mode 100644 index c6c4143..0000000 --- a/SJTUOJ/4309.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - const int Y = 100; - int n; cin >> n; - int** B = new int* [Y + 1]; - for (int j = 1; j <= Y; j++) - B[j] = new int[n + 1]; - for (int i = 1; i <= n; i++) - cin >> B[1][i]; - for (int j = 2; j <= Y; j++) - { - for (int i = 1; i <= n + 1 - j; i++) - { - B[j][i] = B[j - 1][i] > B[j - 1][i + 1] ? B[j - 1][i] : B[j - 1][i + 1]; - } - } - int m; cin >> m; - int l, r, len, k, yushu, max_tmp; - for (int i = 1; i <= m; i++) - { - cin >> l >> r; - len = r - l + 1; - if (len <= Y) - printf("%d\n", B[len][l]); - else - { - k = len / Y; - yushu = len - k * Y; - max_tmp = B[1][l]; - for (int i = 0; i < k; i++) - { - max_tmp = B[Y][l + Y * i] > max_tmp ? B[Y][l + Y * i] : max_tmp; - } - if (yushu != 0) max_tmp = max_tmp > B[yushu][r - yushu + 1] ? max_tmp : B[yushu][r - yushu + 1]; - printf("%d\n", max_tmp); - } - } - return 0; -} \ No newline at end of file diff --git a/SJTUOJ/4314.cpp b/SJTUOJ/4314.cpp deleted file mode 100644 index d2a34cc..0000000 --- a/SJTUOJ/4314.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include - -using namespace std; - -int A[100010]; - -int main() -{ - int N; cin >> N; - - for (int i = 0; i < N; i++) - cin >> A[i]; - - bool flag; - int sum = 0, tmp; - - do - { - flag = false; - for (int i = 0; i < N - 1; i++) - if (A[i + 1] < A[i]) - { - tmp = A[i]; - A[i] = A[i + 1]; - A[i + 1] = tmp; - sum++; - flag = true; - } - }while(flag); - cout << sum; - return 0; -} diff --git a/SJTUOJ/4315.cpp b/SJTUOJ/4315.cpp deleted file mode 100644 index e471a59..0000000 --- a/SJTUOJ/4315.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int l; - int r; - node():l(-1), r(-1){}; -}; -node A[10010]; - -void mirror(int x) -{ - if (A[x].l != -1) mirror(A[x].l); - if (A[x].r != -1) mirror(A[x].r); - - //ǰڵ - int tmp, tmp1, tmp2; - tmp = A[x].l; - A[x].l = A[x].r; - A[x].r = tmp; -} - -void traverse(int x) -{ - if (A[x].l != -1) traverse(A[x].l); - if (A[x].r != -1) traverse(A[x].r); - cout << x << " "; -} - -int main() -{ - int n; cin >> n; - int x, y, z, root; - - cin >> x >> y >> z; root = x; - A[x].l = y; - A[x].r = z; - - for (int i = 2; i <= n; i++) - { - cin >> x >> y >> z; - A[x].l = y; - A[x].r = z; - } - - mirror(root); - traverse(root); - - return 0; -} diff --git a/SJTUOJ/4316.cpp b/SJTUOJ/4316.cpp deleted file mode 100644 index 57b3159..0000000 --- a/SJTUOJ/4316.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -using namespace std; - -int A[10010]; -int B[10010]; - -int main() -{ - int N1, N2; cin >> N1 >> N2; - - for (int i = 1; i <= N1; i++) - cin >> A[i]; - for (int i = 1; i <= N2; i++) - cin >> B[i]; - - int A_xb = 1, B_xb = 1; - - for (int i = 1; i <= N1 + N2 && A_xb <= N1 && B_xb <= N2; i++) - { - if (A[A_xb] < B[B_xb]) - { - cout << A[A_xb] << endl; - A_xb++; - } - else - { - cout << B[B_xb] << endl; - B_xb++; - } - } - - for (int i = A_xb; i <= N1; i++) - cout << A[i] << endl; - for (int i = B_xb; i <= N2; i++) - cout << B[i] << endl; - return 0; -} diff --git a/SJTUOJ/4317.cpp b/SJTUOJ/4317.cpp deleted file mode 100644 index 76f5f6e..0000000 --- a/SJTUOJ/4317.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int x; - int xb; -}; -node A[100010]; - -bool myCompare(node A, node B) -{ - if (A.x == B.x) return A.xb < B.xb; - return A.x < B.x; -} -int main() -{ - int N, m; cin >> N; - - for (int i = 0; i < N; i++) - { - A[i].xb = i; - cin >> A[i].x; - } - - sort(A, A + N, myCompare); - - cin >> m; - int cha, x = 0, y = 0, i, j; - int MAX = 0; - - for (i = 0; i < N; i++) - { - cha = m - A[i].x; - for (j = N - 1; j > i; j--) - { - if (A[j].x == cha) - { - if (A[j].x - A[i].x > MAX) - { - x = A[i].xb; - y = A[j].xb; - MAX = A[j].x - A[i].x; - } - break; - } - } - - } - cout << x << " " << y; - return 0; -} diff --git a/SJTUOJ/4320.cpp b/SJTUOJ/4320.cpp deleted file mode 100644 index d280c84..0000000 --- a/SJTUOJ/4320.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -using namespace std; - -// ݴСҪ˼ʱۼӻᳬint -int main() -{ - int N, M; scanf("%d",&N); - int i, j; - int *A = new int[N]; - int *B = new int[N]; - long long int *dp = new long long int[N]; - - for (i = 0; i < N; i++) - scanf("%d",&A[i]); - - long long int MAX = -10000; - - /*M = N % 2 == 0 ? N / 2 : (N - 1) / 2; - for (i = 1; i < M; i++) - { - B[i] = A[2 * i] + A[2 * i + 1]; - dp[i] = dp[i - 1] > 0 ? B[i] + dp[i - 1] : B[i]; - if (dp[i] > MAX) MAX = dp[i]; - } - - dp[0] = A[1] + A[2]; MAX = MAX > dp[0] ? MAX : dp[0]; - M = N % 2 == 0 ? N / 2 - 1 : (N - 1) / 2; - for (i = 1; i < M; i++) - { - B[i] = A[2 * i + 1] + A[2 * i + 2]; - dp[i] = dp[i - 1] > 0? B[i] + dp[i - 1] : B[i]; - if (dp[i] > MAX) MAX = dp[i]; - }*/ - - if (N % 2 == 0) - { - MAX = dp[0] = A[0] + A[1]; - for (i = 1; i < N / 2; i++) - { - B[i] = A[2 * i] + A[2 * i + 1]; - dp[i] = dp[i - 1] > 0 ? B[i] + dp[i - 1] : B[i]; - if (dp[i] > MAX) MAX = dp[i]; - } - - dp[0] = A[1] + A[2]; if (dp[0] > MAX) MAX = dp[0]; - for (i = 1; i < N / 2 - 1; i++) - { - B[i] = A[2 * i + 1] + A[2 * i + 2]; - dp[i] = dp[i - 1] > 0 ? B[i] + dp[i - 1] : B[i]; - if (dp[i] > MAX) MAX = dp[i]; - } - } - else - { - MAX = dp[0] = A[0] + A[1]; - for (i = 1; i < (N - 1) / 2; i++) - { - B[i] = A[2 * i] + A[2 * i + 1]; - dp[i] = dp[i - 1] > 0 ? B[i] + dp[i - 1] : B[i]; - if (dp[i] > MAX) MAX = dp[i]; - } - - dp[0] = A[1] + A[2]; if (dp[0] > MAX) MAX = dp[0]; - for (i = 1; i < (N - 1) / 2; i++) - { - B[i] = A[2 * i + 1] + A[2 * i + 2]; - dp[i] = dp[i - 1] > 0 ? B[i] + dp[i - 1] : B[i]; - if (dp[i] > MAX) MAX = dp[i]; - } - } - - cout << MAX; - - return 0; -} diff --git a/SJTUOJ/4329.cpp b/SJTUOJ/4329.cpp deleted file mode 100644 index 4444a93..0000000 --- a/SJTUOJ/4329.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -using namespace std; -int A[30]; int A_xb; //26ĸֵĴ - -char s[100010]; int s_xb; -char t[100010]; int t_xb; -char u[100010]; int u_xb; - -int main() -{ - memset(A, 0, sizeof(A)); - - // - string a; cin >> a; - int len = a.length(); - for (int i = 0; i < len; i++) - { - ++A[a[i] - 'a' + 1]; - s[i] = a[i]; - } - //ʼA_xbֵ - for (int i = 1; i <= 26; i++) - if (A[i] == 0) continue; - else {A_xb = i; break;}; - - s_xb = -1; - t_xb = -1; - u_xb = -1; - - while(s_xb < len - 1) - { - //µԪشsβתƵtβ - t[++t_xb] = s[++s_xb]; - //A[A_xb]ֵ - int tmp_xb = s[s_xb] - 'a' + 1; - A[tmp_xb]--; - if (A[A_xb] == 0) //A_xbֵ - for (int i = A_xb + 1; i <= 26; i++) - if (A[i] == 0) continue; - else {A_xb = i; break;}; - - - while(t_xb >= 0 && (t[t_xb] - 'a' + 1) <= A_xb) //tԪǷҪתƵu - { - u[++u_xb] = t[t_xb]; - t_xb--; - } - } - - for (int i = 0; i <= u_xb; i++) - cout << u[i]; - for (int i = t_xb; i >= 0; i--) - cout << t[i]; - return 0; -} diff --git a/SJTUOJ/4331.cpp b/SJTUOJ/4331.cpp deleted file mode 100644 index df35a90..0000000 --- a/SJTUOJ/4331.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int l = 1e6, t = -1e6, r = -1e6, b = 1e6; - int x1, y1, x2, y2; - - int n; cin >> n; - while(n--) - { - cin >> x1 >> y1 >> x2 >> y2; - l = min(l, x1); - l = min(l, x2); - r = max(r, x1); - r = max(r, x2); - t = max(t, y1); - t = max(t, y2); - b = min(b, y1); - b = min(b, y2); - } - - cout << (t - b) * (r - l); - return 0; -} diff --git a/SJTUOJ/4332.cpp b/SJTUOJ/4332.cpp deleted file mode 100644 index 3957e53..0000000 --- a/SJTUOJ/4332.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -using namespace std; - -int B[100010]; -int main() -{ - - int n; cin >> n; - - if (n == 1) {cout << 2; return 0;}; - if (n == 2) {cout << 4; return 0;}; - - int i, j; - for (i = n;; i--) - { - for (j = 2; j <= sqrt(i + 1) && (i % j) != 0; j++); - if (j > sqrt(i + 1)){ cout << 2 * i; return 0; }; - } - - /*int B_xb = 2, tmp; - B[1] = 2; B[2] = 3; - - for (i = 5; i <= n; i++) - { - for (j = 1; j <= B_xb && (i % B[j]) != 0; j++); - if (j > B_xb) B[++B_xb] = i; - } - cout << B[1] * B[B_xb]; - - int sum = B_xb; - - for (i = n + 1; sum > 0; i++) - { - for (j = 1; j <= B_xb; j++) - if (B[j] > 0 && (i % B[j]) == 0) - { sum--; B[j] = -B[j];} - } - cout << B[1] * B[B_xb];*/ - - - return 0; -} diff --git a/SJTUOJ/4340.cpp b/SJTUOJ/4340.cpp deleted file mode 100644 index 24fadb5..0000000 --- a/SJTUOJ/4340.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - long long int E, EM, M, MH, H; - cin >> E >> EM >> M >> MH >> H; - - long long int tmpE = E + EM; - long long int tmpM = M + EM; - long long int tmpH = H + MH; - - - long long int F = min(tmpE, tmpM); - F = min(F, tmpH); - - long long int tmpEM; - long long int tmpMH; - - long long int l = 0, r = 2 * F, m; - - bool flag; - - while(l <= r) - { - //ĿҪ - - m = (l + r) / 2; - - flag = false; - - tmpE = m - E; - tmpM = m - M; - tmpH = m - H; - - tmpEM = EM; if (tmpE > 0) tmpEM -= tmpE; - tmpMH = MH; if (tmpH > 0) tmpMH -= tmpH; - - if (tmpEM >= 0 && tmpMH >= 0 && tmpEM + tmpMH >= tmpM) flag = true; - - if (flag) l = m + 1; - else r = m - 1; - } - - cout << r; - - return 0; -} diff --git a/SJTUOJ/4341.cpp b/SJTUOJ/4341.cpp deleted file mode 100644 index 6646617..0000000 --- a/SJTUOJ/4341.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -using namespace std; - -long long int B[1000010]; -long long int res[20]; -long long int cifang[20]; - -int main() -{ - int N; cin >> N; - memset(B, 0, sizeof(B)); - memset(res, 0, sizeof(res)); - memset(cifang, 0, sizeof(cifang)); - - cifang[0] = 1; - for (int i = 1; i < 20; i++) cifang[i] = 2 * cifang[i - 1]; - - for (int i = 1; i <= N; i++) - { - scanf("%lld", &B[i]); - long long int tmp = B[i]; - for (int j = 0; j < 20 && tmp > 0; j++) - { - res[j] += (tmp & 1); - //cout << (tmp & 1) << " "; - tmp /= 2; - } - //cout << endl; - } - - long long int sum = 0; - for (int i = 0; i < 20; i++) - sum += cifang[i] * res[i] * (res[i] - 1) / 2; - - cout << sum; - return 0; -} diff --git a/SJTUOJ/4342.cpp b/SJTUOJ/4342.cpp deleted file mode 100644 index 7ed8311..0000000 --- a/SJTUOJ/4342.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -using namespace std; - -long long int Mod = 1000000007; - -int power(long long int a, long long int b) -{ - long long int res = 1; - a %= Mod; - while(b) - { - if (b & 1) - res = (res * a) % Mod; - a = (a * a) % Mod; - b >>= 1; - } - return res % Mod; -} - -int main() -{ - long long int n; cin >> n; - - long long int res = power(2, n - 1); - res *= n; - res %= Mod; - cout << res; - return 0; -} diff --git a/SJTUOJ/4345.cpp b/SJTUOJ/4345.cpp deleted file mode 100644 index 60c3fd5..0000000 --- a/SJTUOJ/4345.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include - -using namespace std; -inline __int128 read(){ - __int128 x = 0; - char ch = getchar(); - while (ch >= '0' && ch <= '9') - { - x = x * 10 + ch - '0'; - ch = getchar(); - } - return x; -} -inline void print(__int128 x){ - if (x > 9) - print(x / 10); - putchar(x % 10 + '0'); -} -int main() -{ - __int128 cifang[30]; - cifang[0] = 1; - for (int i = 1; i < 30; i++) cifang[i] = cifang[i - 1] * 10; - - __int128 tmp; - while(tmp = read()){ - - __int128 A[100]; - __int128 B[1000]; //ѭڳȲ1000 - int B_index = -1; - B[++B_index] = tmp; - - bool flag = true; - int i, j; - while(flag){ - for (i = 0; i < B_index; i++) - if (B[B_index] == B[i]){ - flag = false; - break; - } - if (!flag){ - for (j = i; j < B_index; j++) - print(B[j]), printf(" "); - printf("\n"); - break; - } - - int index = -1; - while(tmp > 0) - { - A[++index] = (tmp % 10); - tmp /= 10; - } - int len = index + 1; - __int128 M = 0, m = 0; - - sort(A, A + len, less()); - for (int i = 0; i < len; i++) - M += cifang[i] * A[i]; - for (int i = 0; i < len; i++) - m += cifang[len - i - 1] * A[i]; - tmp = B[++B_index] = M - m; - } - } - return 0; -} diff --git a/SJTUOJ/4354.cpp b/SJTUOJ/4354.cpp deleted file mode 100644 index 012a047..0000000 --- a/SJTUOJ/4354.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - string tmp_str; cin >> tmp_str; - string str = ""; - for (int i = 0; tmp_str[i] != '\0'; i++) - if (tmp_str[i] > '9' || tmp_str[i] < '0') - str = str + tmp_str[i]; - str = str + '\0'; - - stack s; - for (int i = 0; str[i] != '\0'; i++) - if (str[i] == '(') - s.push(i); - else if (str[i] == ')') - { - int l = s.top(), r = i; - for (int j = l; j <= (l + r) / 2; j++) - swap(str[j], str[l + r - j]); - s.pop(); - } - for (int i = 0; str[i] != '\0'; i++) - if (str[i] != '(' && str[i] != ')') - cout << str[i]; - - return 0; -} diff --git a/Solutions/Coin-Change.cpp b/Solutions/Coin-Change.cpp new file mode 100644 index 0000000..c07fef4 --- /dev/null +++ b/Solutions/Coin-Change.cpp @@ -0,0 +1,22 @@ +class Solution { +public: + int coinChange(vector& coins, int amount) { + vector dp(amount + 1, 1e5 + 7); + dp[0] = 0; + + for (auto iter = coins.begin(); iter != coins.end();) { + if (*iter > amount) { + iter = coins.erase(iter); + } else iter++; + }; + + for (int i = 1; i <= amount; i++) { + for (int& coin : coins) { + if (i - coin >= 0) { + dp[i] = min(dp[i], dp[i - coin] + 1); + }; + }; + }; + return dp[amount] == 1e5 + 7 ? -1 : dp[amount]; + } +}; \ No newline at end of file diff --git a/Solutions/House-Robber-III.cpp b/Solutions/House-Robber-III.cpp new file mode 100644 index 0000000..2c887f5 --- /dev/null +++ b/Solutions/House-Robber-III.cpp @@ -0,0 +1,25 @@ +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} + * }; + */ +class Solution { +public: + vector _rob(TreeNode *root) { + if (root == NULL) return {0, 0}; + + vector left = _rob(root->left), right = _rob(root->right); + // cout << root->val << ' ' << left[0] << ' ' << left[1] << ' ' << right[0] << ' ' << right[1] << endl; + return {max(left[0], left[1]) + max(right[0], right[1]), left[0] + right[0] + root->val}; + } + int rob(TreeNode* root) { + vector ans = _rob(root); + return max(ans[0], ans[1]); + } +}; \ No newline at end of file diff --git a/Solutions/Longest-Increasing-Subsequence.cpp b/Solutions/Longest-Increasing-Subsequence.cpp new file mode 100644 index 0000000..f3bd2d6 --- /dev/null +++ b/Solutions/Longest-Increasing-Subsequence.cpp @@ -0,0 +1,14 @@ +class Solution { +public: + int lengthOfLIS(vector& nums) { + int n = nums.size(); + vector dp(n, 1); + for (int i = 0; i < n; i++) { + for (int j = i - 1; j >= 0; j--) { + if (nums[j] < nums[i]) + dp[i] = max(dp[i], dp[j] + 1); + }; + }; + return *max_element(dp.begin(), dp.end()); + } +}; \ No newline at end of file diff --git a/Solutions/Top-K-Frequent-Elements.cpp b/Solutions/Top-K-Frequent-Elements.cpp new file mode 100644 index 0000000..7bc7029 --- /dev/null +++ b/Solutions/Top-K-Frequent-Elements.cpp @@ -0,0 +1,21 @@ +class Solution { +public: + struct cmp { + bool operator() (const vector& v1, const vector& v2) const { + return v1[1] < v2[1]; + } + }; + vector topKFrequent(vector& nums, int k) { + unordered_map counts; + for (int& num : nums) counts[num]++; + priority_queue, vector >, cmp > pque; + for (auto iter : counts) + pque.push({iter.first, iter.second}); + vector answer; + while (k-- > 0) { + answer.push_back(pque.top()[0]); + pque.pop(); + }; + return answer; + } +}; \ No newline at end of file diff --git a/educoder/1.1.cpp b/educoder/1.1.cpp deleted file mode 100644 index ad9cb15..0000000 --- a/educoder/1.1.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -using namespace std; - -int a[10000]; -int main(void){ - int n,m; - cin>>n>>m; - for(int i=0;i>a[i]; - } - - ///////////////////////// - // n,m,a已经输入 - - int ans = 0x7fffffff, tot = 0; - for (int i = 0; i < m; i++) tot += a[i]; - ans = tot < ans ? tot : ans; - for (int i = m; i < n; i++) { - tot += a[i] - a[i - m]; - ans = tot < ans ? tot : ans; - }; - std::cout << ans << std::endl; - - // 在标准输出流中输出(cout,printf) - ///////////////// - return 0; -} diff --git a/educoder/1.2.cpp b/educoder/1.2.cpp deleted file mode 100644 index b9e1745..0000000 --- a/educoder/1.2.cpp +++ /dev/null @@ -1,89 +0,0 @@ - -#include -using namespace std; - -class linkList { -private: - struct node { // 内嵌类 - int data; - node* next; - explicit node(int x, node* p = NULL) { - data = x; - next = p; - } - node() :next(NULL) {} - ~node() {} - }; // 注意有2个构造函数 - node* head; - int N = 0; /* 节点数量*/ -public: - //根据自身需求增加或者减少成员函数/成员变量 - linkList() { - head = new node(); /* 哨兵 */ - }; - ~linkList() { - delete head; - } - int search(const int x) { - int idx = -1; - node* ptr = head; - while (ptr->next && ++idx) { - ptr = ptr->next; - if (ptr->data == x) break; - }; - return idx; - } // 根据数据返回node的下标 - node* visit(int i) { - node* ptr = head; - for (int j = 0; j <= i && ptr; j++) { - ptr = ptr->next; - }; - return ptr; - } // 根据node下标返回node的指针 - void insert(int i, int x) { - node* ptr = visit(i - 1); - if (ptr) { - ptr->next = new node(x, ptr->next); - N++; - }; - return; - } // 在下标为i处插入data为x的点 - void setPtrForLastNode(int pos) { - node* tail = visit(N - 1); - if (pos == -1 || pos == tail->data) return; - else tail->next = visit(pos); - return; - } // 让最后一个node指向下标为pos的node,若最后一个node指向自身,或者pos值为-1,则设为nullptr - int hasCycle() { - node* ptr1 = head, *ptr2 = head; - do { - if (ptr1 == nullptr || ptr2 == nullptr) break; - ptr1 = ptr1->next; - - /* ptr2 比较快 */ - ptr2 = ptr2->next; if (ptr2 == nullptr) break; - ptr2 = ptr2->next; - } while (ptr2 != nullptr && ptr1 != ptr2); - return ptr2 != nullptr; - } // 让两个指针以不同速度遍历链表,如果两个指针可以相遇那么存在环路 -}; - - -int main() { - linkList link_list = linkList(); - int n; - cin >> n; // 读取node的个数 - for (int i = 0; i < n; ++i) { - int data; - cin >> data; - // 处理接受的数据 - link_list.insert(i, data); - } - int pos; - cin >> pos; // 读取最后一个node指向的node的index - link_list.setPtrForLastNode(pos); - // 用链表构建有向图 - - // 判断环路 - std::cout << link_list.hasCycle(); -} \ No newline at end of file diff --git a/educoder/1.3.cpp b/educoder/1.3.cpp deleted file mode 100644 index e625934..0000000 --- a/educoder/1.3.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -using namespace std; - -int main(){ - int n,m; - cin>>n>>m; - vector a(n); - vector b(n); - for(int i = 0; i < n; i++){ - cin>>a[i]; - } - for(int i = 0; i < m; i++){ - cin>>b[i]; - } - //输入已经给出 - int left, right, mid; - for (int i = 0; i < m; i++) { - left = 0, right = n - 1; - while (left <= right) { - mid = (left + right) >> 1; - if (a[mid] == b[i]) { - std::cout << 1 << std::endl; - break; - } else if (a[mid] < b[i]) left = mid + 1; - else right = mid - 1; - }; - if (left > right) std::cout << 0 << std::endl; - } - //在标准输出流中输出(cout,printf) - return 0; -} \ No newline at end of file diff --git a/educoder/2.1.cpp b/educoder/2.1.cpp deleted file mode 100644 index 5485a58..0000000 --- a/educoder/2.1.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include -using namespace std; - -int order[50000]; -int main(void){ - int t; - cin >>t; - while(t--){ - int n,m; - cin>>n>>m; - for(int i=0;i>order[i]; - - // solve - stack s1, s2; - int idx = 0, flag = 1; - for (int i = 0; i < n; i++) - { - if (order[idx] == i) { - idx++; - } else if (!s1.empty() && order[idx] == s1.top()) { - idx++; - s1.pop(); - } else if (s1.size() < m) s1.push(i); - else { - flag = 0; - break; - }; - while (!s1.empty() && order[idx] == s1.top()) { - idx++; - s1.pop(); - }; - }; - cout << (flag && idx == n ? "YES\n" : "NO\n"); - // - } - return 0; -} diff --git a/educoder/2.2.cpp b/educoder/2.2.cpp deleted file mode 100644 index d4ca4c7..0000000 --- a/educoder/2.2.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -using namespace std; - - -int main(void){ - string s; - cin>>s; -// # your code - stack s1; - string ans = ""; - for (int i = 0; i < s.size(); i++) - { - if ('0' <= s[i] && s[i] <= '9') ans += s[i]; - else if (s[i] == '(') s1.push(s[i]); - else if (s[i] == ')') { - while (!s1.empty() && s1.top() != '(') { - ans += s1.top(); - s1.pop(); - }; - s1.pop(); - } else if (s[i] == '*') { - while (!s1.empty() && s1.top() != '(' && s1.top() != '+') { - ans += s1.top(); - s1.pop(); - }; - s1.push(s[i]); - } else if (s[i] == '+') { - while (!s1.empty() && s1.top() != '(') { - ans += s1.top(); - s1.pop(); - }; - s1.push(s[i]); - }; - }; - while (!s1.empty()) { - ans += s1.top(); - s1.pop(); - }; - // cout or printf - cout << ans << endl; - return 0; -} - -//2+(1+5*6)*4 -//2156*+4*+ diff --git a/educoder/2.3.cpp b/educoder/2.3.cpp deleted file mode 100644 index f2a2198..0000000 --- a/educoder/2.3.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -using namespace std; - - -int find(int n, int m) { - if (n == 1) return 0; - return (find(n - 1, m) + m) % n; -} - -int main(){ - int n,m; - cin>>n>>m; - - //your code - cout << find(n, m) + 1 << endl; - // -} \ No newline at end of file diff --git a/educoder/2.4.cpp b/educoder/2.4.cpp deleted file mode 100644 index 84ed550..0000000 --- a/educoder/2.4.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include -#include -#include - -typedef struct stack -{ - char *base; - char *top; - int stacksize; - - void push(char val) { - top += 1; - base[++stacksize] = val; - }; - char pop() { - top -= 1; - return base[stacksize--]; - }; - bool empty() { - return !stacksize; - } -}stack; - -void Initstack(stack& L) { - const int N = 10000000; - L.base = new char[N]; - L.top = L.base; - L.stacksize = 0; - - std::string val = ""; std::cin >> val; - for (int i = 0; i < val.size(); i++) L.push(val[i]); - // char ch; - // while (std::cin >> ch) L.push(ch); -}; - -bool creatstack(stack& L) { - std::string str1 = "", str2 = ""; - while (!L.empty()) { - char val = L.pop(); - str1 = str1 + val; - str2 = val + str2; - } - return !str1.compare(str2); -}; - -int main() -{ - - // 实现stack - stack L; - Initstack(L); - printf("%d",creatstack(L)); - return 0; -} diff --git a/educoder/3.2.cpp b/educoder/3.2.cpp deleted file mode 100644 index ab061fe..0000000 --- a/educoder/3.2.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -using namespace std; - - -int a[100005]; - -int main(void){ - int n; - cin>>n; - - priority_queue, greater > p; - for(int i=0;i>a[i]; - p.push(a[i]); - } - // - int ans = 0; - if (p.size() == 1) ans = p.top(); - while (p.size() > 1) { - int val1 = p.top(); p.pop(); - int val2 = p.top(); p.pop(); - ans += val1 + val2; - p.push(val1 + val2); - }; - std::cout << ans; - - return 0; -} diff --git a/educoder/3.3.cpp b/educoder/3.3.cpp deleted file mode 100644 index 90729a3..0000000 --- a/educoder/3.3.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -using namespace std; - -struct TreeNode { - char val; - TreeNode *left; - TreeNode *right; - TreeNode() : val(0), left(nullptr), right(nullptr) {} - TreeNode(char x) : val(x), left(nullptr), right(nullptr) {} - TreeNode(char x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} -}; - -TreeNode* _buildTree(string inorder, int l_in, int r_in, string postorder, int l_po, int r_po) { - if (l_po > r_po) return nullptr; - - TreeNode* root = new TreeNode(postorder[r_po]); - for (int i = l_in; i <= r_in; i++) - if (root->val == inorder[i]) { - root->left = _buildTree(inorder, l_in, i - 1, postorder, l_po, l_po + i - l_in - 1); - root->right = _buildTree(inorder, i + 1, r_in, postorder, r_po - (r_in - i), r_po - 1); - break; - }; - return root; -}; - -TreeNode* buildTree(string inorder, string postorder) { - return _buildTree(inorder, 0, inorder.size() - 1, postorder, 0, postorder.size() - 1); -}; - -void traverse(string& prev, TreeNode* head) { - if (head == nullptr) return; - - prev += head->val; - traverse(prev, head->left); - traverse(prev, head->right); - return; -}; - -int main(void){ - string mid = ""; cin >> mid; - string post = ""; cin >> post; - /////your code - TreeNode* head = buildTree(mid, post); - string prev = ""; - traverse(prev, head); - std::cout << prev << std::endl; - //////// - return 0; -} diff --git a/educoder/3.4.cpp b/educoder/3.4.cpp deleted file mode 100644 index 02c6a3c..0000000 --- a/educoder/3.4.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -using namespace std; -const int MXN = 100005; -int le[MXN], ri[MXN]; - -int main(void){ - int n; - cin >> n; - - vector flag(n, false); - for(int i = 0; i < n; i++){ - cin >> le[i] >> ri[i]; - flag[le[i]] = flag[ri[i]] = true; - }; - - int head = 0; - for (int i = 1; i < n; i++) - if (flag[i] == false) { - head = i; - break; - }; - - deque res; - deque tmp; - if (head != 0) tmp.push_back(head); - - while (!tmp.empty()) { - int front = tmp.front(); tmp.pop_front(); res.push_back(front); - if (front == 0) continue; - else { - tmp.push_back(le[front]); - tmp.push_back(ri[front]); - }; - }; - - while (!res.empty() && res.front() != 0) { - res.pop_front(); - }; - - while (!res.empty() && res.front() == 0) { - res.pop_front(); - }; - - std::cout << (res.empty() ? 'Y' : 'N') << std::endl; - // - // - return 0; -} diff --git a/educoder/B.cpp b/educoder/B.cpp deleted file mode 100644 index 101cd80..0000000 --- a/educoder/B.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include - -using namespace std; - -bool OK(const vector& nums, const int& n, int eps) { - vector lower(n), upper(n); - for (int i = 0; i < n; i++) { - lower[i] = max(1, nums[i] - eps); - upper[i] = nums[i] + eps; - }; - int start = lower[0]; - for (int i = 1; i < n; i++) { - if (start + 1 <= upper[i]) start = max(lower[i], start + 1); - else return false; - }; - return true; -}; - -int main() -{ - int n; cin >> n; - vector nums(n); - for (int i = 0; i < n; i++) - cin >> nums[i]; - int left = 1, right = 1e9 + 7; - while (left <= right) { - int mid = (left + right) >> 1; - if (OK(nums, n, mid)) right = mid - 1; - else left = mid + 1; - }; - cout << right + 1 << endl; - return 0; -} \ No newline at end of file diff --git a/educoder/E.cpp b/educoder/E.cpp deleted file mode 100644 index fe7d983..0000000 --- a/educoder/E.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main() -{ - int k, n; cin >> k >> n; - for (int i = 0; i < n; i++) { - k += min(k / 10, 5) + 5; - }; - cout << k << endl; - return 0; -} \ No newline at end of file diff --git a/educoder/G.cpp b/educoder/G.cpp deleted file mode 100644 index 7523e08..0000000 --- a/educoder/G.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main() -{ - int n; cin >> n; - int N = 50; - vector ans; - for (int i = 1; i < 100; i++) - if (i <= n) - ans.push_back(to_string(i) + ".mp4"); - - int base = 10; - for (int i = 0; i < 8; i++) { - base *= 10; - for (int j = base; j <= base + 100; j++) - if (j <= n) - ans.push_back(to_string(j) + ".mp4"); - }; - sort(ans.begin(), ans.end(), less()); - for (int i = 0; i < N; i++) - cout << ans[i] << endl; - return 0; -} - -// int main() -// { -// vector v; -// for (int i = 1; i < 10000; i++) -// v.push_back(i); -// sort(v.begin(), v.end(), [](const int& a, const int& b) { -// return to_string(a) < to_string(b); -// }); -// for (int i = 0; i < v.size(); i++) -// cout << v[i] << endl; -// return 0; -// } \ No newline at end of file diff --git a/educoder/I.cpp b/educoder/I.cpp deleted file mode 100644 index 26d4536..0000000 --- a/educoder/I.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#define ll long long -using namespace std; -const ll N=1e6+5; -ll n,b[N],a[N],ans; -//b[i]表示二进制下的第i位 -void update(ll x){ - for(ll i=60;i>=0;i--){ - if( (x >> i) & 1 ){//如果x在二进制表示下含有第i位 - if(b[i])x^=b[i];//如果b[i]存在则让x^b[i], - //因为之前b[i]也是由已经保存过的a[]数组贡献的 - //所以,这样异或x可以看作x于之前的a[]数组进行异或 - //然后一直异或到为0或者当前b[i]还没有被赋值 - else { b[i] = x ;break;}//否则b[i]赋值为x, - //表示当前二进制下的第i位可以被异或出来,且x的最高位就是i - } - } -} - -int main(){ - cin>>n; - for(ll i=1;i<=n;i++){cin>>a[i];update(a[i]);}//读入数据对于每一个数字都下放来维护b[i] - for(ll i=60;i>=0;i--)if((ans^(1ll<ans)ans^=b[i]; - //贪心的过程,ans看作一个二进制数,从高位开始,如果b[i]存在, - //肯定优先跟b[i]异或,倒着让小值不会影响到大值 - cout< -#include -#include - -using namespace std; - -int main() -{ - int m, n, k; cin >> m >> n >> k; - - vector> nums(m, vector(n / m + 1, 0)); - - int idx = 1, x, y; - for (int j = 0; idx <= n; j++) - for (int i = 0; i < m && idx <= n; i++) { - nums[i][j] = idx; - if (idx == k) { - x = i; - y = j; - }; - idx++; - }; - int ans = (y > 0) + (x > 0); - - int cnt = 0; - for (int i = x; i < m; i++) - for (int j = y; j < n / m + 1; j++) { - if (nums[i][j]) - cnt++; - }; - // cout << cnt << endl; - if (cnt == 1) ans += 0; - else if (cnt <= m || m == 1) ans += 1; - else ans += 2; - - if (x == 0 || x == m - 1) - ans = min(ans, 3); - cout << ans << endl; - return 0; -} \ No newline at end of file diff --git a/educoder/K.cpp b/educoder/K.cpp deleted file mode 100644 index 8d1b709..0000000 --- a/educoder/K.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main() -{ - int n; cin >> n; - vector v(n); - for (int i = 0; i < n; i++) - cin >> v[i]; - int ans = v[0]; - for (int i = 1; i < n; i++) - ans = max(ans, v[i]); - cout << ans << endl; - return 0; -} \ No newline at end of file diff --git a/educoder/L.cpp b/educoder/L.cpp deleted file mode 100644 index 27145b0..0000000 --- a/educoder/L.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include - -using namespace std; - -const int64_t maxn= 1 << 20; - -int64_t a[maxn+2]; - -struct tree{ - int64_t l,r; - long long pre,add; -}t[4*maxn+2]; - -void bulid(int64_t p,int64_t l,int64_t r){ - t[p].l=l;t[p].r=r; - if(l==r){ - t[p].pre=a[l]; - return; - } - int64_t mid=l+r>>1; - bulid(p*2,l,mid); - bulid(p*2+1,mid+1,r); - t[p].pre=t[p*2].pre+t[p*2+1].pre; -} - -void spread(int64_t p){ - if(t[p].add){ - t[p*2].pre+=t[p].add*(t[p*2].r-t[p*2].l+1); - t[p*2+1].pre+=t[p].add*(t[p*2+1].r-t[p*2+1].l+1); - t[p*2].add+=t[p].add; - t[p*2+1].add+=t[p].add; - t[p].add=0; - } -} - -void change(int64_t p,int64_t x,int64_t y,int64_t z){ - if(x<=t[p].l && y>=t[p].r){ - t[p].pre+=(long long)z*(t[p].r-t[p].l+1); - t[p].add+=z; - return; - } - spread(p); - int64_t mid=t[p].l+t[p].r>>1; - if(x<=mid) change(p*2,x,y,z); - if(y>mid) change(p*2+1,x,y,z); - t[p].pre=t[p*2].pre+t[p*2+1].pre; -} - -long long ask(int64_t p,int64_t x,int64_t y){ - if(x<=t[p].l && y>=t[p].r) return t[p].pre; - spread(p); - int64_t mid=t[p].l+t[p].r>>1; - long long ans=0; - if(x<=mid) ans+=ask(p*2,x,y); - if(y>mid) ans+=ask(p*2+1,x,y); - return ans; -} - -int main(){ - int64_t n,m,level=1; - scanf("%lld%lld",&n,&m); - while (pow(2, level) <= n) level++; - level = pow(2, level) - 1; - for(int64_t i=1;i<=n;i++) - scanf("%lld",&a[i]); - bulid(1,1,n); - for(int64_t i=1;i<=m;i++) - { - int64_t x,y,z; - scanf("%lld%lld%lld",&x,&y,&z); - change(1,x,y,z); - cout<< ask(1,1,n) * level< str: - path = os.getcwd() + '/README.md' - markdown = os.path.exists(path) - if not markdown: - markdown = open(path, 'w') - markdown.write('# Leetcode\n\n| Cnt | Problem | Solution | Difficulty | date |\n| :--: | :-- | :-- | :-- | :--: |\n') - markdown.close() - return 'REAMDE.md file successfully generated.' - else: return 'README.md file already exists.' - - -def append(entry) -> str: - path = os.getcwd() + '/README.md' - markdown = os.path.exists(path) - if not markdown: return "README.md file not exists. Use `generate.py -g` to init." - else: - markdown = open(path, 'w+') - markdown.write('') - - -def commit() -> str: - pass - - -def main(argv): - try: - opts, args = getopt.getopt(argv, "hga:", ["help", "generate", "append="]) - except getopt.GetoptError: - print('Use `generate.py -h` to get usage information.') - sys.exit(2) - for opt, arg in opts: - if opt in ('-h', '--help'): - print('generate.py -g : Generate a markdown file using specified formats.') - print('generate.py -a : Append one entry to the markdown file.') - sys.exit() - elif opt in ('-g', '--generate'): - print(generate()) - elif opt in ('-a', '--append'): - print(append(arg)) - elif opt in ('-c', '--commit'): - print(commit()) - else: print('Unknown option.') - - -if __name__ == '__main__': - main(sys.argv[1:]) \ No newline at end of file diff --git a/kickstart/Round-A-2021-K-Goodness-String.cpp b/kickstart/Round-A-2021-K-Goodness-String.cpp deleted file mode 100644 index 6c8d5bc..0000000 --- a/kickstart/Round-A-2021-K-Goodness-String.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int T; cin >> T; - for (int t = 1; t <= T; t++) { - int N, K; cin >> N >> K; - string str; cin >> str; str = ' ' + str; - int tot = 0; - for (int i = 1; i <= N / 2; i++) { - if (str[i] != str[N - i + 1]) - tot++; - }; - cout << "Case #" << t << ": " << abs(tot - K) << endl; - }; - return 0; -}; \ No newline at end of file diff --git a/kickstart/Round-A-2021-L-Shaped-Plots.cpp b/kickstart/Round-A-2021-L-Shaped-Plots.cpp deleted file mode 100644 index d6eb50b..0000000 --- a/kickstart/Round-A-2021-L-Shaped-Plots.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int T; cin >> T; - for (int i = 1; i <= T; i++) { - int R, C; cin >> R >> C; - vector< vector > v(R, vector(C, 0)); - for (int j = 0; j < R; j++) - for (int k = 0; k < C; k++) - cin >> v[j][k]; - - vector< vector > prefix_row(R, vector(C, 0)); - for (int j = 0; j < R; j++) - for (int k = 0; k < C; k++) { - if (k == 0) prefix_row[j][0] = v[j][0]; - else prefix_row[j][k] = v[j][k] == 1 ? prefix_row[j][k - 1] + v[j][k] : 0; - }; - vector< vector > prefix_col(R, vector(C, 0)); - for (int k = 0; k < C; k++) - for (int j = 0; j < R; j++) { - if (j == 0) prefix_col[0][k] = v[0][k]; - else prefix_col[j][k] = v[j][k] == 1 ? prefix_col[j - 1][k] + v[j][k] : 0; - }; - - int ans = 0; - for (int j = 0; j < R; j++) - for (int k = 0; k < C; k++) { - if (prefix_row[j][k] > 1 && prefix_col[j][k] > 1) { - ans += min(prefix_row[j][k] >> 1, prefix_col[j][k]) + min(prefix_col[j][k] >> 1, prefix_row[j][k]) - 2; - }; - }; - cout << "Case #" << i << ": " << ans << endl; - }; - return 0; -}; \ No newline at end of file diff --git a/kickstart/Session-1-2022-Centauri-Prime.cpp b/kickstart/Session-1-2022-Centauri-Prime.cpp deleted file mode 100644 index d9a9fa3..0000000 --- a/kickstart/Session-1-2022-Centauri-Prime.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -using namespace std; - -string GetRuler(const string& kingdom) { - // TODO: implement this method to determine the ruler name, given the kingdom. - string ruler = ""; - char end = kingdom.back(); - char const init_s [] = { - 'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u' - }; - set s (std::begin(init_s), std::end(init_s)); - if (end == 'y' || end == 'Y') ruler = "nobody"; - else if (s.find(end) != s.end()) ruler = "Alice"; - else ruler = "Bob"; - return ruler; -} - -int main() { - int testcases; - cin >> testcases; - string kingdom; - - for (int t = 1; t <= testcases; ++t) { - cin >> kingdom; - cout << "Case #" << t << ": " << kingdom << " is ruled by " - << GetRuler(kingdom) << ".\n"; - } - return 0; -} diff --git a/kickstart/Session-1-2022-H-index.cpp b/kickstart/Session-1-2022-H-index.cpp deleted file mode 100644 index ad34728..0000000 --- a/kickstart/Session-1-2022-H-index.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include - -using namespace std; - -vector GetHIndexScore(vector citations_per_paper) { - int len = citations_per_paper.size(); - vector h_index; - // TODO: Calculate and return h-index score for each paper. - vector cnt(1e5 + 1, 0); - int cur = 0, tot = 0; - for (auto &paper : citations_per_paper) { - cnt[paper]++; - if (paper >= cur) tot++; - - while (tot - cnt[cur] > cur) { - tot -= cnt[cur]; - cur++; - }; - - h_index.push_back(cur); - }; - return h_index; -} - -int main() { - int tests; - cin >> tests; - for (int test_case = 1; test_case <= tests; test_case++) { - // Get number of papers for this test case - int paper_count; - cin >> paper_count; - // Get number of citations for each paper - vector citations(paper_count); - for (int i = 0; i < paper_count; i++) { - cin >> citations[i]; - } - vector answer = GetHIndexScore(citations); - cout << "Case #" << test_case << ": "; - for (int i = 0; i < answer.size(); i++) { - cout << answer[i] << " "; - } - cout << endl; - } - return 0; -} diff --git a/kickstart/Session-1-2022-Hex.cpp b/kickstart/Session-1-2022-Hex.cpp deleted file mode 100644 index ee7442d..0000000 --- a/kickstart/Session-1-2022-Hex.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include - -using namespace std; - -bool dfs(const int size, const char (*board)[100], vector< vector >& flag, const char ch, int x, int y) { - flag[x][y] = true; - - if (x == 0 && ch == 'R' && board[x][y] == 'R' || y == 0 && ch == 'B' && board[x][y] == 'B') return true; - - if (board[x][y] != ch) return false; - - int ans = false; - if (ch == 'R') { - if (x < size - 1 && !flag[x + 1][y]) ans |= dfs(size, board, flag, ch, x + 1, y); if (ans) return ans; // 下 - if (y < size - 1 && !flag[x][y + 1]) ans |= dfs(size, board, flag, ch, x, y + 1); if (ans) return ans; // 右 - if (x > 0 && !flag[x - 1][y]) ans |= dfs(size, board, flag, ch, x - 1, y); if (ans) return ans; // 上 - if (y > 0 && !flag[x][y - 1]) ans |= dfs(size, board, flag, ch, x, y - 1); if (ans) return ans; // 左 - } else if (ch == 'B') { - if (x > 0 && !flag[x - 1][y]) ans |= dfs(size, board, flag, ch, x - 1, y); if (ans) return ans; // 上 - if (y > 0 && !flag[x][y - 1]) ans |= dfs(size, board, flag, ch, x, y - 1); if (ans) return ans; // 左 - if (x < size - 1 && !flag[x + 1][y]) ans |= dfs(size, board, flag, ch, x + 1, y); if (ans) return ans; // 下 - if (y < size - 1 && !flag[x][y + 1]) ans |= dfs(size, board, flag, ch, x, y + 1); if (ans) return ans; // 右 - } - return ans; -}; - -string FindBoardStatus(int size, char (*board)[100]) { - // TODO: Complete this function to find the status of the board. - string ans = ""; - int cntB = 0, cntR = 0, winB = 0, winR = 0; - for (int i = 0; i < size; i++) - for (int j = 0; j < size; j++) { - if (board[i][j] == 'B') cntB++; - if (board[i][j] == 'R') cntR++; - }; - - vector< vector > flagB(size, vector(size, false)); - for (int i = 0; i < size; i++) { - winB += dfs(size, board, flagB, 'B', i, size - 1); - }; - vector< vector > flagR(size, vector(size, false)); - for (int j = 0; j < size; j++) { - winR += dfs(size, board, flagR, 'R', size - 1, j); - }; - - // cout << "cntB: " << cntB << "cntR: " << cntR << "winB " << winB << "winR " << winR << endl; - - if (abs(cntB - cntR) > 1 || winB + winR > 1) ans = "Impossible"; - else if (winB > 0) ans = "Blue wins"; - else if (winR > 0) ans = "Red wins"; - else ans = "Nobody wins"; - return ans; -} - -int main() { - int t; - cin >> t; - for (int tc = 1; tc <= t; ++tc) { - int n; - cin >> n; - char board[100][100]; - for (int r = 0; r < n; ++r) { - for (int c = 0; c < n; ++c) { - cin >> board[r][c]; - } - } - cout << "Case #" << tc << ": " << FindBoardStatus(n, board) << endl; - } - return 0; -} diff --git a/kickstart/Session-1-2022-Sample-Problem.cpp b/kickstart/Session-1-2022-Sample-Problem.cpp deleted file mode 100644 index 1c084f0..0000000 --- a/kickstart/Session-1-2022-Sample-Problem.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int T; cin >> T; - for (int i = 1; i <= T; i++) { - int N, M; cin >> N >> M; - int tot = 0, tmp; - while (N-- > 0) { - cin >> tmp; - tot += tmp; - }; - cout << "Case #" << i << ": " << tot % M << endl; - }; - return 0; -} \ No newline at end of file diff --git "a/\346\264\233\350\260\267/P1000.cpp" "b/\346\264\233\350\260\267/P1000.cpp" deleted file mode 100644 index 9d6af53..0000000 --- "a/\346\264\233\350\260\267/P1000.cpp" +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - printf( -" ********\n" -" ************\n" -" ####....#.\n" -" #..###.....##....\n" -" ###.......###### ### ###\n" -" ........... #...# #...#\n" -" ##*####### #.#.# #.#.#\n" -" ####*******###### #.#.# #.#.#\n" -" ...#***.****.*###.... #...# #...#\n" -" ....**********##..... ### ###\n" -" ....**** *****....\n" -" #### ####\n" -" ###### ######\n" -"##############################################################\n" -"#...#......#.##...#......#.##...#......#.##------------------#\n" -"###########################################------------------#\n" -"#..#....#....##..#....#....##..#....#....#####################\n" -"########################################## #----------#\n" -"#.....#......##.....#......##.....#......# #----------#\n" -"########################################## #----------#\n" -"#.#..#....#..##.#..#....#..##.#..#....#..# #----------#\n" -"########################################## ############\n"); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1002.cpp" "b/\346\264\233\350\260\267/P1002.cpp" deleted file mode 100644 index f219c36..0000000 --- "a/\346\264\233\350\260\267/P1002.cpp" +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -using namespace std; - -int A[25][25]; -long long int dp[25][25]; -long long int sum = 0; - -void Dfs(int x, int y) -{ - if (A[x][y] == 2) {sum++; return;} - - if (A[x][y] == 1) return; - - Dfs(x + 1, y); - Dfs(x, y + 1); -} - -int main() -{ - memset(A, 0, sizeof(A)); - - int n, m; cin >> n >> m; - int x, y; cin >> x >> y; - - A[2][2] = 0; // - A[n + 2][m + 2] = 2; //յ - A[x + 2][y + 2] = 1; - A[x + 1][y] = A[x][y + 1] = A[x][y + 3] = A[x + 1][y + 4] = 1; //· - A[x + 3][y] = A[x + 4][y + 1] = A[x + 4][y + 3] = A[x + 3][y + 4] = 1; - for (int i = 0; i <= n + 2; i++) - A[i][1] = A[i][m + 3] = 1; - for (int j = 0; j <= m + 2; j++) - A[1][j] = A[n + 3][j] = 1; - //Dfs(2, 2); - - memset(dp, 0, sizeof(dp)); - - dp[2][2] = 1; - - for (int i = 2; i <= n + 2; i++) - for (int j = 2; j <= m + 2; j++) - if (i == 2 && j == 2) dp[i][j] = 1; - else if (A[i][j] == 1) dp[i][j] = 0; - else dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; - - cout << dp[n + 2][m + 2]; - //cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1003.cpp" "b/\346\264\233\350\260\267/P1003.cpp" deleted file mode 100644 index 131820f..0000000 --- "a/\346\264\233\350\260\267/P1003.cpp" +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -using namespace std; -struct node -{ - int x1, x2, y1, y2; -}; - -node A[10010]; - -int main() -{ - int n; scanf("%d", &n); - - int len_x, len_y; - for (int i = 1; i <= n; i++) - { - - scanf("%d%d%d%d", &A[i].x1, &A[i].y1, &len_x, &len_y); - A[i].x2 = A[i].x1 + len_x; - A[i].y2 = A[i].y1 + len_y; - } - - int x, y; scanf("%d%d", &x, &y); - - int i = n; - while(i >= 1) - { - if (A[i].x1 <= x && x <= A[i].x2 && A[i].y1 <= y && y <= A[i].y2) - { - printf("%d", i); - break; - } - i--; - } - if (i == 0) printf("%d", -1); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1004.cpp" "b/\346\264\233\350\260\267/P1004.cpp" deleted file mode 100644 index 8aa1f4d..0000000 --- "a/\346\264\233\350\260\267/P1004.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[10][10][10][10]; -int B[10][10]; - -int main() -{ - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - - int N; cin >> N; - int x, y, num; - - cin >> x >> y >> num; - while(x != 0 || y != 0 || num != 0) - { - B[x][y] = num; - cin >> x >> y >> num; - } - - for (int i = 1; i <= N; i++) - for (int j = 1; j <= N; j++) - for (int k = 1; k <= N; k++) - for (int s = 1; s <= N; s++) - { - A[i][j][k][s] = max(max(A[i - 1][j][k - 1][s], A[i][j - 1][k][s - 1]), max(A[i - 1][j][k][s - 1], A[i][j - 1][k - 1][s])) + B[i][j] + B[k][s]; - if (i == k && j == s) A[i][j][k][s] -= B[i][j]; - } - - cout << A[N][N][N][N]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1005.cpp" "b/\346\264\233\350\260\267/P1005.cpp" deleted file mode 100644 index d7e01e9..0000000 --- "a/\346\264\233\350\260\267/P1005.cpp" +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -using namespace std; - -__int128 cifang[100]; -__int128 A[100]; -__int128 dp[100][100]; - -inline int read() -{ - int x; - cin >> x; - return x; -} -inline void print(__int128 x) -{ - if (x > 9) print(x / 10); - putchar(x % 10 + '0'); -} - -int main() -{ - int n, m; cin >> n >> m; - - cifang[0] = 1; - for (int i = 1 ; i < 100; i++) - cifang[i] = 2 * cifang[i - 1]; - - __int128 sum = 0; - - while(n--) - { - for (int i = 1; i <= m; i++) - A[i] = read(); - - dp[0][m + 1] = 0; - - for (int i = m; i >= 1; i--) //i + 1䳤 - { - for (int j = 0; j <= m - i + 1; j++) //j˵ - { - int left = j; - int right = j + i; - if (left == 0) dp[left][right] = dp[left][right + 1] + A[right] * cifang[m - i + 1]; - else if (right == m + 1) dp[left][right] = dp[left - 1][right] + A[left] * cifang[m - i + 1]; - else - dp[left][right] = max(A[left] * cifang[m - i + 1] + dp[left - 1][right], A[right] * cifang[m - i + 1] + dp[left][right + 1]); - } - } - - __int128 res = 0; - for (int i = 0; i <= m; i++) - res = max(res, dp[i][i + 1]); - //cout << res << endl; - sum += res; - } - print(sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1006.cpp" "b/\346\264\233\350\260\267/P1006.cpp" deleted file mode 100644 index 718c0a3..0000000 --- "a/\346\264\233\350\260\267/P1006.cpp" +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -int A[60][60]; -int dp[60][60][60][60]; - -int main() -{ - int n, m; scanf("%d%d", &n, &m); - - memset(A, 0, sizeof(A)); - memset(dp, 0, sizeof(dp)); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= m; j++) - scanf("%d", &A[i][j]); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= m; j++) - for (int k = 1; k <= n; k++) - for (int s = 1; s <= m; s++) - { - if (i == 1 && j == 1 && k == 1 && s == 1) - dp[i][j][k][s] = 0; - else - if (i == k && j == s && (i != n || j != m)) dp[i][j][k][s] -= 1e9; - else dp[i][j][k][s] = A[i][j] + A[k][s] + max(max(dp[i - 1][j][k - 1][s], dp[i - 1][j][k][s - 1]), max(dp[i][j - 1][k - 1][s], dp[i][j - 1][k][s - 1])); - } - cout << dp[n][m][n][m]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1007.cpp" "b/\346\264\233\350\260\267/P1007.cpp" deleted file mode 100644 index e49ac5e..0000000 --- "a/\346\264\233\350\260\267/P1007.cpp" +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include -using namespace std; - -int A[5010]; -int main() -{ - int L, N; scanf("%d%d", &L, &N); - - memset(A, 0, sizeof(A)); - - int tmp; - int m = 0, M; - int l = L + 1, r = 0; - for (int i = 1; i <= N; i++) - { - scanf("%d", &tmp); - A[tmp] = 1; - - m = max(m, min(tmp, L + 1 - tmp)); //ȡм - l = min(l, tmp); // - r = max(r, tmp); //ұ - } - M = max(L + 1 - l, r); - - printf("%d %d", m, M); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1008.cpp" "b/\346\264\233\350\260\267/P1008.cpp" deleted file mode 100644 index fdc1def..0000000 --- "a/\346\264\233\350\260\267/P1008.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -#include - -using namespace std; - -int main() -{ - double A, B, C; cin >> A >> B >> C; - bool flag = false; - - for (int a = 1; a <= 9; a++) - for (int b = 1; b <= 9; b++) - if (b == a) continue; - else - for (int c = 1; c <= 9; c++) - if (c == b || c == a) continue; - else - for (int d = 1; d <= 9; d++) - if (d == c || d == b || d == a) continue; - else - for (int e = 1; e <= 9; e++) - if (e == d || e == c || e == b || e == a) continue; - else - for (int f = 1; f <= 9; f++) - if (f == e || f == d || f == c || f == b || f == a) continue; - else - for (int g = 1; g <= 9; g++) - if (g == f || g == e || g == d || g == c || g == b || g == a) continue; - else - for (int h = 1; h <= 9; h++) - if (h == g || h == f || h == e || h == d || h == c || h == b || h == a) continue; - else - for (int i = 1; i <= 9; i++) - if (i == h || i == g || i == f || i == e || i == d || i == c || i == b || i == a) continue; - else - { - double x1 = a * 100 + b * 10 + c * 1; - double x2 = d * 100 + e * 10 + f * 1; - double x3 = g * 100 + h * 10 + i * 1; - if (x1 * B == x2 * A && x1 * C == x3 * A) - { - cout << x1 << " " << x2 << " " << x3 << endl; - flag = true; - } - } - if (!flag) cout << "No!!!"; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1009.cpp" "b/\346\264\233\350\260\267/P1009.cpp" deleted file mode 100644 index 2a4c047..0000000 --- "a/\346\264\233\350\260\267/P1009.cpp" +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -using namespace std; - -int A[50][100]; -int main() -{ - memset(A, 0, sizeof(A)); - - int n; cin >> n; - A[1][1] = 1; - - int x1, x2, yushu = 0; - for (int i = 2; i <= n; i++) - { - x1 = i % 10; - x2 = i / 10; - for (int j = 1; j < 100; j++) - { - A[i][j] = x1 * A[i - 1][j] + x2 * A[i - 1][j - 1] + yushu; - yushu = A[i][j] / 10; - A[i][j] %= 10; - } - } - - int res[100]; - memset(res, 0, sizeof(res)); - - yushu = 0; - for (int i = 1; i < 100; i++) - { - for (int j = 1; j <= n; j++) - res[i] += A[j][i]; - res[i] += yushu; - yushu = res[i] / 10; - res[i] %= 10; - } - - int xb = 99; - for (; xb >= 1 && res[xb] == 0; xb--); - for (; xb >= 1; xb--) - cout << res[xb]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1010.cpp" "b/\346\264\233\350\260\267/P1010.cpp" deleted file mode 100644 index 36e4f7e..0000000 --- "a/\346\264\233\350\260\267/P1010.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -#include - -using namespace std; - -int A[20] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768}; - -void f(int x) -{ - if (x == 0) return; - for (int i = 0; i < 20; i++) - if (x >= A[i] && x < A[i + 1]) - { - if (i == 0) - cout << "2(0)"; - else if (i == 1) - cout << "2"; - else if (i == 2) - cout << "2(2)"; - //else if (i == 2 || i == 4 || i == 8 || i == 16) - //cout << 2 << '(' << i << ')'; - else - { - cout << "2("; - f(i); - cout << ")"; - } - if (x != A[i]) - { - cout << '+'; - f(x - A[i]); - } - break; - } - return; -} - -int main() -{ - int N; cin >> N; - /*for (int i = 1; i < 20000; i++) - { - f(i); - cout << '\n'; - }*/ - f(N); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1011.cpp" "b/\346\264\233\350\260\267/P1011.cpp" deleted file mode 100644 index c294bf2..0000000 --- "a/\346\264\233\350\260\267/P1011.cpp" +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include - -using namespace std; - -struct node -{ - int on; - int off; - int total; -}; - -node A[20]; - -int main() -{ - int a, n, m, x; scanf("%d%d%d%d", &a, &n, &m, &x); - - A[1].on = a, A[1].off = 0, A[1].total = a; - - for (int i = 0; i <= 10000; i++) - { - A[2].on = A[2].off = i; - A[2].total = A[1].total; - - for (int j = 3; j < n; j++) - { - A[j].on = A[j - 1].on + A[j - 2].on; - A[j].off = A[j - 1].on; - A[j].total = A[j - 1].total + A[j].on - A[j].off; - } - - if (A[n - 1].total == m) - { - printf("%d", A[x].total); - break; - } - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P1012.cpp" "b/\346\264\233\350\260\267/P1012.cpp" deleted file mode 100644 index e249485..0000000 --- "a/\346\264\233\350\260\267/P1012.cpp" +++ /dev/null @@ -1,19 +0,0 @@ -#include -using namespace std; - -string A[25]; - -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) cin >> A[i]; - - for (int i = 1; i < n; i++) - { - for (int j = i + 1; j <= n; j++) - if (A[j] + A[i] > A[i] + A[j]) - swap(A[j], A[i]); - } - for (int i = 1; i <= n; i++) cout << A[i]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1014.cpp" "b/\346\264\233\350\260\267/P1014.cpp" deleted file mode 100644 index 394cce6..0000000 --- "a/\346\264\233\350\260\267/P1014.cpp" +++ /dev/null @@ -1,23 +0,0 @@ -#include - -using namespace std; - -int Fib[40000]; -int main() -{ - int N; cin >> N; - - Fib[0] = 0, Fib[1] = 1; - for (int i = 2; i < 40000; i++) - Fib[i] = i + Fib[i - 1]; - - int x; - for (int j = 0; j < 40000; j++) - if (Fib[j] < N && N <= Fib[j + 1]) - { x = j; break;} - - int sun = x + 1 - (N - Fib[x] - 1); - cout << sun << '/' << x + 2 - sun; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1016.cpp" "b/\346\264\233\350\260\267/P1016.cpp" deleted file mode 100644 index 21db5ea..0000000 --- "a/\346\264\233\350\260\267/P1016.cpp" +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - double D; // - double P; //ͼ -}; - -int main() -{ - double D1, C, D2, P; cin >> D1 >> C >> D2 >> P; - int N; cin >> N; - node A[20]; - - A[0].D = 0; A[0].P = P; // - A[N + 1].D = D1; - A[N + 1].P = 0; //յ - - for (int i = 1; i <= N; i++) - { - cin >> A[i].D >> A[i].P; - if (A[i].D - A[i - 1].D > C * D2){ cout << "No Solution"; return 0;} - } - if (A[N + 1].D - A[N].D > C * D2) {cout << "No Solution"; return 0;} - - double sum = 0, oil = 0; - for (int i = 0; i <= N; i++) - { - for (int j = i + 1; j <= N + 1; j++) - if (A[j].D - A[i].D > C * D2) - { - sum += A[i].P * C; - oil += C - (A[j - 1].D - A[i].D) / D2; - i = j - 2; - break; - } - else if (A[j].P <= A[i].P) - { - sum += A[i].P * ((A[j].D - A[i].D) / D2 - oil); - oil = 0; - i = j - 1; - break; - } - } - printf("%.2f", sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1020.cpp" "b/\346\264\233\350\260\267/P1020.cpp" deleted file mode 100644 index a6220ef..0000000 --- "a/\346\264\233\350\260\267/P1020.cpp" +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -using namespace std; - -int A[100010]; -int dp_lower[100010]; -int dp_higher[100010]; -int main() -{ - int n = 1; - while(cin >> A[n]) n++; - - int dp_index = 0; - dp_lower[++dp_index] = A[1]; - for (int i = 2; i < n; i++) - { - if (A[i] <= dp_lower[dp_index]) - dp_lower[++dp_index] = A[i]; - else - { - int index = upper_bound(dp_lower + 1, dp_lower + dp_index + 1, A[i], greater()) - dp_lower; - dp_lower[index] = A[i]; - } - } - cout << dp_index << endl; - - dp_index = 0; - dp_higher[++dp_index] = A[1]; - for (int i = 2; i < n; i++) - { - if (A[i] > dp_higher[dp_index]) - dp_higher[++dp_index] = A[i]; - else - { - int index = lower_bound(dp_higher + 1, dp_higher + dp_index + 1, A[i]) - dp_higher; - dp_higher[index] = A[i]; - } - } - cout << dp_index; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1025.cpp" "b/\346\264\233\350\260\267/P1025.cpp" deleted file mode 100644 index 920e968..0000000 --- "a/\346\264\233\350\260\267/P1025.cpp" +++ /dev/null @@ -1,21 +0,0 @@ -#include - -using namespace std; -int dp[256][8]; -int main() -{ - int n, k; cin >> n >> k; - memset(dp, 0, sizeof(dp)); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= min(i, k); j++) - { - if (i < j) dp[i][j] = 0; - else if (i == j) dp[i][j] = 1; - else - dp[i][j] = dp[i - 1][j - 1] + dp[i - j][j]; - } - cout << dp[n][k]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1028.cpp" "b/\346\264\233\350\260\267/P1028.cpp" deleted file mode 100644 index 608f3fd..0000000 --- "a/\346\264\233\350\260\267/P1028.cpp" +++ /dev/null @@ -1,21 +0,0 @@ -#include - -using namespace std; - -int dp[1024]; -int main() -{ - int n; cin >> n; - - dp[0] = dp[1] = 1; - for (int i = 2; i <= n; i++) - { - if (i % 2 == 1) - dp[i] = dp[i - 1]; - else - dp[i] = dp[i - 1] + dp[i / 2]; - } - cout << dp[n]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1029.cpp" "b/\346\264\233\350\260\267/P1029.cpp" deleted file mode 100644 index 795e18e..0000000 --- "a/\346\264\233\350\260\267/P1029.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int x0, y0; cin >> x0 >> y0; - if (y0 % x0 != 0) { cout << 0; return 0;} - - int D = y0 / x0; - - bool flag; - int sum = 0; - - flag = false; - while(D % 2 == 0) - { - D /= 2; - flag = true; - } - if (flag) sum++; - - for (int i = 3; D != 1; i += 2) - { - flag = false; - while(D % i == 0) - { - D /= i; - flag = true; - } - if (flag) sum++; - } - - cout << pow(2.0, sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1031.cpp" "b/\346\264\233\350\260\267/P1031.cpp" deleted file mode 100644 index c6ce2e7..0000000 --- "a/\346\264\233\350\260\267/P1031.cpp" +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -using namespace std; -int A[128]; - -int main() -{ - int N; scanf("%d", &N); - - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - int ave = accumulate(A + 1, A + N + 1, 0) / N; - - int sum = 0; - for (int i = 1; i < N; i++) - if (A[i] < ave) - { - sum++; - A[i + 1] -= ave - A[i]; - } - else if (A[i] > ave) - { - sum++; - A[i + 1] += A[i] - ave; - } - printf("%d", sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1033.cpp" "b/\346\264\233\350\260\267/P1033.cpp" deleted file mode 100644 index f5ccb2f..0000000 --- "a/\346\264\233\350\260\267/P1033.cpp" +++ /dev/null @@ -1,18 +0,0 @@ -#include - -using namespace std; - -int main() -{ - double H, S1, V, L, K; - int n; - cin >> H >> S1 >> V >> L >> K >> n; - - double t1, t2; - t1 = sqrt(H / 5); - t2 = sqrt((H - K) / 5); - - cout << min(int (S1 - t2 * V + L), n) - max(0, int(S1 - t1 * V)); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1035.cpp" "b/\346\264\233\350\260\267/P1035.cpp" deleted file mode 100644 index 11753e6..0000000 --- "a/\346\264\233\350\260\267/P1035.cpp" +++ /dev/null @@ -1,14 +0,0 @@ -#include - -using namespace std; - -int main() -{ - double S = 0; - double k; cin >> k; - double i = 1; - for (; S <= k; i++) - S += 1 / i; - cout << int(i - 1); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1036.cpp" "b/\346\264\233\350\260\267/P1036.cpp" deleted file mode 100644 index f0e650b..0000000 --- "a/\346\264\233\350\260\267/P1036.cpp" +++ /dev/null @@ -1,40 +0,0 @@ -#include - -using namespace std; - -int A[25]; - -bool is(int x) -{ - if (x == 0 || x == 1) return false; - for (int i = 2; i <= sqrt(x) + 4; i++) - if (x % i == 0) return false; - return true; -} -int main() -{ - int n, k; cin >> n >> k; - - for (int i = 1; i <= n; i++) - cin >> A[i]; - - int x, sum, sum_xb, res = 0; - for (int i = 0; i < pow(2.0, double(n)); i++) - { - sum = sum_xb = 0; - x = i; - for (int j = 1; j <= n; j++) - { - if (x % 2) - { - sum_xb++; - sum += A[j]; - } - x = x >> 1; - } - if (sum_xb == k && is(sum)) res++; - } - - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1040.cpp" "b/\346\264\233\350\260\267/P1040.cpp" deleted file mode 100644 index e1dd0c9..0000000 --- "a/\346\264\233\350\260\267/P1040.cpp" +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -using namespace std; -unsigned int A[32]; -unsigned int dp[32][32]; -unsigned int root[32][32]; -void Dfs(int l, int r) -{ - if (l > r) return; - printf("%d ", root[l][r]); - - Dfs(l, root[l][r] - 1); - Dfs(root[l][r] + 1, r); -} -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - for (int i = 1; i <= n; i++) - dp[i][i] = A[i], dp[i][i - 1] = 1, root[i][i] = i; - - for (int i = n; i >= 1; i--) - for (int j = i + 1; j <= n; j++) - for (int k = i; k <= j; k++) - if (dp[i][j] < dp[i][k - 1] * dp[k + 1][j] + A[k]) - { - dp[i][j] = dp[i][k - 1] * dp[k + 1][j] + A[k]; - root[i][j] = k; - } - - /*for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - cout << dp[i][j] << " "; - cout << "\n"; - }*/ - printf("%d\n", dp[1][n]); - Dfs(1, n); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1042.cpp" "b/\346\264\233\350\260\267/P1042.cpp" deleted file mode 100644 index c10abfc..0000000 --- "a/\346\264\233\350\260\267/P1042.cpp" +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - string s; - char S[800000]; - int xb = 0; - - int len; - bool flag = true; - while(flag) - { - cin >> s; - len = s.length(); - for (int i = 0; i < len; i++) - if (s[i] != 'E') S[++xb] = s[i]; - else - { - flag = false; - break; - } - } - - int x = 0, y = 0; - for (int i = 1; i <= xb; i++) - { - if (S[i] == 'W') x++; - else if (S[i] == 'L') y++; - if ((x >= 11 || y >= 11) && abs(x - y) >= 2) - { - printf("%d%c%d\n", x, ':', y); - x = y = 0; - } - } - printf("%d%c%d\n", x, ':', y); - x = y = 0; - - printf("\n"); - - for (int i = 1; i <= xb; i++) - { - if (S[i] == 'W') x++; - else if (S[i] == 'L') y++; - if ((x >= 21 || y >= 21) && abs(x - y) >= 2) - { - printf("%d%c%d\n", x, ':', y); - x = y = 0; - } - } - printf("%d%c%d", x, ':', y); - x = y = 0; - - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1044.cpp" "b/\346\264\233\350\260\267/P1044.cpp" deleted file mode 100644 index 28e5cc1..0000000 --- "a/\346\264\233\350\260\267/P1044.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -#include - -using namespace std; -int dp[20]; - -int main() -{ - int n; cin >> n; - memset(dp, 0, sizeof(dp)); - dp[0] = dp[1] = 1; - - for (int i = 2; i <= n; i++) - for (int j = 0; j < i; j++) - dp[i] += dp[j] * dp[i - j - 1]; - cout << dp[n]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1045.cpp" "b/\346\264\233\350\260\267/P1045.cpp" deleted file mode 100644 index 794d613..0000000 --- "a/\346\264\233\350\260\267/P1045.cpp" +++ /dev/null @@ -1,87 +0,0 @@ -#include - -using namespace std; - -int* T; -int* base; -int* res; -const int N = 500 + 10; - -void bigplus(int *T, int *base) -{ - int yushu = 0; - for (int i = 1; i <= 500; i++) - { - T[i] += base[i] + yushu; - if (T[i] >= 10) - { - T[i] -= 10; - yushu = 1; - }else yushu = 0; - } -} -void bigminus1(int *A) -{ - int index = 1; - A[index] -= 1; - while(index <= 500 && A[index] < 0) - { - A[index] += 10; - A[++index]--; - } -} -int* bigmul(int* A, int* B) -{ - int yushu = 0; - for (int i = 1; i < N; i++) res[i] = 0; - - for (int i = 1; i <= 500; i++) - { - yushu = 0; - for (int j = 1; j <= 501 - i; j++) - { - res[i + j - 1] += A[i] * B[j] + yushu; - if (res[i + j - 1] >= 10) - { - yushu = res[i + j - 1] / 10; - res[i + j - 1] %= 10; - }else yushu = 0; - } - } - return res; -} - -void fastPower2(int k) -{ - - for (int i = 0; i < N; i++) base[i] = 0; - - base[1] = 2; - T[1] = 1; - - while(k > 1) - { - if (k & 1) - T = bigmul(T, base); - base = bigmul(base, base); - k = k >> 1; - } - -} -int main() -{ - int P; cin >> P; - cout << int(P * log10(2) + 1) << endl; - T = new int[N]; - base = new int[N]; - res = new int[N]; - for (int i = 0; i < N; i++) T[i] = 0; - - fastPower2(P); - bigminus1(T); - - for (int i = 500; i >= 1; i--) - printf("%d", T[i]); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1047.cpp" "b/\346\264\233\350\260\267/P1047.cpp" deleted file mode 100644 index 70e7c57..0000000 --- "a/\346\264\233\350\260\267/P1047.cpp" +++ /dev/null @@ -1,19 +0,0 @@ -#include - -using namespace std; - -bool T[10010]; -int main() -{ - int l, m; cin >> l >> m; - int left, right; - while(m--) - { - cin >> left >> right; - for (int i = left; i <= right; i++) - T[i] = 1; - } - cout << l + 1 - accumulate(T, T + l + 1, 0); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1048.cpp" "b/\346\264\233\350\260\267/P1048.cpp" deleted file mode 100644 index 72da9ba..0000000 --- "a/\346\264\233\350\260\267/P1048.cpp" +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -using namespace std; -struct node -{ - int value; - int time; -}; -node A[110]; - -int dp[1010]; - -int main() -{ - int T, M; scanf("%d%d", &T, &M); - for (int i = 1; i <= M; i++) - scanf("%d%d", &A[i].time, &A[i].value); - - memset(dp, 0, sizeof(dp)); - for (int i = 1; i <= M; i++) - for (int j = T; j >= A[i].time; j--) - dp[j] = max(dp[j], dp[j - A[i].time] + A[i].value); - - - cout << dp[T]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1049.cpp" "b/\346\264\233\350\260\267/P1049.cpp" deleted file mode 100644 index da269d4..0000000 --- "a/\346\264\233\350\260\267/P1049.cpp" +++ /dev/null @@ -1,44 +0,0 @@ -#include - -using namespace std; - -int A[32]; - -int T[20010]; -int T_xb = 0; - -bool flag[20010]; - -int main() -{ - int n, V; cin >> V >> n; - memset(A, 0, sizeof(A)); - memset(flag, 0, sizeof(flag)); - - for (int i = 1; i <= n; i++) - cin >> A[i]; - - int x; - for (int i = 1; i <= n; i++) - { - int tmp_xb = T_xb; - for (int j = 1; j <= tmp_xb; j++) - { - x = T[j] - A[i]; - if (x >= 0 && !flag[x]) - { - T[++T_xb] = x; - flag[x] = true; - } - } - x = V - A[i]; - if (x >= 0 && !flag[x]) - { - T[++T_xb] = x; - flag[x] = true; - } - } - for (int i = 0; i <= V; i++) - if (flag[i]) {cout << i; break;} - return 0; -} diff --git "a/\346\264\233\350\260\267/P1057.cpp" "b/\346\264\233\350\260\267/P1057.cpp" deleted file mode 100644 index 109cd93..0000000 --- "a/\346\264\233\350\260\267/P1057.cpp" +++ /dev/null @@ -1,23 +0,0 @@ -#include - -using namespace std; - -long long dp[32][32]; - -int main() -{ - int n, m; cin >> n >> m; - memset(dp, 0, sizeof(dp)); - - dp[1][0] = 1; - for (int i = 1; i <= m; i++) - for (int j = 1; j <= n; j++) - if (j == 1) - dp[j][i] += dp[n][i - 1] + dp[j + 1][i - 1]; - else if (j == n) - dp[j][i] += dp[j - 1][i - 1] + dp[1][i - 1]; - else dp[j][i] += dp[j - 1][i - 1] + dp[j + 1][i - 1]; - cout << dp[1][m]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1059.cpp" "b/\346\264\233\350\260\267/P1059.cpp" deleted file mode 100644 index e04ea08..0000000 --- "a/\346\264\233\350\260\267/P1059.cpp" +++ /dev/null @@ -1,25 +0,0 @@ -#include - -using namespace std; - -bool A[1010]; - -int main() -{ - int n; cin >> n; - int tmp, sum = 0; - - memset(A, 0, sizeof(A)); - for (int i = 0; i < n; i++) - { - cin >> tmp; - if (A[tmp] == 0) - sum++; - A[tmp] = 1; - } - cout << sum << endl; - for (int i = 1; i <= 1000; i++) - if (A[i]) cout << i << " "; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1060.cpp" "b/\346\264\233\350\260\267/P1060.cpp" deleted file mode 100644 index a969cf2..0000000 --- "a/\346\264\233\350\260\267/P1060.cpp" +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -using namespace std; -int v[30]; -int w[30]; -int dp[32000]; - -int main() -{ - int n, m; scanf("%d%d", &n, &m); - for (int i = 1; i <= m; i++) - { - scanf("%d%d", &v[i], &w[i]); - w[i] *= v[i]; - } - - memset(dp, 0, sizeof(dp)); - - for (int i = 1; i <= m; i++) - for (int j = n; j >= v[i]; j--) - dp[j] = max(dp[j], dp[j - v[i]] + w[i]); - cout << *max_element(dp, dp + n); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1063.cpp" "b/\346\264\233\350\260\267/P1063.cpp" deleted file mode 100644 index 0ee65cb..0000000 --- "a/\346\264\233\350\260\267/P1063.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -using namespace std; -int A[128]; -int dp[128][128]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) scanf("%d", &A[i]); - - int m = n, res = 0; - while(m--) - { - A[0] = A[n]; A[n + 1] = A[1]; - - memset(dp, 0, sizeof(dp)); - - int r; - for (int step = 1; step < n; step++) - for (int l = 1; r = l + step, r <= n; l++) - for (int k = r; k > l; k--) - dp[l][r] = max(dp[l][r], dp[l][k - 1] + dp[k][r] + A[l] * A[k] * A[r + 1]); - res = max(res, dp[1][n]); - - A[0] = A[n]; - for (int i = n; i >= 1; i--) - A[i] = A[i - 1]; - - /*for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - cout << dp[i][j] << " "; - cout << endl; - }*/ - } - printf("%d", res); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1064.cpp" "b/\346\264\233\350\260\267/P1064.cpp" deleted file mode 100644 index cfae18f..0000000 --- "a/\346\264\233\350\260\267/P1064.cpp" +++ /dev/null @@ -1,50 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int v; //۸ - int p; //Ҫ - int q; //Ӧ -}; -node A[80]; - -int B[4000]; //۸ΪiʱҪΪj - -int main() -{ - int n, k; cin >> n >> k; - n /= 10; - for (int i = 1; i <= k; i++) - { - cin >> A[i].v >> A[i].p >> A[i].q; - A[i].p *= A[i].v; - A[i].v /= 10; - } - - memset(B, 0, sizeof(B)); - for (int i = 1; i <= k; i++) - if (A[i].q == 0) - B[A[i].v] = A[i].p; - else - { - int x = A[i].q; //Ӧ - if (A[i].v + A[x].v <= n) - B[A[i].v + A[x].v] = max(B[A[i].v + A[x].v], A[i].p + A[x].p); - - for (int j = i - 1; j >= 1; j--) - if (A[j].q == A[i].q && A[j].v + A[i].v + A[x].v <= n) - B[A[j].v + A[i].v + A[x].v] = max(B[A[j].v + A[i].v + A[x].v], A[j].p + A[i].p + A[x].p); - } - - for (int i = 0; i <= n; i++) - { - for (int j = i - 1; j >= i / 2; j--) - B[i] = max(B[i], B[j] + B[i - j]); - //cout << B[i] << " "; - } - cout << B[n]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1068.cpp" "b/\346\264\233\350\260\267/P1068.cpp" deleted file mode 100644 index b956c70..0000000 --- "a/\346\264\233\350\260\267/P1068.cpp" +++ /dev/null @@ -1,40 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int k; // - int s; //Գɼ -}; -node A[5010]; - -bool myCompare(node a, node b) -{ - if (a.s == b.s) - return a.k < b.k; - return a.s > b.s; -} -int main() -{ - int n, m; cin >> n >> m; - m *= 1.5; - - int k, s; - for (int i = 1; i <= n; i++) - { - scanf("%d%d", &A[i].k, &A[i].s); - } - - sort(A + 1, A + n + 1, myCompare); - - - for (int i = m + 1; i <= n; i++) - if (A[i].s == A[m].s) m++; - - cout << A[m].s << " " << m << endl; - for (int i = 1; i <= m; i++) - cout << A[i].k << " " << A[i].s << endl; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1075.cpp" "b/\346\264\233\350\260\267/P1075.cpp" deleted file mode 100644 index ab5f0fe..0000000 --- "a/\346\264\233\350\260\267/P1075.cpp" +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - int n; cin >> n; - for (int i = sqrt(n) + 1; i < n; i++) - if (n % i == 0) { cout << i; break;} - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1077.cpp" "b/\346\264\233\350\260\267/P1077.cpp" deleted file mode 100644 index cb421f7..0000000 --- "a/\346\264\233\350\260\267/P1077.cpp" +++ /dev/null @@ -1,32 +0,0 @@ -#include - -using namespace std; - -int A[110][110]; -int B[110]; -const int Mod = 1000007; - -int main() -{ - int n, k; cin >> n >> k; - - memset(B, 0, sizeof(B)); - for (int i = 1; i <= n; i++) - cin >> B[i]; - - memset(A, 0, sizeof(A)); - A[0][0] = 1; - for (int i = 1; i <= n; i++) //A[i][j]ֹiֻj̵İڷ - for (int j = 0; j <= k; j++) - { - if (j == 0) A[i][j] = 1; //Ϊ0⴦ - else - for (int s = 0; s <= j && s <= B[i]; s++) //s - { - A[i][j] += A[i - 1][j - s]; - A[i][j] %= Mod; - } - } - cout << A[n][k]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1080.cpp" "b/\346\264\233\350\260\267/P1080.cpp" deleted file mode 100644 index 875c6ba..0000000 --- "a/\346\264\233\350\260\267/P1080.cpp" +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -using namespace std; - -inline long long read() -{ - long long x; - scanf("%lld", &x); - return x; -} -inline void print(__int128 x) -{ - if (x > 9) print(x / 10); - putchar(x % 10 + '0'); -} -struct node -{ - __int128 l; - __int128 r; -}; -node A[1010]; - - -bool myCompare(node a, node b) -{ - return a.l * a.r < b.l * b.r; -} -int main() -{ - int n; cin >> n; - for (int i = 0; i <= n; i++) - { - A[i].l = read(); - A[i].r = read(); - } - sort(A + 1, A + n + 1, myCompare); - - __int128 cur = 1; - __int128 M = 0; - __int128 tmp; - for (int i = 0; i < n; i++) - { - cur *= A[i].l; - if (cur > A[i + 1].r * M) - M = cur / __int128(A[i + 1].r); - } - print(M); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1086.cpp" "b/\346\264\233\350\260\267/P1086.cpp" deleted file mode 100644 index 73c5723..0000000 --- "a/\346\264\233\350\260\267/P1086.cpp" +++ /dev/null @@ -1,48 +0,0 @@ -#include -using namespace std; -struct node -{ - int x; - int y; - int num; -}; -node T[410]; -int T_xb = 0; -bool myCompare(node a, node b) -{ - return a.num > b.num; -} -int A[21][21]; - -int main() -{ - int M, N, K; cin >> M >> N >> K; - for (int i = 1; i <= M; i++) - for (int j = 1; j <= N; j++) - { - cin >> A[i][j]; - if (A[i][j] != 0) - { - ++T_xb; - T[T_xb].x = i; - T[T_xb].y = j; - T[T_xb].num = A[i][j]; - } - } - sort(T + 1, T + T_xb + 1, myCompare); - - T[0].x = 0, T[0].y = T[1].y; - int sum = 0; - for (int i = 1; i <= T_xb; i++) - { - int time = abs(T[i].y - T[i - 1].y) + abs(T[i].x - T[i - 1].x) + 1 + T[i].x; - if (K >= time) - { - sum += T[i].num; - K -= time - T[i].x; - } - else break; - } - cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1088.cpp" "b/\346\264\233\350\260\267/P1088.cpp" deleted file mode 100644 index 0d14e6f..0000000 --- "a/\346\264\233\350\260\267/P1088.cpp" +++ /dev/null @@ -1,16 +0,0 @@ -#include - -using namespace std; - -int A[10010]; - -int main() -{ - int N, M; cin >> N >> M; - for (int i = 0; i < N; i++) cin >> A[i]; - while(M--) next_permutation(A, A + N); - for (int i = 0; i < N - 1; i++) - cout << A[i] << " "; - cout << A[N - 1]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1090.cpp" "b/\346\264\233\350\260\267/P1090.cpp" deleted file mode 100644 index 609b004..0000000 --- "a/\346\264\233\350\260\267/P1090.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - priority_queue< int, vector, greater > q; - - int n; scanf("%d", &n); - int tmp; - while(n--) - { - scanf("%d", &tmp); - q.push(tmp); - } - - int sum = 0; - int x1, x2, x; - - if (n == 1) cout << q.top(); - else - while(1) - { - x1 = q.top(); q.pop(); - x2 = q.top(); q.pop(); - - x = x1 + x2; - sum += x; - - if (q.empty()) break; - q.push(x); - } - - cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1091.cpp" "b/\346\264\233\350\260\267/P1091.cpp" deleted file mode 100644 index f001655..0000000 --- "a/\346\264\233\350\260\267/P1091.cpp" +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -using namespace std; -int A[128]; -int dp_L[128], dp_R[128]; - -int main() -{ - int N; scanf("%d", &N); - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - - memset(dp_L, 0, sizeof(dp_L)); - memset(dp_R, 0, sizeof(dp_R)); - - for (int i = 1; i <= N; i++) - for (int j = i - 1; j >= 0; j--) - if (A[j] < A[i]) - dp_L[i] = max(dp_L[i], dp_L[j] + 1); - for (int i = N; i >= 1; i--) - for (int j = i + 1; j <= N + 1; j++) - if (A[j] < A[i]) - dp_R[i] = max(dp_R[i], dp_R[j] + 1); - int res = 0; - for (int i = 1; i <= N; i++) - for (int j = i + 1; j <= N; j++) - res = max(res, dp_L[i] + dp_R[j]); - cout << N - res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1093.cpp" "b/\346\264\233\350\260\267/P1093.cpp" deleted file mode 100644 index fdd9e96..0000000 --- "a/\346\264\233\350\260\267/P1093.cpp" +++ /dev/null @@ -1,40 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int Chinese; - int Math; - int English; - int total; - int label; -}; -node A[310]; - -bool myCompare(node a, node b) -{ - if (a.total == b.total) - if (a.Chinese == b.Chinese) - return a.label < b.label; - else return a.Chinese > b.Chinese; - else return a.total > b.total; - -} - -int main() -{ - int n; cin >> n; - for (int i = 0; i < n; i++) - { - cin >> A[i].Chinese >> A[i].Math >> A[i].English; - A[i].total = A[i].Chinese + A[i].Math + A[i].English; - A[i].label = i + 1; - } - for (int i = 0; i < 5; i++) - { - nth_element(A, A + i, A + n, myCompare); - cout << A[i].label << " " << A[i].total << endl; - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P1094.cpp" "b/\346\264\233\350\260\267/P1094.cpp" deleted file mode 100644 index 6a117f6..0000000 --- "a/\346\264\233\350\260\267/P1094.cpp" +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -using namespace std; - -int A[30010]; -int main() -{ - int w, n; scanf("%d%d", &w, &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - sort(A + 1, A + n + 1); - - int l = 1, r = n; - int sum = 0; - while(r > l) - { - if (A[r] + A[l] <= w) l++; - sum++; r--; - } - if (r == l) sum++; - cout << sum; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1095.cpp" "b/\346\264\233\350\260\267/P1095.cpp" deleted file mode 100644 index 81c44a5..0000000 --- "a/\346\264\233\350\260\267/P1095.cpp" +++ /dev/null @@ -1,24 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int M, S, T; cin >> M >> S >> T; - - int sum = 0; - int i = 1; - for (; i <= T; i++) - { - if (M >= 10) { sum += 60; M -= 10;} - else if (((10 - M - 1) / 4 + 1 + 1) * 17 >= S - sum) sum += 17; - else if (M + 4 * (T - i) >= 10) - M += 4; - else sum += 17; - - if (sum >= S) { cout << "Yes\n" << i; break;} - } - if (i > T) cout << "No\n" << sum; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1096.cpp" "b/\346\264\233\350\260\267/P1096.cpp" deleted file mode 100644 index 2ea7ffe..0000000 --- "a/\346\264\233\350\260\267/P1096.cpp" +++ /dev/null @@ -1,52 +0,0 @@ -#include - -using namespace std; - -int res[300]; - -int main() -{ - int n; cin >> n; - memset(res, 0, sizeof(res)); - - res[0] = 1; - for (int i = 0; i <= n; i++) - { - int yushu = 0; - for (int j = 0; j <= 205; j++) - res[j] *= 2; - for (int j = 0; j <= 205; j++) - { - res[j] += yushu; - if (res[j] >= 10) - { - yushu = res[j] / 10; - res[j] %= 10; - } - else yushu = 0; - } - } - - int tmp_index = 0; - int yushu = 2; - while(1) - { - res[tmp_index] -= yushu; - if (res[tmp_index] >= 0) break; - res[tmp_index] += 10; - yushu = 1; - tmp_index++; - } - - int index = 0; - for (int i = 205; i >= 0; i--) - if (res[i] != 0) - { - index = i; - break; - } - for (int i = index; i >= 0; i--) - cout << res[i]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1102.cpp" "b/\346\264\233\350\260\267/P1102.cpp" deleted file mode 100644 index 3934ffe..0000000 --- "a/\346\264\233\350\260\267/P1102.cpp" +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include - -using namespace std; -struct node -{ - int num; - long long times; - node():times(1){}; -}; -node A[200010]; -int ans[200010]; - -int main() -{ - int N, C; scanf("%d%d", &N, &C); - C = abs(C); //ֵ - - for (int i = 1; i <= N; i++) - scanf("%d", &ans[i]); - sort(ans + 1, ans + N + 1); - - int index = 0; - - int j; - for (int i = 1; i <= N; i = j) - { - A[++index].num = ans[i]; - j = i + 1; - while(j <= N && ans[j] == ans[i]) j++; - - A[index].times = j - i; - } - - long long res = 0; - if (C == 0) - { - for (int i = 1; i <= index; i++) - res += A[i].times * (A[i].times - 1) / 2; - printf("%lld", res); - return 0; - } - - int left = 1, right = 1; - while(right <= index) - { - while(right <= index && A[right].num - A[left].num < C) right++; - if (A[right].num - A[left].num == C) { res += A[left].times * A[right].times; left++;} - while(left <= index && A[right].num - A[left].num > C) left++; - if (A[right].num - A[left].num == C) { res += A[left].times * A[right].times; right++;} - } - printf("%lld", res); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1104.cpp" "b/\346\264\233\350\260\267/P1104.cpp" deleted file mode 100644 index 419939b..0000000 --- "a/\346\264\233\350\260\267/P1104.cpp" +++ /dev/null @@ -1,40 +0,0 @@ -#include - -using namespace std; - -struct node -{ - string s; - int year; - int month; - int day; - int label; -}; -node A[128]; - -bool myCompare(node a, node b) -{ - if (a.year == b.year) - if (a.month == b.month) - if (a.day == b.day) - return a.label > b.label; - else - return a.day < b.day; - else - return a.month < b.month; - else - return a.year < b.year; -} -int main() -{ - int n; cin >> n; - for (int i = 0; i < n; i++) - { - cin >> A[i].s >> A[i].year >> A[i].month >> A[i].day; - A[i].label = i; - } - sort(A, A + n, myCompare); - for (int i = 0; i < n; i++) - cout << A[i].s << endl; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1106.cpp" "b/\346\264\233\350\260\267/P1106.cpp" deleted file mode 100644 index 58b834c..0000000 --- "a/\346\264\233\350\260\267/P1106.cpp" +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main() -{ - string A; cin >> A; - int n = A.length(), k; cin >> k; - int ans = n - k; - - stack s; - s.push(A[0]); - - int i = 1; - for (; i < n; i++) - { - while(!s.empty() && A[i] < s.top() && k > 0) - { - s.pop(); - k--; - } - s.push(A[i]); - } - - stack res; - - while(!s.empty()) - { - res.push(s.top()); - s.pop(); - } - - while(!res.empty() && res.top() == '0') //ȥǰ - { - res.pop(); - ans--; - } - if (ans <= 0) cout << 0; - while(ans-- > 0) - { - cout << res.top(); - res.pop(); - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1115.cpp" "b/\346\264\233\350\260\267/P1115.cpp" deleted file mode 100644 index a56bd35..0000000 --- "a/\346\264\233\350\260\267/P1115.cpp" +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -using namespace std; - -int A[200010]; -int dp[200010]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - dp[1] = A[1]; - for (int i = 2; i <= n; i++) - dp[i] = dp[i - 1] > 0 ? dp[i - 1] + A[i] : A[i]; - cout << *max_element(dp + 1, dp + n + 1); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1116.cpp" "b/\346\264\233\350\260\267/P1116.cpp" deleted file mode 100644 index f502733..0000000 --- "a/\346\264\233\350\260\267/P1116.cpp" +++ /dev/null @@ -1,18 +0,0 @@ -#include - -using namespace std; - -int A[10010]; -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - cin >> A[i]; - - int sum = 0; - for (int i = 2; i <= n; i++) - for (int j = i - 1; j >= 1; j--) - if (A[j] > A[i]) sum++; - cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1125.cpp" "b/\346\264\233\350\260\267/P1125.cpp" deleted file mode 100644 index 643d0ab..0000000 --- "a/\346\264\233\350\260\267/P1125.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -#include - -using namespace std; - -int T[30]; -bool is(int x) -{ - if (x == 0 || x == 1) return false; - for (int i = 2; i <= sqrt(x); i++) - if (x % i == 0) return false; - return true; -} -int main() -{ - string s; cin >> s; - memset(T, 0, sizeof(T)); - - int M = 0, m = 1e9; - int len = s.length(); - for (int i = 0; i < len; i++) - T[s[i] - 'a']++; - - for (int i = 0; i < 30; i++) - if (T[i]) - { - if (T[i] > M) M = T[i]; - else if (T[i] < m) m = T[i]; - } - if (is(M - m)) - cout << "Lucky Word" << endl << M - m; - else - cout << "No Answer" << endl << 0; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1130.cpp" "b/\346\264\233\350\260\267/P1130.cpp" deleted file mode 100644 index 69b1314..0000000 --- "a/\346\264\233\350\260\267/P1130.cpp" +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -using namespace std; - -int dp[2001][2001]; //ʾNõMС -int T[2001][2001]; - -int main() -{ - int N, M; scanf("%d%d", &N, &M); - for (int j = 1; j <= M; j++) - for (int i = 1; i <= N; i++) - scanf("%d", &T[i][j]); - - for (int j = 0; j <= M; j++) dp[0][j] = 0; - - for (int i = 1; i <= N; i++) - for (int j = 1; j <= M; j++) - if (j == 1) - dp[i][j] = min(dp[i - 1][j], dp[i - 1][M]) + T[i][j]; - else - dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1]) + T[i][j]; - - printf("%d", *min_element(dp[N] + 1, dp[N] + M)); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1135.cpp" "b/\346\264\233\350\260\267/P1135.cpp" deleted file mode 100644 index 2da1404..0000000 --- "a/\346\264\233\350\260\267/P1135.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -using namespace std; - -struct node -{ - int layer; - int num; - node(int l, int n):layer(l), num(n){}; -}; -int A[300]; -bool T[300]; - -int main() -{ - int n; scanf("%d", &n); - int a, b; scanf("%d%d", &a, &b); - - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - memset(T, 0, sizeof(T)); - - queue q; - q.push(node(a, 0)); - - int tmp_num, tmp_layer , res = -1; - - while(!q.empty()) - { - tmp_num = q.front().num; - tmp_layer = q.front().layer; - if (tmp_layer == b) { res = tmp_num; break;}; - - q.pop(); - - if (T[tmp_layer]) continue; - T[tmp_layer] = true; - - if (tmp_layer - A[tmp_layer] >= 1) q.push(node(tmp_layer - A[tmp_layer], tmp_num + 1)); - if (tmp_layer + A[tmp_layer] <= n) q.push(node(tmp_layer + A[tmp_layer], tmp_num + 1)); - } - - printf("%d", res); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1149.cpp" "b/\346\264\233\350\260\267/P1149.cpp" deleted file mode 100644 index a7315ae..0000000 --- "a/\346\264\233\350\260\267/P1149.cpp" +++ /dev/null @@ -1,40 +0,0 @@ -#include - -using namespace std; - -int f(int x) -{ - if (x == 0) return 6; - if (x == 1) return 2; - if (x == 2) return 5; - if (x == 3) return 5; - if (x == 4) return 4; - if (x == 5) return 5; - if (x == 6) return 6; - if (x == 7) return 3; - if (x == 8) return 7; - if (x == 9) return 6; - if (x >= 10) - return f(x / 10) + f(x % 10); -} -int main() -{ - int n; cin >> n; - n -= 4; //ȥӺź͵Ⱥ - - int k, sum = 0; - for (int i = 0; i <= 1000; i++) - for (int j = 0; j <= 1000; j++) - { - int k = i + j; - if (f(i) + f(j) + f(k) == n) - { - //cout << i << " + " << j << " = " << k << endl; - sum++; - } - - } - cout << sum; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1152.cpp" "b/\346\264\233\350\260\267/P1152.cpp" deleted file mode 100644 index 0223ce9..0000000 --- "a/\346\264\233\350\260\267/P1152.cpp" +++ /dev/null @@ -1,27 +0,0 @@ -#include - -using namespace std; - -int A[1024]; -bool T[100000010]; - -int main() -{ - int n; cin >> n; - - for (int i = 0; i < n; i++) - cin >> A[i]; - - int sum = 0; - memset(T, 0, sizeof(T)); - for (int i = 1; i < n; i++) - { - int x = abs(A[i] - A[i - 1]); - if (T[x] == 0) { T[x] = 1; sum++;}; - } - - if (sum == n - 1) cout << "Jolly"; - else cout << "Not jolly"; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1154.cpp" "b/\346\264\233\350\260\267/P1154.cpp" deleted file mode 100644 index f9127bf..0000000 --- "a/\346\264\233\350\260\267/P1154.cpp" +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -using namespace std; - -int A[5010]; -bool T[1000010]; - -int main() -{ - int N; scanf("%d", &N); - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - - memset(T, 0, sizeof(T)); - for (int i = 1; i <= N; i++) - for (int j = i + 1; j <= N; j++) - if (abs(A[j] - A[i]) <= 1000000) - T[abs(A[j] - A[i])] = 1; - - bool F[1000010]; - bool flag; - int i = N; - while(1) - { - if (!T[i]) - { - memset(F, 0, sizeof(F)); - flag = true; - for (int j = 1; j <= N; j++) - if (F[A[j] % i]) { flag = false; break;} - else F[A[j] % i] = 1; - break; - } - i++; - } - cout << i; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1157.cpp" "b/\346\264\233\350\260\267/P1157.cpp" deleted file mode 100644 index 0bdab61..0000000 --- "a/\346\264\233\350\260\267/P1157.cpp" +++ /dev/null @@ -1,31 +0,0 @@ -#include - -using namespace std; - -int n, r, A[100]; - -void Dfs(int k) -{ - int i; - if (k > r) - { - for (i = 1; i <= r; i++) - cout << setw(3) << A[i]; - cout << "\n"; - return; - } - - for (i = A[k - 1] + 1; i <= n; i++) - { - A[k] = i; - Dfs(k + 1); - } -} -int main() -{ - cin >> n >> r; - A[0] = 0; - - Dfs(1); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1158.cpp" "b/\346\264\233\350\260\267/P1158.cpp" deleted file mode 100644 index a3d216a..0000000 --- "a/\346\264\233\350\260\267/P1158.cpp" +++ /dev/null @@ -1,38 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int A; - int B; -}; -node T[100010]; -bool myCompare(node a, node b) -{ - return a.A > b.A; -} -int main() -{ - int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; - int N; cin >> N; - int tmp1, tmp2; - for (int i = 1; i <= N; i++) - { - cin >> tmp1 >> tmp2; - T[i].A = (x1 - tmp1) * (x1 - tmp1) + (y1 - tmp2) * (y1 - tmp2); - T[i].B = (x2 - tmp1) * (x2 - tmp1) + (y2 - tmp2) * (y2 - tmp2); - } - sort(T + 1, T + N + 1, myCompare); - - T[0].A = T[0].B = 0; - int B_max = 0; - int sum_min = 1000000000; - for (int i = 1; i <= N; i++) - { - B_max = max(B_max, T[i - 1].B); - sum_min = min(sum_min, T[i].A + B_max); - } - cout << sum_min; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1177.cpp" "b/\346\264\233\350\260\267/P1177.cpp" deleted file mode 100644 index 2f6642b..0000000 --- "a/\346\264\233\350\260\267/P1177.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -using namespace std; - -int A[100010]; - -int main() -{ - int n; cin >> n; - - for (int i = 0; i < n; i++) - scanf("%d", &A[i]); - sort(A, A + n); - for (int i = 0; i < n; i++) - printf("%d ", A[i]); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1179.cpp" "b/\346\264\233\350\260\267/P1179.cpp" deleted file mode 100644 index 03c6286..0000000 --- "a/\346\264\233\350\260\267/P1179.cpp" +++ /dev/null @@ -1,20 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int L, R; cin >> L >> R; - int sum = 0; - for (int i = L; i <= R; i++) - { - int num = i; - while(num > 0) - { - if (num % 10 == 2) sum++; - num /= 10; - } - } - cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1203.cpp" "b/\346\264\233\350\260\267/P1203.cpp" deleted file mode 100644 index 83fd357..0000000 --- "a/\346\264\233\350\260\267/P1203.cpp" +++ /dev/null @@ -1,63 +0,0 @@ -#include - -using namespace std; -int A[800]; -int dp[800][800][2]; - -int main() -{ - int N; cin >> N; - string str; cin >> str; - for (int i = 0; i < N; i++) - switch(str[i]) - { - case 'w': A[i + 1] = A[i + 1 + N] = 0; break; - case 'r': A[i + 1] = A[i + 1 + N] = 1; break; - case 'b': A[i + 1] = A[i + 1 + N] = 2; break; - } - //for (int i = 1; i <= N; i++) cout << A[i] << " "; - N <<= 1; - int res = 0; - - memset(dp, 0, sizeof(dp)); - for (int step = 0; step < N; step++) - for (int l = 1; l <= N; l++) - if (!step) dp[l][l][0] = dp[l][l][1] = 1; - else - { - int r = l + step; - //dp[l][r] = max(dp[l + 1][r], dp[l][r - 1]); - - if (!A[l]) dp[l][r][0] = dp[l + 1][r][0] + 1; - else{ - int index = l + 1; - while(index <= r && !A[index]) index++; - - if (index <= r && A[l] == A[index]) - dp[l][r][0] = index - l + dp[index][r][0]; - else dp[l][r][0] = index - l; - } - - if (!A[r]) dp[l][r][1] = dp[l][r - 1][1] + 1; - else{ - int index = r - 1; - while(index >= l && !A[index]) index--; - - if (index >= l && A[r] == A[index]) - dp[l][r][1] = r - index + dp[l][index][1]; - else dp[l][r][1] = r - index; - } - } - A[0] = A[N]; - for (int i = N; i > 0; i--) - A[i] = A[i - 1]; - - for (int l = 1; l <= N; l++) - for (int r = l; r <= N && r - l < (N >> 1); r++) - for (int m = l; m <= r; m++) - res = max(res, dp[l][m][1] + dp[m + 1][r][0]); - - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1208.cpp" "b/\346\264\233\350\260\267/P1208.cpp" deleted file mode 100644 index 07a448b..0000000 --- "a/\346\264\233\350\260\267/P1208.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -using namespace std; - -struct node -{ - int per; - int weight; -}; -node A[5010]; -bool myCompare(node a, node b) -{ - return a.per < b.per; -} -int main() -{ - int n, m; scanf("%d%d", &n, &m); - for (int i = 1; i <= m; i++) - scanf("%d%d", &A[i].per, &A[i].weight); - - sort(A + 1, A + m + 1, myCompare); - - int res = 0; - for (int i = 1; i <= m; i++) - { - if (A[i].weight > n) - { - res += n * A[i].per; - break; - } - else - { - res += A[i].weight * A[i].per; - n -= A[i].weight; - } - } - printf("%d", res); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1216.cpp" "b/\346\264\233\350\260\267/P1216.cpp" deleted file mode 100644 index 28bcb64..0000000 --- "a/\346\264\233\350\260\267/P1216.cpp" +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -using namespace std; - -int A[1001][1001]; -int dp[1001][1001]; -int main() -{ - int r; cin >> r; - for (int i = 1; i <= r; i++) - for (int j = 1; j <= i; j++) - scanf("%d", &A[i][j]); - - memset(dp, 0, sizeof(dp)); - dp[1][1] = A[1][1]; - for (int i = 2; i <= r; i++) - for (int j = 1; j <= i; j++) - dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + A[i][j]; - int res = 0; - for (int j = 1; j <= r; j++) - res = max(res, dp[r][j]); - cout << res; - - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1217.cpp" "b/\346\264\233\350\260\267/P1217.cpp" deleted file mode 100644 index 7ca88c3..0000000 --- "a/\346\264\233\350\260\267/P1217.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; - -bool isH(int s[], int len) -{ - for (int i = 1; i <= len / 2; i++) - if (s[i] != s[len - i + 1]) return false; - return true; -} -int main() -{ - int a, b; cin >> a >> b; - - bool flag; - int len = 0; - int s[10]; - - b = min(b, 9989900); - for (int i = a; i <= b; i++) - { - int tmp = i; - - len = 0; - while(tmp > 0) - { - s[++len] = tmp % 10; - tmp /= 10; - } - - if(isH(s, len)) - { - flag = 1; - for (int j = 2; j <= sqrt(i) + 1; j++) - if (i % j == 0) {flag = false; break;} - if (flag) cout << i << endl; - } - - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P1219.cpp" "b/\346\264\233\350\260\267/P1219.cpp" deleted file mode 100644 index 0a51108..0000000 --- "a/\346\264\233\350\260\267/P1219.cpp" +++ /dev/null @@ -1,51 +0,0 @@ -#include - -using namespace std; - -int n; - -int A[30]; //A[i]¼iеyֵ -int sum = 0; - -bool B[60]; - -void Dfs(int x) -{ - if (x > n) - { - sum++; - if (sum <= 3) - { - for (int i = 1; i <= n; i++) - cout << A[i] << " "; - cout << endl; - } - return; - } - - bool flag; - for (int j = 1; j <= n; j++) - { - flag = true; - for (int i = 1; i < x; i++) - if (A[i] == j || abs(i - x) == abs(A[i] - j)) - { flag = false; break;} - - if (flag) - { - A[x] = j; - Dfs(x + 1); - } - } - return; -} - -int main() -{ - cin >> n; - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - Dfs(1); - cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1220.cpp" "b/\346\264\233\350\260\267/P1220.cpp" deleted file mode 100644 index 5d3a36c..0000000 --- "a/\346\264\233\350\260\267/P1220.cpp" +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -using namespace std; -struct node -{ - int pos; - int P; - bool flag; - node():flag(false){}; -}; -node A[52]; -int n, c, res = 0x7fffffff; -void Dfs(int index, int x, int ans, int time, int left, int right) -{ - //indexǵƺ±꣬xǵǰѹصansĵtimeѹʱ - if (ans >= res) return; - if (x == n) - res = min(res, ans); - - A[index].flag = true; - - //int left = index, right = index; - //while(left >= 1 && A[left].flag) left--; - //while(right <= n && A[right].flag) right++; - - if (left >= 1) - Dfs(left, x + 1, ans + A[left].P * (time + A[index].pos - A[left].pos), time + A[index].pos - A[left].pos, left - 1, right); - if (right <= n) - Dfs(right, x + 1, ans + A[right].P * (time + A[right].pos - A[index].pos), time + A[right].pos - A[index].pos, left, right + 1); - - A[index].flag = false; - - return; -} -int main() -{ - scanf("%d%d", &n, &c); - for (int i = 1; i <= n; i++) - scanf("%d%d", &A[i].pos, &A[i].P); - - Dfs(c, 1, 0, 0, c - 1, c + 1); - printf("%d", res); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1223.cpp" "b/\346\264\233\350\260\267/P1223.cpp" deleted file mode 100644 index e38968c..0000000 --- "a/\346\264\233\350\260\267/P1223.cpp" +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int T; - int label; -}; -node A[1010]; -bool myCompare(node a, node b) -{ - return a.T < b.T; -} -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - { - cin >> A[i].T; - A[i].label = i; - } - sort(A + 1, A + n + 1, myCompare); - - long long int sum = 0; - for (int i = 1; i <= n; i++) - { - cout << A[i].label << " "; - sum += (long long)A[i].T * (long long)(n - i); - } - printf("\n%.2f", double(sum) / n); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1226.cpp" "b/\346\264\233\350\260\267/P1226.cpp" deleted file mode 100644 index d3d503c..0000000 --- "a/\346\264\233\350\260\267/P1226.cpp" +++ /dev/null @@ -1,21 +0,0 @@ -#include - -using namespace std; -long long fastPower(long long base, long long k, long long mod) -{ - long long res = 1; - while(k > 0) - { - if (k & 1) - res = (res * base) % mod; - k = k >> 1; - base = (base * base) % mod; - } - return res % mod; //ֹk = 0mod = 1ʱ -} -int main() -{ - long long base, k, mod; cin >> base >> k >> mod; - cout << base << '^' << k << " mod " << mod << '=' << fastPower(base, k, mod); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1241.cpp" "b/\346\264\233\350\260\267/P1241.cpp" deleted file mode 100644 index 10d638a..0000000 --- "a/\346\264\233\350\260\267/P1241.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; - -int T[120]; //0ȫ1ƥ - -int main() -{ - string s; cin >> s; - int len = s.length(); - - memset(T, 0, sizeof(T)); - - for (int i = 0; i < len; i++) - if (s[i] == ']') - { - for (int j = i - 1; j >= 0; j--) - if (T[j] == 0) - if (s[j] == '(') break; - else if (s[j] == '[') { T[i] = T[j] = 1; break;} - - } - else if (s[i] == ')') - { - for (int j = i - 1; j >= 0; j--) - if (T[j] == 0) - if (s[j] == '[') break; - else if (s[j] == '(') { T[i] = T[j] = 1; break;} - } - - for (int i = 0; i < len; i++) - if (T[i] == 0) - { - if (s[i] == '(' || s[i] == ')') printf("()"); - else if (s[i] == '[' || s[i] == ']') printf("[]"); - } - else - printf("%c", s[i]); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1244.cpp" "b/\346\264\233\350\260\267/P1244.cpp" deleted file mode 100644 index b739fda..0000000 --- "a/\346\264\233\350\260\267/P1244.cpp" +++ /dev/null @@ -1,13 +0,0 @@ -#include - -using namespace std; -int dp[21]; - -int main() -{ - int h, k; cin >> h >> k; - - cout << (k + 1) * (1 << h); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1255.cpp" "b/\346\264\233\350\260\267/P1255.cpp" deleted file mode 100644 index 81237e8..0000000 --- "a/\346\264\233\350\260\267/P1255.cpp" +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -using namespace std; -const int N = 1200; -int dp[5010][N + 10]; - -void bigplus(int x, int* A, int* B) -{ - int yushu = 0; - for (int i = 1; i <= N; i++) - { - dp[x][i] = A[i] + B[i] + yushu; - if (dp[x][i] > 9) - { - dp[x][i] -= 10; - yushu = 1; - }else yushu = 0; - } -} -int main() -{ - int n; cin >> n; - if (n == 0) {cout << 0; return 0;}; - - memset(dp, 0, sizeof(dp)); - dp[0][1] = 1; - dp[1][1] = 1; - for (int i = 2; i <= n; i++) - bigplus(i, dp[i - 1], dp[i - 2]); - - int index = N; - - while(!dp[n][index]) - index--; - for (int i = index; i >= 1; i--) - cout << dp[n][i]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1271.cpp" "b/\346\264\233\350\260\267/P1271.cpp" deleted file mode 100644 index eb0c834..0000000 --- "a/\346\264\233\350\260\267/P1271.cpp" +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - int n, m; cin >> n >> m; - int *A = new int[m]; - for (int i = 0; i < m; i++) - cin >> A[i]; - sort(A, A + m); - for (int i = 0; i < m; i++) - cout << A[i] << " "; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1280.cpp" "b/\346\264\233\350\260\267/P1280.cpp" deleted file mode 100644 index 20ba283..0000000 --- "a/\346\264\233\350\260\267/P1280.cpp" +++ /dev/null @@ -1,45 +0,0 @@ -/* -dpʱ̿ʼdp[i]i ~ nʱڵʱ -ʱûdp[i] = dp[i + 1] + 1; -ʱdp[i] = max(dp[i], dp[start + last_minute]) -*/ - -#include -#include - -using namespace std; -struct node{ - int start, last_minute; - node():start(0), last_minute(0){}; - node(int s, int l):start(s), last_minute(l){}; -}; -node A[10010]; -bool nodeCompare(node a, node b){ - return a.start < b.start; -} -int dp[10010]; - -int main() -{ - int n, k; scanf("%d%d", &n, &k); - for (int i = 1; i <= k; i++) - scanf("%d%d", &A[i].start, &A[i].last_minute); - sort(A + 1, A + k + 1, nodeCompare); - - memset(dp, 0, sizeof(dp)); - int cur_work_index = k; - - for (int i = n; i >= 1; i--) - { - bool flag = true; - while (A[cur_work_index].start == i) - { - dp[i] = max(dp[i], dp[A[cur_work_index].start + A[cur_work_index].last_minute]); - cur_work_index--; - flag = false; - } - if (flag) dp[i] = dp[i + 1] + 1; - } - cout << dp[1]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1306.cpp" "b/\346\264\233\350\260\267/P1306.cpp" deleted file mode 100644 index 40e7e6e..0000000 --- "a/\346\264\233\350\260\267/P1306.cpp" +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -using namespace std; - -const long long Mod = 100000000; -long long base[3][3]; -long long res[3]; -void matrix_self_mul(long long A[][3]) -{ - long long A11 = (A[1][1] * A[1][1] + A[1][2] * A[2][1]) % Mod; - long long A12 = (A[1][1] * A[1][2] + A[1][2] * A[2][2]) % Mod; - long long A21 = (A[2][1] * A[1][1] + A[2][2] * A[2][1]) % Mod; - long long A22 = (A[2][1] * A[1][2] + A[2][2] * A[2][2]) % Mod; - A[1][1] = A11; A[1][2] = A12; A[2][1] = A21; A[2][2] = A22; - return; -} -void matrix_mul(long long A[][3], long long B[]) -{ - long long B1 = (A[1][1] * B[1] + A[1][2] * B[2]) % Mod; - long long B2 = (A[2][1] * B[1] + A[2][2] * B[2]) % Mod; - B[1] = B1; - B[2] = B2; - return; -} -long long fastPower(long long n) -{ - if (n <= 2) return 1; - - res[1] = res[2] = 1; - base[1][1] = base[1][2] = base[2][1] = 1; base[2][2] = 0; - - n -= 2; - while(n > 0) - { - if (n & 1) - matrix_mul(base, res); - matrix_self_mul(base); - n = n >> 1; - } - return res[1]; -} -long long gcd(long long n, long long m) -{ - long long tmp; - while(m > 0) - { - tmp = n % m; - n = m; - m = tmp; - } - return n; -} -int main() -{ - long long n, m; scanf("%lld%lld", &n, &m); - n = gcd(n, m); - printf("%lld", fastPower(n)); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1359.cpp" "b/\346\264\233\350\260\267/P1359.cpp" deleted file mode 100644 index 27f027c..0000000 --- "a/\346\264\233\350\260\267/P1359.cpp" +++ /dev/null @@ -1,34 +0,0 @@ -#include - -using namespace std; -int A[200][200]; -int dp[200][200]; - -int main() -{ - int n; cin >> n; - memset(A, 0, sizeof(A)); - for (int i = 1; i < n; i++) - for (int j = i + 1; j <= n; j++) - cin >> A[i][j]; - - for (int i = 0; i <= n; i++) - for (int j = 0; j <= n; j++) - if (i >= j) dp[i][j] = 0; - else dp[i][j] = A[i][j]; - - int r; - for (int step = 1; step < n; step++) - for (int l = 1; r = l + step, r <= n; l++) - for (int m = l; m < r; m++) - dp[l][r] = min(dp[l][r], min(dp[l][m] + dp[m + 1][r] + A[m][m + 1], dp[l][m] + A[m][r])); - - /*for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - cout << dp[i][j] << "\t"; - cout << endl; - }*/ - cout << dp[1][n]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1379.cpp" "b/\346\264\233\350\260\267/P1379.cpp" deleted file mode 100644 index 2f1f791..0000000 --- "a/\346\264\233\350\260\267/P1379.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include - -using namespace std; -long long mod; -long long res[3]; -long long base[3][3]; -void matrix_mul(long long A[][3], long long B[]) -{ - long long B1 = (A[1][1] * B[1] + A[1][2] * B[2]) % mod; - long long B2 = (A[2][1] * B[1] + A[2][2] * B[2]) % mod; - B[1] = B1; B[2] = B2; - return; -} -void matrix_self_mul(long long A[][3]) -{ - long long A11 = (A[1][1] * A[1][1] + A[1][2] * A[2][1]) % mod; - long long A12 = (A[1][1] * A[1][2] + A[1][2] * A[2][2]) % mod; - long long A21 = (A[2][1] * A[1][1] + A[2][2] * A[2][1]) % mod; - long long A22 = (A[2][1] * A[1][2] + A[2][2] * A[2][2]) % mod; - A[1][1] = A11; A[1][2] = A12; A[2][1] = A21; A[2][2] = A22; - return; -} -long long fastPower(long long n) -{ - if (n <= 2) return res[n]; - - n -= 2; - while(n > 0) - { - if (n & 1) - matrix_mul(base, res); - matrix_self_mul(base); - n = n >> 1; - } - return res[1]; -} -int main() -{ - long long p, q, a1, a2, n; - scanf("%lld%lld%lld%lld%lld%lld", &p, &q, &a1, &a2, &n, &mod); - res[1] = a2; res[2] = a1; - base[1][1] = p; base[1][2] = q; base[2][1] = 1; base[2][2] = 0; - printf("%lld", fastPower(n)); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1403.cpp" "b/\346\264\233\350\260\267/P1403.cpp" deleted file mode 100644 index 632da15..0000000 --- "a/\346\264\233\350\260\267/P1403.cpp" +++ /dev/null @@ -1,55 +0,0 @@ -#include - -using namespace std; -const int N = 1000000 + 10; -int Prime[N]; -bool Check[N]; -void getPrime() -{ - int tot = 0; - memset(Check, 0, sizeof(Check)); - for (int i = 2; i < N; i++) - { - if (!Check[i]) - Prime[++tot] = i; - for (int j = 1; j <= tot; j++) - { - if (i * Prime[j] > N) - break; - Check[i * Prime[j]] = true; - if (i % Prime[j] == 0) - break; - } - } -} -int main() -{ - getPrime(); - int n; cin >> n; - int res = 0; - int tmp_sum; - int tmp_res; - for (int i = 1; i <= n; i++) - { - int m = i; - tmp_res = 1; - for (int j = 1; m > 1; j++) - { - if (!Check[m]) - { - tmp_res *= 2; - break; - } - tmp_sum = 0; - while(m % Prime[j] == 0) - { - m /= Prime[j]; - tmp_sum++; - } - tmp_res *= tmp_sum + 1; - } - res += tmp_res; - } - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1433.cpp" "b/\346\264\233\350\260\267/P1433.cpp" deleted file mode 100644 index a8de53f..0000000 --- "a/\346\264\233\350\260\267/P1433.cpp" +++ /dev/null @@ -1,97 +0,0 @@ -/*#include -#include -#include -using namespace std; - -int n; -double MIN; -bool T[16]; - -struct node -{ - double x; - double y; -}; -node A[16]; - -double distance(int i, int j) -{ - double dx = (A[i].x - A[j].x) * (A[i].x - A[j].x); - double dy = (A[i].y - A[j].y) * (A[i].y - A[j].y); - return pow(dx + dy, 0.5); -} - -void Dfs(int x, double dis) //xǰ± -{ - if (dis >= MIN) return; - - bool flag = true; - - for (int i = 1; i <= n; i++) - if (!T[i]) - { - T[i] = true; - Dfs(i, dis + distance(x, i)); - T[i] = false; - flag = false; - } - - if (flag && dis < MIN) MIN = dis; - -} - -int main() -{ - scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%lf%lf", &A[i].x, &A[i].y); - A[0].x = A[0].y = 0; - MIN = 2000000000.0; - - Dfs(0, 0); - - printf("%.2lf\n", MIN); - - return 0; -}*/ - - -#include -#include - -using namespace std; -int X[16]; -int Y[16]; -double dp[16][16][16]; - -double dis(int& x1, int& y1, int& x2, int& y2) -{ - double dx2 = (x1 - x2) * (x1 - x2); - double dy2 = (y1 - y2) * (y1 - y2); - return sqrt(dx2 + dy2); -} -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%lf%lf", &X[i], &Y[i]); - - memset(dp, 0x7fffffff, sizeof(dp)); - - int r; - for (int step = 0; step < n; step++) - for (int l = 1; r = l + step, r <= n; l++) - { - if (!step) dp[l][l][l] = dis(0, 0, X[l], Y[l]); - else{ - for (int i = l; i < r; i++) - for (int j = l; j <= i; j++) - for (int k = i + 1; k <= r; k++) - { - dp[l][r][k] = min(dp[l][r][k], dp[l][i][j] + dp[i + 1][r][k] + dis(X[j], Y[j], X[k], Y[k]); - dp[l][r][j] = min() - } - } - } - -} diff --git "a/\346\264\233\350\260\267/P1434.cpp" "b/\346\264\233\350\260\267/P1434.cpp" deleted file mode 100644 index 139597f..0000000 --- "a/\346\264\233\350\260\267/P1434.cpp" +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git "a/\346\264\233\350\260\267/P1439.cpp" "b/\346\264\233\350\260\267/P1439.cpp" deleted file mode 100644 index 88776d7..0000000 --- "a/\346\264\233\350\260\267/P1439.cpp" +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include - -using namespace std; - -int A[100010]; -int From[100010]; -int To[100010]; -int dp[100010]; -struct node -{ - int num; - int index; - node(int n, int i):num(n), index(i){}; - node(){}; -}; -bool myCompare(node a, node b) -{ - return a.num < b.num; -} -node T[100010]; -int T_xb = 0; -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &From[i]); - for (int i = 1; i <= n; i++) - scanf("%d", &To[i]); - for (int i = 1; i <= n; i++) - A[From[i]] = i; - for (int i = 1; i <= n; i++) - To[i] = A[To[i]]; - //for (int i = 1; i <= n; i++) - // cin >> To[i]; - - memset(dp, 0, sizeof(dp)); - dp[1] = 1; - ++T_xb; T[T_xb].num = To[1]; T[T_xb].index = 1; - - for (int i = 2; i <= n; i++) - { - if (To[i] >= T[T_xb].num) - { - dp[i] = dp[T[T_xb].index] + 1; - T_xb++; - T[T_xb].index = i; - T[T_xb].num = To[i]; - } - else - { - node* Q = upper_bound(T + 1, T + T_xb + 1, node(To[i], i), myCompare); - dp[i] = dp[Q->index]; - Q->index = i; - Q->num = To[i]; - } - } - cout << *max_element(dp + 1, dp + n + 1); - return 0; -} - -/* -const int N = 100000 + 10; -int A[N]; -int B[N]; -int dp[2][N]; -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - for (int i = 1; i <= n; i++) - scanf("%d", &B[i]); - - memset(dp, 0, sizeof(dp)); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - { - if (A[i] == B[j]) - dp[i % 2][j] = dp[(i - 1) % 2][j - 1] + 1; - else - dp[i % 2][j] = max(dp[(i - 1) % 2][j], dp[i % 2][j - 1]); - } - - printf("%d", dp[n % 2][n]); - return 0; -} -*/ - diff --git "a/\346\264\233\350\260\267/P1443.cpp" "b/\346\264\233\350\260\267/P1443.cpp" deleted file mode 100644 index 5a38aa5..0000000 --- "a/\346\264\233\350\260\267/P1443.cpp" +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -using namespace std; - -int n, m; -struct node -{ - int x; - int y; - int steps; - node(int the_x, int the_y, int t):x(the_x), y(the_y),steps(t){}; -}; -int A[500][500]; - -bool is(int x, int y) {return x >= 1 && x <= n && y >= 1 && y <= m;}; - -const int M = 1000000000 + 7; -int main() -{ - scanf("%d%d", &n, &m); - int x, y, steps; scanf("%d%d", &x, &y); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= m; j++) - A[i][j] = M; - - queue q; - q.push(node(x, y, 1)); - - while(!q.empty()) - { - x = q.front().x; - y = q.front().y; - steps = q.front().steps; - q.pop(); - if (A[x][y] <= steps) continue; - - A[x][y] = steps; - - if (is(x - 1, y - 2)) q.push(node(x - 1, y - 2, steps + 1)); - if (is(x - 2, y - 1)) q.push(node(x - 2, y - 1, steps + 1)); - if (is(x - 2, y + 1)) q.push(node(x - 2, y + 1, steps + 1)); - if (is(x - 1, y + 2)) q.push(node(x - 1, y + 2, steps + 1)); - if (is(x + 1, y + 2)) q.push(node(x + 1, y + 2, steps + 1)); - if (is(x + 2, y + 1)) q.push(node(x + 2, y + 1, steps + 1)); - if (is(x + 2, y - 1)) q.push(node(x + 2, y - 1, steps + 1)); - if (is(x + 1, y - 2)) q.push(node(x + 1, y - 2, steps + 1)); - } - - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= m; j++) - { - if (A[i][j] == M) A[i][j] = 0; - printf("%-5d", A[i][j] - 1); - } - printf("\n"); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P1478.cpp" "b/\346\264\233\350\260\267/P1478.cpp" deleted file mode 100644 index fad7ac6..0000000 --- "a/\346\264\233\350\260\267/P1478.cpp" +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -using namespace std; - -int n, s; -int h; -struct node -{ - int xi; - int yi; -}; -node A[5010]; - -bool myCompare(node a, node b) -{ - if (a.xi > h) return false; - if (b.xi > h) return true; - - return a.yi < b.yi; -} -int main() -{ - scanf("%d%d", &n, &s); - int a, b; - scanf("%d%d", &a, &b); - h = a + b; - - for (int i = 1; i <= n; i++) - scanf("%d%d", &A[i].xi, &A[i].yi); - sort(A + 1, A + n + 1, myCompare); - - int x = 1; - while(x <= n && s >= A[x].yi && A[x].xi <= h) - { - s -= A[x].yi; - x++; - } - cout << x - 1; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1507.cpp" "b/\346\264\233\350\260\267/P1507.cpp" deleted file mode 100644 index 6a4ee9a..0000000 --- "a/\346\264\233\350\260\267/P1507.cpp" +++ /dev/null @@ -1,29 +0,0 @@ -#include - -using namespace std; -int v[50]; -int w[50]; -int h[50]; -int dp[400][400]; - -int main() -{ - int V, W; cin >> V >> W; - int N; cin >> N; - for (int i = 1; i <= N; i++) - cin >> v[i] >> w[i] >> h[i]; - - memset(dp, 0, sizeof(dp)); - - int res = 0; - for (int k = 1; k <= N; k++) - for (int i = V; i > 0; i--) - for (int j = W; j > 0; j--) - if (v[k] <= i && w[k] <= j) - { - dp[i][j] = max(dp[i][j], dp[i - v[k]][j - w[k]] + h[k]); - res = max(res, dp[i][j]); - } - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1510.cpp" "b/\346\264\233\350\260\267/P1510.cpp" deleted file mode 100644 index 42bf893..0000000 --- "a/\346\264\233\350\260\267/P1510.cpp" +++ /dev/null @@ -1,30 +0,0 @@ -#include - -using namespace std; -int v[10001]; -int c[10001]; -int dp[10001]; - -int main() -{ - int V, N, C; cin >> V >> N >> C; - for (int i = 1; i <= N; i++) - cin >> v[i] >> c[i]; - - memset(dp, 0, sizeof(dp)); - - for (int i = 1; i <= N; i++) - for (int j = C; j >= c[i]; j--) - dp[j] = max(dp[j], dp[j - c[i]] + v[i]); - - int res = 0x7fffffff; - for (int i = 0; i <= C; i++) - if (dp[i] >= V) - res = min(res, i); - - res = C - res; - if (res >= 0) cout << res; - else cout << "Impossible"; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1516.cpp" "b/\346\264\233\350\260\267/P1516.cpp" deleted file mode 100644 index 6b3962c..0000000 --- "a/\346\264\233\350\260\267/P1516.cpp" +++ /dev/null @@ -1,20 +0,0 @@ -#include - -using namespace std; - -int main() -{ - long long int x, y, m, n, L; cin >> x >> y >> m >> n >> L; - - long long int sum = x - y; - long long int m_n = m - n; m_n %= L; - - for (long long int t = 0; t <= 10000000; t++) - { - sum %= L; - if (sum == 0) { cout << t; return 0;} - sum += m_n; - } - cout << "Impossible"; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1540.cpp" "b/\346\264\233\350\260\267/P1540.cpp" deleted file mode 100644 index e29b102..0000000 --- "a/\346\264\233\350\260\267/P1540.cpp" +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -using namespace std; - -int A[1010]; -int q[1010]; - -int main() -{ - int M, N; scanf("%d%d", &M, &N); - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - - int l = 1, r = 0; - int sum = 0; - bool flag; - - for (int i = 1; i <= N; i++) - { - flag = false; - for (int j = r; j >= l; j--) - if (q[j] == A[i]) - { - flag = true; - break; - } - if (!flag) - { - sum++; - if (r - l + 1 == M) - l++; - q[++r] = A[i]; - } - } - printf("%d", sum); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1541.cpp" "b/\346\264\233\350\260\267/P1541.cpp" deleted file mode 100644 index d46b8a9..0000000 --- "a/\346\264\233\350\260\267/P1541.cpp" +++ /dev/null @@ -1,40 +0,0 @@ -#include -using namespace std; - -int A[45][45][45][45]; - -int score[400]; -int B[5]; - -int main() -{ - int N, M; cin >> N >> M; - - for (int i = 0; i < N; i++) - cin >> score[i]; - - memset(B, 0, sizeof(B)); - int tmp; - for (int i = 0; i < M; i++) - { - cin >> tmp; - B[tmp]++; - } - - memset(A, 0, sizeof(A)); - A[0][0][0][0] = score[0]; - - for (int i = 0; i <= B[1]; i++) - for (int j = 0; j <= B[2]; j++) - for (int k = 0; k <= B[3]; k++) - for (int s = 0; s <= B[4]; s++) - { - int r = i + 2 * j + 3 * k + 4 * s; - if (i > 0) A[i][j][k][s] = max(A[i][j][k][s], A[i - 1][j][k][s] + score[r]); - if (j > 0) A[i][j][k][s] = max(A[i][j][k][s], A[i][j - 1][k][s] + score[r]); - if (k > 0) A[i][j][k][s] = max(A[i][j][k][s], A[i][j][k - 1][s] + score[r]); - if (s > 0) A[i][j][k][s] = max(A[i][j][k][s], A[i][j][k][s - 1] + score[r]); - } - cout << A[B[1]][B[2]][B[3]][B[4]]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1616.cpp" "b/\346\264\233\350\260\267/P1616.cpp" deleted file mode 100644 index 1f6e29e..0000000 --- "a/\346\264\233\350\260\267/P1616.cpp" +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int value; - int time; -}; -node A[10010]; - -int dp[10000010]; - -int main() -{ - int t, m; cin >> t >> m; - for (int i = 1; i <= m; i++) - scanf("%d%d", &A[i].time, &A[i].value); - - memset(dp, 0, sizeof(dp)); - - for (int i = 1; i <= m; i++) - for (int j = A[i].time; j <= t; j++) - for (int k = 1; k * A[i].time <= j; k++) - dp[j] = max(dp[j], dp[j - k * A[i].time] + k * A[i].value); - cout << dp[t]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1627.cpp" "b/\346\264\233\350\260\267/P1627.cpp" deleted file mode 100644 index 608c28b..0000000 --- "a/\346\264\233\350\260\267/P1627.cpp" +++ /dev/null @@ -1,50 +0,0 @@ -#include - -using namespace std; - -int A[100010]; -int left_sum_less[100010]; -int left_sum_more[100010]; -int right_sum_less[100010]; -int right_sum_more[100010]; -int main() -{ - int n, b; cin >> n >> b; - int xb; - for (int i = 1; i <= n; i++) - { - cin >> A[i]; - if (A[i] == b) xb = i; - A[i] = A[i] > b ? 1 : -1; - } - A[xb] = 0; - - memset(left_sum_less, 0, sizeof(left_sum_less)); - memset(left_sum_more, 0, sizeof(left_sum_more)); - memset(right_sum_less, 0, sizeof(right_sum_less)); - memset(right_sum_more, 0, sizeof(right_sum_more)); - - int sum = 0; - for (int i = xb - 1; i >= 1; i--) - { - sum += A[i]; - if (sum >= 0) left_sum_more[sum]++; - else left_sum_less[-sum]++; - } - - sum = 0; - for (int i = xb + 1; i <= n; i++) - { - sum += A[i]; - if (sum >= 0) right_sum_more[sum]++; - else right_sum_less[-sum]++; - } - - int res = 1; // - res += left_sum_more[0] * right_sum_more[0] + left_sum_more[0] + right_sum_more[0]; - for (int i = 1; i <= 100000; i++) - res += left_sum_less[i] * right_sum_more[i] + left_sum_more[i] * right_sum_less[i]; - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1631.cpp" "b/\346\264\233\350\260\267/P1631.cpp" deleted file mode 100644 index 310b48b..0000000 --- "a/\346\264\233\350\260\267/P1631.cpp" +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -using namespace std; -int A[100010]; -int B[100010]; -int res[100010]; - -int main() -{ - int N; scanf("%d", &N); - for (int i = 1; i <= N; i++) - scanf("%d", &B[i]); - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - sort(A + 1, A + N + 1); - sort(B + 1, B + N + 1); - - priority_queue< int, vector, less > q; - - for (int i = 1; i <= N; i++) - q.push(A[1] + B[i]); - for (int i = 2; i <= N; i++) - for (int j = 1; j <= N; j++) - { - if (A[i] + B[j] >= q.top()) - continue; - q.pop(); - q.push(A[i] + B[j]); - } - - - for (int i = 1; i <= N; i++) - { - res[N - i + 1] = q.top(); - q.pop(); - } - for (int i = 1; i <= N; i++) - printf("%d ", res[i]); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1654.cpp" "b/\346\264\233\350\260\267/P1654.cpp" deleted file mode 100644 index 5afd367..0000000 --- "a/\346\264\233\350\260\267/P1654.cpp" +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -using namespace std; -double x1[100010]; double x2[100010]; double ans[100010]; double p[100010]; -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - cin >> p[i]; - - x1[0] = x2[0] = ans[0] = 0; - for (int i = 1; i <= n; i++) - { - x1[i] = (x1[i - 1] + 1) * p[i]; - x2[i] = (x2[i - 1] + 2 * x1[i - 1] + 1) * p[i]; - ans[i] = ans[i - 1] + (3 * x1[i - 1] + 3 * x2[i - 1] + 1) * p[i]; - } - printf("%.1f", ans[n]); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1664.cpp" "b/\346\264\233\350\260\267/P1664.cpp" deleted file mode 100644 index 3abd772..0000000 --- "a/\346\264\233\350\260\267/P1664.cpp" +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include - -using namespace std; -bool A[1010]; -int isT[7] = {0, 1, 3, 7, 30, 120, 365}; -int ciFang[12] = {0,1,2,4,8,16,32,64,128,256,512,1012}; - -int main() -{ - int N; scanf("%d", &N); - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - - int ses = 0; - int ses_less = 0; - int res = 0; - for (int i = 1; i <= N; i++) - { - int index = i; - - ses = max(ses - ses_less, 0); - while(index <= N && A[index]) - { - ses++; - int j = 1; - while(j <= 6 && ses >= isT[j]) j++; - j--; - - res += j; - index++; - } - - ses_less = 0; - while(index <= N && !A[index]) - { - ses_less++; - index++; - } - if (ses_less > 11) - ses_less = 11; - ses_less = ciFang[ses_less]; - - i = index - 1; - } - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1679.cpp" "b/\346\264\233\350\260\267/P1679.cpp" deleted file mode 100644 index 9c63564..0000000 --- "a/\346\264\233\350\260\267/P1679.cpp" +++ /dev/null @@ -1,25 +0,0 @@ -#include - -using namespace std; - -int A[20]; -int dp[100001]; - -int main() -{ - int n; cin >> n; - - memset(dp, 0x7f, sizeof(dp)); - int top = sqrt(sqrt(n)); - for (int i = 1; i <= top; i++) - { - A[i] = i * i * i * i; - dp[i * i * i * i] = 1; - } - - for (int i = 1; i <= top; i++) - for (int j = A[i]; j <= n; j++) - dp[j] = min(dp[j], dp[j - A[i]] + 1); - cout << dp[n]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1706.cpp" "b/\346\264\233\350\260\267/P1706.cpp" deleted file mode 100644 index cd9113b..0000000 --- "a/\346\264\233\350\260\267/P1706.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -#include -using namespace std; - -int A[10]; -int n; - -void Dfs(int i, int x) -{ - A[i] = x; - - if (i == n) - { - for (int j = 1; j <= n; j++) - cout << setw(5) << A[j]; - cout << endl; - return; - } - - bool flag = true; - for (int j = 1; j <= n; j++) - { - flag = true; - for (int k = 1; k <= i; k++) - if (A[k] == j) {flag = false; break;}; - if (flag) Dfs(i + 1, j); - } - return; -} -int main() -{ - cin >> n; - for (int i = 1; i <= n; i++) - Dfs(1, i); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1719.cpp" "b/\346\264\233\350\260\267/P1719.cpp" deleted file mode 100644 index f654b2f..0000000 --- "a/\346\264\233\350\260\267/P1719.cpp" +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -using namespace std; - -int A[121][121]; -int dp[121]; //dp[i][j]ʾiеjʱֵ - -int main() -{ - int N; scanf("%d", &N); - memset(A, 0, sizeof(A)); - for (int i = 1; i <= N; i++) - for (int j = 1; j <= N; j++) - { - scanf("%d", &A[i][j]); - A[i][j] += A[i - 1][j]; - } - - int res = 0; - for (int i = 0; i <= N; i++) - for (int j = i + 1; j <= N; j++) - { - memset(dp, 0, sizeof(dp)); - for (int k = 1; k <= N; k++) - dp[k] = A[j][k] - A[i][k]; - for (int k = 1; k <= N; k++) - if (dp[k - 1] > 0) dp[k] += dp[k - 1]; - res = max(res, *max_element(dp + 1, dp + N + 1)); - } - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1734.cpp" "b/\346\264\233\350\260\267/P1734.cpp" deleted file mode 100644 index 84cfa31..0000000 --- "a/\346\264\233\350\260\267/P1734.cpp" +++ /dev/null @@ -1,22 +0,0 @@ -#include - -using namespace std; -int A[1024]; -int dp[1024]; -int main() -{ - int S; cin >> S; - memset(A, 0, sizeof(A)); - - for (int i = 1; i <= S; i++) - for (int j = 1; j < i; j++) - if (i % j == 0) A[i] += j; - //for (int i = 1; i <= S; i++) cout << A[i] << " "; - - memset(dp, 0, sizeof(dp)); - for (int i = 1; i <= S; i++) - for (int j = S; j >= i; j--) - dp[j - i] = max(dp[j - i], dp[j] + A[i]); - cout << dp[0]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1755.cpp" "b/\346\264\233\350\260\267/P1755.cpp" deleted file mode 100644 index 6869f86..0000000 --- "a/\346\264\233\350\260\267/P1755.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -using namespace std; -const int N = 60; -long long Fib[N]; -int main() -{ - int t; cin >> t; - while(t--) - { - int n; scanf("%d", &n); - cout << n << "="; - Fib[0] = 0; Fib[1] = 1; - - for (int i = 2; i <= 51; i++) - Fib[i] = Fib[i - 1] + Fib[i - 2]; - - long long res[100]; int index = 0; - for (int i = 51; i >= 1; i--) - { - if (n >= Fib[i]) - { - res[++index] = Fib[i]; - n -= Fib[i]; - } - if (n == 0) - break; - } - cout << res[index]; - for (int i = index - 1; i >= 1; i--) - cout << "+" << res[i]; - cout << endl; - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P1757.cpp" "b/\346\264\233\350\260\267/P1757.cpp" deleted file mode 100644 index 4a09dc9..0000000 --- "a/\346\264\233\350\260\267/P1757.cpp" +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -using namespace std; -int a[1001]; -int b[1001]; -int c[1001]; -int dp[1001]; - -int main() -{ - int m, n; scanf("%d%d", &m, &n); - for (int i = 1; i <= n; i++) - scanf("%d%d%d", &a[i], &b[i], &c[i]); - - memset(dp, 0, sizeof(dp)); - for (int k = 1; k <= n; k++) - for (int v = m; v >= 0; v--) - for (int i = 1; i <= n; i++) - if (c[i] == k && v >= a[i]) - dp[v] = max(dp[v], dp[v - a[i]] + b[i]); - - cout << *max_element(dp, dp + m + 1); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1781.cpp" "b/\346\264\233\350\260\267/P1781.cpp" deleted file mode 100644 index 812760f..0000000 --- "a/\346\264\233\350\260\267/P1781.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include - -using namespace std; - -struct node -{ - string s; - int label; -}; -node A[25]; -bool myCompare(node a, node b) -{ - int len_A = a.s.length(); - int len_B = b.s.length(); - - if (len_A == len_B) - for (int i = 0; i < len_A; i++) - if (a.s[i] != b.s[i]) return a.s[i] > b.s[i]; - - return len_A > len_B; -} -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - { - cin >> A[i].s; - A[i].label = i; - } - - sort(A + 1, A + n + 1, myCompare); - - cout << A[1].label << endl << A[1].s; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1786.cpp" "b/\346\264\233\350\260\267/P1786.cpp" deleted file mode 100644 index 3de54b3..0000000 --- "a/\346\264\233\350\260\267/P1786.cpp" +++ /dev/null @@ -1,73 +0,0 @@ -#include - -using namespace std; - -struct node -{ - string name; - string job; - int value; - int grade; - int label; -}; -node A[128]; - -bool myCompare(node a, node b) -{ - if (a.job == "BangZhu") return true; - if (a.job == "FuBangZhu" && b.job == "BangZhu") return false; - if (a.job == "FuBangZhu") return true; - - if (a.value == b.value) return a.label < b.label; - - return a.value > b.value; -} - -bool myCompare2(node a, node b) -{ - if (a.job == "BangZhu") return true; - if (a.job == "FuBangZhu" && b.job == "BangZhu") return false; - if (a.job == "FuBangZhu") return true; - - if (a.job == b.job) - if (a.grade == b.grade) - return a.label < b.label; - else return a.grade > b.grade; - - return false; -} - -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - { - cin >> A[i].name >> A[i].job >> A[i].value >> A[i].grade; - A[i].label = i; - } - - sort(A + 1, A + n + 1, myCompare); - for (int i = 1; i <= n; i++) - { - if (i == 1) - A[i].job = "BangZhu"; - else if (i == 2) - A[i].job = "FuBangZhu"; - else if (4 <= i && i <= 5) - A[i].job = "HuFa"; - else if (6 <= i && i <= 9) - A[i].job = "ZhangLao"; - else if (10 <= i && i <= 16) - A[i].job = "TangZhu"; - else if (17 <= i && i <= 41) - A[i].job = "JingYing"; - else - A[i].job = "BangZhong"; - } - sort(A + 1, A + n + 1, myCompare2); - - for (int i = 1; i <= n; i++) - cout << A[i].name << " " << A[i].job << " " << A[i].grade << endl; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1802.cpp" "b/\346\264\233\350\260\267/P1802.cpp" deleted file mode 100644 index d016157..0000000 --- "a/\346\264\233\350\260\267/P1802.cpp" +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -using namespace std; - -struct node -{ - int lose; - int win; - int use; -}; -node A[1010]; -int dp[1010]; -int main() -{ - int n, x; cin >> n >> x; - for (int i = 1; i <= n; i++) - cin >> A[i].lose >> A[i].win >> A[i].use; - - memset(dp, 0, sizeof(dp)); - for (int i = 1; i <= n; i++) - { - for (int j = x; j >= A[i].use; j--) - dp[j] = max(dp[j] + A[i].lose, dp[j - A[i].use] + A[i].win); - for (int j = A[i].use - 1; j >= 0; j--) - dp[j] += A[i].lose; - } - printf("%lld", 5ll * dp[x]); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1803.cpp" "b/\346\264\233\350\260\267/P1803.cpp" deleted file mode 100644 index 93638aa..0000000 --- "a/\346\264\233\350\260\267/P1803.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int Start; - int End; -}; -node A[1000010]; - -bool myCompare(node a, node b) -{ - if (a.End == b.End) return a.Start > b.Start; - return a.End < b.End; -} -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - cin >> A[i].Start >> A[i].End; - sort(A + 1, A + n + 1, myCompare); - - int E = 0; - int sum = 0; - for (int i = 1; i <= n; i++) - if (A[i].Start >= E) - { - sum++; - E = A[i].End; - } - cout << sum; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1830.cpp" "b/\346\264\233\350\260\267/P1830.cpp" deleted file mode 100644 index e17bfe8..0000000 --- "a/\346\264\233\350\260\267/P1830.cpp" +++ /dev/null @@ -1,32 +0,0 @@ -#include -using namespace std; - -int A[101][101]; -int B[101][101]; - -int main() -{ - int n, m, x, y; cin >> n >> m >> x >> y; - int x1, y1, x2, y2; - memset(A, 0, sizeof(A)); - - for (int i = 1; i <= x; i++) - { - cin >> x1 >> y1 >> x2 >> y2; - for (int j = x1; j <= x2; j++) - for (int k = y1; k <= y2; k++) - { - A[j][k]++; - B[j][k] = i; - } - } - for (int i = 1; i <= y; i++) - { - cin >> x1 >> y1; - if (A[x1][y1]) - cout << "Y " << A[x1][y1] << " " << B[x1][y1] << endl; - else - cout << "N" << endl; - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P1853.cpp" "b/\346\264\233\350\260\267/P1853.cpp" deleted file mode 100644 index 7b5d4e1..0000000 --- "a/\346\264\233\350\260\267/P1853.cpp" +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include - -using namespace std; -long long L, R; -const long long N = 1000010; -long long Prime[N]; -bool Check[N]; -int tot = 0; - -void getPrime() -{ - memset(Check, 0, sizeof(Check)); - - for (long long i = 2; i < N; i++) - { - if (!Check[i]) - Prime[++tot] = i; - for (long long j = 1; j <= tot; j++) - { - if (i * Prime[j] > N) - break; - Check[i * Prime[j]] = true; - if (i % Prime[j] == 0) - break; - } - } - //for (int i = 1; i <= tot; i++) - //cout << Prime[i] << " "; - -} -bool isPrime[N]; - -int main() -{ - getPrime(); - cin >> L >> R; - memset(isPrime, 0, sizeof(isPrime)); - - for (long long i = 1; i <= tot; i++) - { - long long start; - if (L / Prime[i] <= 1) - start = 2 * Prime[i]; - else - { - start = (L / Prime[i]) * Prime[i]; - while(start < L) start += Prime[i]; - } - - for (long long j = start; j <= R; j += Prime[i]) - isPrime[j - L] = true; - } - - int res = 0; - for (int i = 0; i <= R - L; i++) - if (!isPrime[i]) res++; - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1880.cpp" "b/\346\264\233\350\260\267/P1880.cpp" deleted file mode 100644 index dac3521..0000000 --- "a/\346\264\233\350\260\267/P1880.cpp" +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include - -using namespace std; -int A[128]; -int dp[128][128]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) scanf("%d", &A[i]); - - int m = n, res_M = 0, res_m = 0x7fffffff; - while(m--) - { - //Сֵ - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - if (i == j) dp[i][j] = A[i]; - else dp[i][j] = 0x7fffffff; - - int r; - for (int step = 1; step < n; step++) - for (int l = 1; r = l + step, r <= n; l++) - for (int k = r - 1; k >= l; k--) - { - int sumL = 0, sumR = 0; - for (int i = l; i <= k; i++) sumL += A[i]; - for (int i = k + 1; i <= r; i++) sumR += A[i]; - if (k == l) sumL = 0; - if (k + 1 == r) sumR = 0; - dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + sumL + sumR); - } - res_m = min(res_m, dp[1][n]); - - //ֵ - memset(dp, 0, sizeof(dp)); - - for (int step = 1; step < n; step++) - for (int l = 1; r = l + step, r <= n; l++) - for (int k = r - 1; k >= l; k--) - { - int sumL = 0, sumR = 0; - for (int i = l; i <= k; i++) sumL += A[i]; - for (int i = k + 1; i <= r; i++) sumR += A[i]; - //if (k == l) sumL = 0; - dp[l][r] = max(dp[l][r], dp[l][k] + dp[k + 1][r] + sumL + sumR); - } - res_M = max(res_M, dp[1][n]); - /*for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - cout << dp[i][j] << " "; - cout << endl; - }*/ - - A[0] = A[n]; - for (int i = n; i >= 1; i--) - A[i] = A[i - 1]; - } - printf("%d\n%d\n", res_m, res_M); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1896.cpp" "b/\346\264\233\350\260\267/P1896.cpp" deleted file mode 100644 index 7f7172f..0000000 --- "a/\346\264\233\350\260\267/P1896.cpp" +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -using namespace std; -int sit[2000], gs[2000]; -int sit_index = 0; -int N, K; - -long long dp[10][2000][100]; //iõj״̬ʣk - -void Dfs(int he, int sum, int node) -{ - if (node >= N) - { - sit[++sit_index] = he; - gs[sit_index] = sum; - return; - } - - Dfs(he, sum, node + 1); //õnode - Dfs(he + (1 << node), sum + 1, node + 2); //õnodeʱnodeҪ2һ -} -int main() -{ - scanf("%d%d", &N, &K); - Dfs(0, 0, 0); - - memset(dp, 0, sizeof(dp)); - for (int i = 1; i <= sit_index; i++) dp[1][i][K - gs[i]] = 1; - - for (int i = 2; i <= N; i++) - for (int j = 1; j <= sit_index; j++) - for (int k = 1; k <= sit_index; k++) - { - - if (sit[j] & sit[k]) continue; // - if ((sit[j] << 1) & sit[k]) continue; //ƣǰλᲹ1 - if (sit[j] & (sit[k] << 1)) continue; - //cout << sit[j] << " " << sit[k] << "Yes" << endl; - - for (int s = K; s >= gs[j]; s--) dp[i][j][s - gs[j]] += dp[i - 1][k][s]; - } - long long res = 0; - for (int i = 1; i <= sit_index; i++) res += dp[N][i][0]; - - //for (int i = 1; i <= sit_index; i++) - //cout << hex << sit[i] << endl; - printf("%lld", res); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1908.cpp" "b/\346\264\233\350\260\267/P1908.cpp" deleted file mode 100644 index 473601e..0000000 --- "a/\346\264\233\350\260\267/P1908.cpp" +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include - -using namespace std; - -int A[500010]; -int tmp[500010]; -long long res = 0; -void msort(int left, int right) -{ - if (left >= right) return; - - int mid = (left + right) >> 1; - msort(left, mid); - msort(mid + 1, right); - - int L = left, R = mid + 1, index = 0; - while(L <= mid && R <= right) - if (A[L] > A[R]) - { - tmp[++index] = A[R]; - res += mid + 1 - L; - R++; - } - else - tmp[++index] = A[L++]; - while(L <= mid) - tmp[++index] = A[L++]; - while(R <= right) - tmp[++index] = A[R++]; - //ԭ - for (int i = 1; i <= index; i++) - A[left + i - 1] = tmp[i]; - return; -} -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - msort(1, n); - printf("%lld", res); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1923.cpp" "b/\346\264\233\350\260\267/P1923.cpp" deleted file mode 100644 index 805ecee..0000000 --- "a/\346\264\233\350\260\267/P1923.cpp" +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -using namespace std; - -int A[5000010]; - -int main() -{ - int n, k; cin >> n >> k; - for (int i = 0; i < n; i++) - scanf("%d", &A[i]); - nth_element(A, A + k, A + n); - cout << A[k]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P1939.cpp" "b/\346\264\233\350\260\267/P1939.cpp" deleted file mode 100644 index 5c10c32..0000000 --- "a/\346\264\233\350\260\267/P1939.cpp" +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -using namespace std; -const long long Mod = 1000000000 + 7; -long long res[4]; -long long base[4][4]; -long long tmp[4][4]; -void matrix_mul(long long A[][4], long long B[]) -{ - memset(tmp, 0, sizeof(tmp)); - for (int i = 1; i <= 3; i++) - for (int j = 1; j <= 3; j++) - tmp[1][i] = (tmp[1][i] + A[i][j] * B[j]) % Mod; - for (int i = 1; i <= 3; i++) - B[i] = tmp[1][i]; - return; -} -void matrix_self_mul(long long A[][4], long long B[][4]) -{ - memset(tmp, 0, sizeof(tmp)); - for (int i = 1; i <= 3; i++) - for (int j = 1; j <= 3; j++) - for (int k = 1; k <= 3; k++) - tmp[i][j] = (tmp[i][j] + A[i][k] * B[k][j]) % Mod; - for (int i = 1; i <= 3; i++) - for (int j = 1; j <= 3; j++) - A[i][j] = tmp[i][j]; - return; -} -long long fastPowerMatrix(int n) -{ - if (n <= 3) return 1; - memset(base, 0, sizeof(base)); - memset(res, 0, sizeof(res)); - res[0] = res[1] = res[2] = res[3] = 1; - base[1][1] = base[1][3] = base[2][1] = base[3][2] = 1; - - n -= 3; - while(n > 0) - { - if (n & 1) - matrix_mul(base, res); - matrix_self_mul(base, base); - n = n >> 1; - } - return res[1]; -} -int main() -{ - long long T; scanf("%lld", &T); - while(T--) - { - int n; - scanf("%d", &n); - printf("%lld\n", fastPowerMatrix(n)); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P1962.cpp" "b/\346\264\233\350\260\267/P1962.cpp" deleted file mode 100644 index 422356e..0000000 --- "a/\346\264\233\350\260\267/P1962.cpp" +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include - -using namespace std; - -const long long Mod = 1000000000 + 7; -long long base[3][3]; -long long res[3]; -void matrix_self_mul(long long A[][3]) -{ - long long A11 = (A[1][1] * A[1][1] + A[1][2] * A[2][1]) % Mod; - long long A12 = (A[1][1] * A[1][2] + A[1][2] * A[2][2]) % Mod; - long long A21 = (A[2][1] * A[1][1] + A[2][2] * A[2][1]) % Mod; - long long A22 = (A[2][1] * A[1][2] + A[2][2] * A[2][2]) % Mod; - A[1][1] = A11; A[1][2] = A12; A[2][1] = A21; A[2][2] = A22; - return; -} -void matrix_mul(long long A[][3], long long B[]) -{ - long long B1 = (A[1][1] * B[1] + A[1][2] * B[2]) % Mod; - long long B2 = (A[2][1] * B[1] + A[2][2] * B[2]) % Mod; - B[1] = B1; - B[2] = B2; - return; -} -long long fastPower(long long n) -{ - if (n <= 2) return 1; - - res[1] = res[2] = 1; - base[1][1] = base[1][2] = base[2][1] = 1; base[2][2] = 0; - - n -= 2; - while(n > 0) - { - if (n & 1) - matrix_mul(base, res); - matrix_self_mul(base); - n = n >> 1; - } - return res[1]; -} -int main() -{ - long long n; scanf("%lld", &n); - printf("%lld", fastPower(n)); - return 0; -} diff --git "a/\346\264\233\350\260\267/P1966.cpp" "b/\346\264\233\350\260\267/P1966.cpp" deleted file mode 100644 index 0f5dafe..0000000 --- "a/\346\264\233\350\260\267/P1966.cpp" +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include - -using namespace std; -const int mod = 100000000 - 3; -struct node -{ - int height; - int index; -}; -node A[100010]; -node B[100010]; -bool myCompare(node a, node b){return a.height < b.height;}; - -int ans[100010]; -int tmp[100010]; -long long res = 0; - -void msort(int L, int R) -{ - if (L >= R) return; - int mid = (L + R) >> 1; - msort(L, mid); - msort(mid + 1, R); - - int index = 0, left = L, right = mid + 1; - while(left <= mid && right <= R) - if (ans[left] <= ans[right]) - tmp[++index] = ans[left++]; - else - { - res = (res + mid + 1 - left) % mod; - tmp[++index] = ans[right++]; - } - while(left <= mid) tmp[++index] = ans[left++]; - while(right <= R) tmp[++index] = ans[right++]; - - for (int i = 1; i <= index; i++) - ans[L + i - 1] = tmp[i]; - return; -} -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - { - scanf("%d", &A[i].height); - A[i].index = i; - } - for (int i = 1; i <= n; i++) - { - scanf("%d", &B[i].height); - B[i].index = i; - } - - sort(A + 1, A + n + 1, myCompare); - sort(B + 1, B + n + 1, myCompare); - - for (int i = 1; i <= n; i++) - ans[A[i].index] = B[i].index; - - msort(1, n); - printf("%lld", res); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P1982.cpp" "b/\346\264\233\350\260\267/P1982.cpp" deleted file mode 100644 index 56b5ae2..0000000 --- "a/\346\264\233\350\260\267/P1982.cpp" +++ /dev/null @@ -1,55 +0,0 @@ -#include - -using namespace std; -typedef __int128 ll; -ll A[1000010]; // -ll B[1000010]; //ֵ -ll dp[1000010]; // -ll score[1000010]; // -inline int read() -{ - int x; - scanf("%d", &x); - return x; -} -inline void print(__int128 x){ - if(x < 0){ - putchar('-'); - x = -x; - } - if(x > 9) - print(x / 10); - putchar(x % 10 + '0'); -} - -int main() -{ - ll n, p; - n = read(); p = read(); - for (int i = 1; i <= n; i++) - A[i] = read(); - - ll M = B[1] = dp[1] = A[1]; - for (int i = 2; i <= n; i++) - { - if (dp[i - 1] > 0) - dp[i] = dp[i - 1] + A[i]; - else - dp[i] = A[i]; - - if (dp[i] > M) M = dp[i]; - B[i] = M; - } - - score[1] = B[1]; - M = B[1] + score[1]; - for (int i = 2; i <= n; i++) - { - if (B[i - 1] + score[i - 1] > M) M = B[i - 1] + score[i - 1]; - score[i] = M; - } - - print(*max_element(score + 1, score + n + 1) % p); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P2004.cpp" "b/\346\264\233\350\260\267/P2004.cpp" deleted file mode 100644 index be03451..0000000 --- "a/\346\264\233\350\260\267/P2004.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include - -using namespace std; -long long int A[1024][1024]; -int main() -{ - int N, M, C; scanf("%d%d%d", &N, &M, &C); - - memset(A, 0, sizeof(A)); - for (int i = 1; i <= N; i++) - for (int j = 1; j <= M; j++) - { - scanf("%lld", &A[i][j]); - A[i][j] += A[i - 1][j]; - } - - long long int res = 0, x_index, y_index; - for (int i = 0; i <= N - C; i++) - { - int j = i + C; - - long long int tmp = 0; - for (int k = 1; k <= C; k++) - tmp += A[j][k] - A[i][k]; - - if (tmp > res) - { - res = tmp; - x_index = i + 1; - y_index = 1; - } - for (int k = C + 1; k <= M; k++) - { - tmp += (A[j][k] - A[i][k]) - (A[j][k - C] - A[i][k - C]); - if (tmp > res) - { - res = tmp; - x_index = i + 1; - y_index = k - C + 1; - } - } - } - cout << x_index << " " << y_index; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P2036.cpp" "b/\346\264\233\350\260\267/P2036.cpp" deleted file mode 100644 index ccdc097..0000000 --- "a/\346\264\233\350\260\267/P2036.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; - -struct node -{ - long long int s; // - long long int k; // -}; -node A[12]; - - -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - cin >> A[i].s >> A[i].k; - - long long int t_s = 1; // - long long int t_k = 0; //ܿ - long long int x, MIN = 1e9; - for (long long int i = 1; i < pow(2.0, double(n)); i++) - { - t_s = 1; t_k = 0; - - x = i; - for (int j = 1; j <= n; j++) - { - if (x % 2 == 1) - { - t_s *= A[j].s; if (t_s > 1e10) { t_s = 1e18; break;} - t_k += A[j].k; - } - x = x >> 1; - } - - if (abs(t_s - t_k) < MIN) MIN = abs(t_s - t_k); - } - cout << MIN; - return 0; -} diff --git "a/\346\264\233\350\260\267/P2058.cpp" "b/\346\264\233\350\260\267/P2058.cpp" deleted file mode 100644 index 24b5f08..0000000 --- "a/\346\264\233\350\260\267/P2058.cpp" +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include - -using namespace std; - -int Con[100010]; // -int Time[100010]; //ʱ -int People[100010][100]; -int sum = 0; - -int main() -{ - memset(Con, 0, sizeof(Con)); - - int n, k; scanf("%d", &n); - int xb = 1; - - for (int i = 1; i <= n; i++) - { - scanf("%d", &Time[i]); - scanf("%d", &k); - People[i][0] = k; - - for (int j = 1; j <= k; j++) - { - scanf("%d", &People[i][j]); - if (Con[People[i][j]] == 0) sum++; - Con[People[i][j]]++; - } - - while (Time[i] - Time[xb] >= 86400) - { - for (int j = 1; j <= People[xb][0]; j++) - { - Con[People[xb][j]]--; - if (Con[People[xb][j]] == 0) sum--; - } - xb++; - } - printf("%d\n", sum); - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P2089.cpp" "b/\346\264\233\350\260\267/P2089.cpp" deleted file mode 100644 index b4da906..0000000 --- "a/\346\264\233\350\260\267/P2089.cpp" +++ /dev/null @@ -1,52 +0,0 @@ -#include -using namespace std; - -int C(int bottom, int top) -{ - int res = 1; - for (int i = 0; i < top; i++) - res *= bottom - i; - for (int i = 0; i < top; i++) - res /= top - i; - return res; -} -int A[12]; -int B[10000][12]; - -int main() -{ - int n; cin >> n; - if (n > 30) { cout << 0; return 0;}; - - int sum = 0, tmp; - for (A[1] = 1; A[1] <= 3; A[1]++) - for (A[2] = 1; A[2] <= 3; A[2]++) - for (A[3] = 1; A[3] <= 3; A[3]++) - for (A[4] = 1; A[4] <= 3; A[4]++) - for (A[5] = 1; A[5] <= 3; A[5]++) - for (A[6] = 1; A[6] <= 3; A[6]++) - for (A[7] = 1; A[7] <= 3; A[7]++) - for (A[8] = 1; A[8] <= 3; A[8]++) - for (A[9] = 1; A[9] <= 3; A[9]++) - for (A[10] = 1; A[10] <= 3; A[10]++) - { - tmp = 0; - for (int i = 1; i <= 10; i++) - tmp += A[i]; - if (tmp == n) - { - sum++; - for (int j = 1; j <= 10; j++) - B[sum][j] = A[j]; - } - } - - cout << sum << endl; - for (int i = 1; i <= sum; i++) - { - for (int j = 1; j <= 10; j++) - cout << B[i][j] << " "; - cout << endl; - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P2110.cpp" "b/\346\264\233\350\260\267/P2110.cpp" deleted file mode 100644 index ae65959..0000000 --- "a/\346\264\233\350\260\267/P2110.cpp" +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -using namespace std; -long long getsum(long long x) -{ - if (x <= 9) return x; - - long long res = x / 10 + 9; - long long b = x; while(b >= 10) b /= 10; - if (b > x % 10) --res; - return res; - -} -int main() -{ - long long L, R; scanf("%lld%lld", &L, &R); - printf("%lld", getsum(R) - getsum(L - 1)); - return 0; -} diff --git "a/\346\264\233\350\260\267/P2196.cpp" "b/\346\264\233\350\260\267/P2196.cpp" deleted file mode 100644 index fbb02e2..0000000 --- "a/\346\264\233\350\260\267/P2196.cpp" +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -using namespace std; - -int Landmine[21]; -int A[21][21]; -bool Go[21]; -int MAX = 0; -int N; - -int dp[21]; -int tmp_Road[21]; -int Road[21]; -int _index; - -void Dfs(int x, int label, int num) -{ - if (num <= dp[x]) return; //ڵûǰ - tmp_Road[label] = x; - - bool flag = true; - for (int i = 1; i <= N; i++) - if (A[x][i] && !Go[x]) - { - Go[x] = true; - Dfs(i, label + 1, num + Landmine[i]); - Go[x] = false; - flag = false; - } - if (flag && num > MAX) - { - MAX = num; - for (int i = 1; i <= label; i++) - Road[i] = tmp_Road[i]; - _index = label; - } -} -int main() -{ - scanf("%d", &N); - for (int i = 1; i <= N; i++) - scanf("%d", &Landmine[i]); - for (int i = 1; i <= N; i++) - for (int j = i + 1; j <= N; j++) - scanf("%d", &A[i][j]); - - - - for (int i = 1; i <= N; i++) - { - memset(Go, 0, sizeof(Go)); - memset(dp, 0, sizeof(dp)); - - Dfs(i, 1, Landmine[i]); - } - for (int i = 1; i <= _index; i++) - cout << Road[i] << " "; - cout << endl << MAX; - return 0; -} diff --git "a/\346\264\233\350\260\267/P2234.cpp" "b/\346\264\233\350\260\267/P2234.cpp" deleted file mode 100644 index 5eab45b..0000000 --- "a/\346\264\233\350\260\267/P2234.cpp" +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -using namespace std; - -struct node -{ - int num; - int day; -}; -node A[35000]; -bool myCompare(node a, node b) -{ - return a.num < b.num; -} -int main() -{ - int n; cin >> n; - - for (int i = 1; i <= n; i++) - { - scanf("%d", &A[i].num); - A[i].day = i; - } - - sort(A + 1, A + n + 1, myCompare); - - long long int m, res = 0; - - for (int i = 1; i <= n; i++) - { - if (A[i].day == 1) - res += A[i].num; - else - { - m = 1e9; - for (int j = i - 1; j >= 1; j--) - if (A[j].day < A[i].day) - { - if (A[i].num - A[j].num < m) - m = A[i].num - A[j].num; - break; - } - for (int j = i + 1; j <= n; j++) - if (A[j].day < A[i].day) - { - if (A[j].num - A[i].num < m) - m = A[j].num - A[i].num; - break; - } - res += m; - } - - } - - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P2240.cpp" "b/\346\264\233\350\260\267/P2240.cpp" deleted file mode 100644 index 20f574c..0000000 --- "a/\346\264\233\350\260\267/P2240.cpp" +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include - -using namespace std; - -struct node -{ - double m; // - double v; //۸ -}; -node A[110]; -bool myCompare(node a, node b) -{ - return a.v / a.m > b.v / b.m; -} -int main() -{ - int N, T; cin >> N >> T; - for (int i = 0; i < N; i++) - cin >> A[i].m >> A[i].v; - sort(A, A + N, myCompare); - - double sum = 0; - for (int i = 0; i < N; i++) - if (T <= A[i].m) - { - sum += double(T) * A[i].v / A[i].m; - break; - } - else - { - sum += A[i].v; - T -= A[i].m; - } - printf("%.2f", sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P2241.cpp" "b/\346\264\233\350\260\267/P2241.cpp" deleted file mode 100644 index ac0f6de..0000000 --- "a/\346\264\233\350\260\267/P2241.cpp" +++ /dev/null @@ -1,20 +0,0 @@ -#include - -using namespace std; - -int main() -{ - int n, m; cin >> n >> m; //n m - int MIN = min(n, m); - - long long int Z = 0; // - for (int i = 1; i <= MIN; i++) //α߳ - Z += (long long)(m - i + 1) * (long long)(n - i + 1); - - long long int C = 0; //ΣΣ - for (int i = 1; i <= n; i++) // - for (int j = 1; j <= m; j++) // - C += (long long)(n - i + 1) * (long long)(m - j + 1); - cout << Z << " " << C - Z; - return 0; -} diff --git "a/\346\264\233\350\260\267/P2249.cpp" "b/\346\264\233\350\260\267/P2249.cpp" deleted file mode 100644 index fc7d551..0000000 --- "a/\346\264\233\350\260\267/P2249.cpp" +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -using namespace std; -int A[1000010]; - -int main() -{ - int n, m; scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - int x; - while(m--) - { - scanf("%d", &x); - int left = 1, right = n, mid; - while(right >= left) - { - mid = (right + left) >> 1; - if (A[mid] == x) {right = mid; break;} - else if (A[mid] < x) left = mid + 1; - else right = mid - 1; - } - - if (A[right] == x) - { - left = 1; - while(right >= left) - { - mid = (left + right) >> 1; - if (A[mid] == x) right = mid - 1; - else left = mid + 1; - } - - while(A[++right] != x); - printf("%d ", right); - } - else printf("-1 "); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P2261.cpp" "b/\346\264\233\350\260\267/P2261.cpp" deleted file mode 100644 index d0aad22..0000000 --- "a/\346\264\233\350\260\267/P2261.cpp" +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -using namespace std; - -int main() -{ - long long n, k; scanf("%lld%lld", &n, &k); - - long long ans = n * k; - for (long long L = 1, R; L <= n; L = R + 1) - { - if (k / L != 0) R = min(k / (k / L), n); - else R = n; - ans -= (k / L) * (R - L + 1) * (L + R) / 2; - } - printf("%lld", ans); - return 0; -} diff --git "a/\346\264\233\350\260\267/P2401.cpp" "b/\346\264\233\350\260\267/P2401.cpp" deleted file mode 100644 index 7261b36..0000000 --- "a/\346\264\233\350\260\267/P2401.cpp" +++ /dev/null @@ -1,18 +0,0 @@ -#include - -using namespace std; - -int A[1024][1024]; -const int Mod = 2015; -int main() -{ - int n, k; cin >> n >> k; - - A[1][0] = 0; - A[2][0] = A[2][1] = 1; - for (int i = 3; i <= n; i++) - for (int j = 0; j < i; j++) - A[i][j] = (A[i - 1][j] * (j + 1) + A[i - 1][j - 1] * (i - j)) % Mod; - cout << A[n][k]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P2574.cpp" "b/\346\264\233\350\260\267/P2574.cpp" deleted file mode 100644 index b5043c0..0000000 --- "a/\346\264\233\350\260\267/P2574.cpp" +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include - -using namespace std; -const int MAXN = 200000 + 10; -long long ans[MAXN << 2]; -bool tag[MAXN << 2]; -inline int ls(int p){return p << 1;}; -inline int rs(int p){return p << 1 | 1;}; -int A[MAXN]; - -void push_up_sum(int p) -{ - ans[p] = ans[ls(p)] + ans[rs(p)]; -} -void build_tree(int p, int L, int R) -{ - if (L == R) {ans[p] = A[L]; return;}; - - int mid = (L + R) >> 1; - build_tree(ls(p), L, mid); - build_tree(rs(p), mid + 1, R); - push_up_sum(p); -} -inline void f(int p, int L, int R) -{ - ans[p] = R - L + 1 - ans[p]; - tag[p] = !tag[p]; -} -inline void push_down(int p, int L, int R) -{ - if (!tag[p]) return; - - int mid = (L + R) >> 1; - f(ls(p), L, mid); - f(rs(p), mid + 1, R); - tag[p] = false; -} -inline void update(int nL, int nR, int L, int R, int p) -{ - if (nL <= L && R <= nR) - { - ans[p] = R - L + 1 - ans[p]; - tag[p] = !tag[p]; - return; - } - push_down(p, L, R); - - int mid = (L + R) >> 1; - if (nL <= mid) update(nL, nR, L, mid, ls(p)); - if (nR > mid) update(nL, nR, mid + 1, R, rs(p)); - push_up_sum(p); -} -long long query(int nL, int nR, int L, int R, int p) -{ - long long res = 0; - if (nL <= L && R <= nR) return ans[p]; - push_down(p, L, R); - - int mid = (L + R) >> 1; - if (nL <= mid) res += query(nL, nR, L, mid, ls(p)); - if (nR > mid) res += query(nL, nR, mid + 1, R, rs(p)); - return res; -} -int main() -{ - int n, m; scanf("%d%d", &n, &m); - - memset(tag, 0, sizeof(tag)); - memset(ans, 0, sizeof(ans)); - - string str; cin >> str; - for (int i = 1; i <= n; i++) - A[i] = str[i - 1] - '0'; - build_tree(1, 1, n); - - int op, l, r; - while(m--) - { - scanf("%d%d%d", &op, &l, &r); - if (op) - printf("%lld\n", query(l, r, 1, n, 1)); - else if (!op) - update(l, r, 1, n, 1); - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P2671.cpp" "b/\346\264\233\350\260\267/P2671.cpp" deleted file mode 100644 index efac102..0000000 --- "a/\346\264\233\350\260\267/P2671.cpp" +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include - -using namespace std; -const int N = 100000; -const long long Mod = 10007; -struct node -{ - long long int number; - long long int color; - long long int index; -}; -node A[N + 10]; -bool myCompare(node a, node b) -{ - if (a.color == b.color) - return a.index & 1; - return a.color < b.color; -} -int main() -{ - int n, m; scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) - scanf("%lld", &A[i].number); - for (int i = 1; i <= n; i++) - scanf("%lld", &A[i].color); - for (int i = 1; i <= n; i++) - A[i].index = i; - sort(A + 1, A + n + 1, myCompare); - - int Start = 1, Mid = 1, End = 1; - long long int res = 0; - - while(Start <= n) - { - //ΪStartMid - Mid = Start; - while(Mid <= n && A[Mid].color == A[Start].color && (A[Mid].index & 1)) Mid++; - Mid--; - - //żΪMid + 1End - End = Mid + 1; - while(End <= n && A[End].color == A[Start].color && !(A[End].index & 1)) End++; - End--; - - int tmp_sum = 0; - int tmp_num = Mid - Start - 1; - - for (int i = Start; i <= Mid; i++) tmp_sum += A[i].number; - for (int i = Start; i <= Mid; i++) - { - res += A[i].index * (tmp_sum + A[i].number * tmp_num); - res %= Mod; - } - - tmp_sum = 0; - tmp_num = End - (Mid + 1) - 1; - for (int i = Mid + 1; i <= End; i++) tmp_sum += A[i].number; - for (int i = Mid + 1; i <= End; i++) - { - res += A[i].index * (tmp_sum + A[i].number * tmp_num); - res %= Mod; - } - End = Mid = Start = End + 1; - } - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P2676.cpp" "b/\346\264\233\350\260\267/P2676.cpp" deleted file mode 100644 index 16ab52e..0000000 --- "a/\346\264\233\350\260\267/P2676.cpp" +++ /dev/null @@ -1,23 +0,0 @@ -#include - -using namespace std; - -int A[20010]; - -int main() -{ - long long int N, B; cin >> N >> B; - for (int i = 1; i <= N; i++) - cin >> A[i]; - - sort(A + 1, A + N + 1); - - long long int sum = 0; - for (int i = N; i >= 1; i--) - { - if (sum >= B) { cout << N - i; break;} - else sum += (long long int) A[i]; - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P2758.cpp" "b/\346\264\233\350\260\267/P2758.cpp" deleted file mode 100644 index cdba36b..0000000 --- "a/\346\264\233\350\260\267/P2758.cpp" +++ /dev/null @@ -1,31 +0,0 @@ -#include - -using namespace std; -/* -*/ -int dp[2048][2048]; - -int main() -{ - string A, B; cin >> A >> B; - int len_A = A.length(), len_B = B.length(); - A = 'A' + A, B = 'B' + B; - - memset(dp, 0, sizeof(dp)); - for (int i = 0; i <= len_A; i++) dp[i][0] = i; - for (int j = 0; j <= len_B; j++) dp[0][j] = j; - - for (int i = 1; i <= len_A; i++) - for (int j = 1; j <= len_B; j++) - if (A[i] == B[j]) - dp[i][j] = dp[i - 1][j - 1]; - else dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1; - /*for (int i = 1; i <= len_A; i++) - { - for (int j = 1; j <= len_B; j++) - cout << dp[i][j] << " "; - cout << endl; - }*/ - cout << dp[len_A][len_B]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P3156.cpp" "b/\346\264\233\350\260\267/P3156.cpp" deleted file mode 100644 index f0d1fd8..0000000 --- "a/\346\264\233\350\260\267/P3156.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -using namespace std; -int A[2000010]; -int main() -{ - int n, m; scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - while(m--) - { - scanf("%d", &n); - printf("%d\n", A[n]); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P3367.cpp" "b/\346\264\233\350\260\267/P3367.cpp" deleted file mode 100644 index 5887d94..0000000 --- "a/\346\264\233\350\260\267/P3367.cpp" +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include - -using namespace std; -const int N = 10000 + 10; -int n, m; -int Head[N]; - -int Find(int x) -{ - int y = x; - while(Head[y] != y) - y = Head[y]; - - int tmp; - while(Head[x] != x) - { - tmp = Head[x]; - Head[x] = y; - x = tmp; - } - return x; -} -int main() -{ - scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) - Head[i] = i; - int Zi, Xi, Yi; - while(m--) - { - scanf("%d%d%d", &Zi, &Xi, &Yi); - if (Zi == 1) - { - int X_head = Find(Xi); - int Y_head = Find(Yi); - Head[Y_head] = X_head; - } - else if (Zi == 2) - { - if (Find(Xi) == Find(Yi)) - printf("Y\n"); - else printf("N\n"); - } - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P3368.cpp" "b/\346\264\233\350\260\267/P3368.cpp" deleted file mode 100644 index 9886931..0000000 --- "a/\346\264\233\350\260\267/P3368.cpp" +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -using namespace std; -int ans[500010]; -int dx[500010]; // -int res[500010]; -int N, M; - -int lowbit(int x) -{ - return x & -x; -} -void update(int x, int k) -{ - while(x <= N) - { - res[x] += k; - x += lowbit(x); - } - return; -} -void update(int x, int y, int k) -{ - update(x, k); - update(y + 1, -k); -} -long long getnum(int x) -{ - long long tmp_res = 0; - while(x >= 1) - { - tmp_res += res[x]; - x -= lowbit(x); - } - return tmp_res; -} -int main() -{ - scanf("%d%d", &N, &M); - - memset(res, 0, sizeof(res)); - ans[0] = 0; - for (int i = 1; i <= N; i++) - scanf("%d", &ans[i]); - for (int i = 1; i <= N; i++) - { - dx[i] = ans[i] - ans[i - 1]; - update(i, dx[i]); - } - int ch, x, y, k; - while(M--) - { - scanf("%d", &ch); - if (ch == 1) - { - scanf("%d%d%d", &x, &y, &k); - update(x, y, k); - } - else if (ch == 2) - { - scanf("%d", &x); - printf("%lld\n", getnum(x)); - } - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P3372.cpp" "b/\346\264\233\350\260\267/P3372.cpp" deleted file mode 100644 index ea05439..0000000 --- "a/\346\264\233\350\260\267/P3372.cpp" +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include - -using namespace std; - -const int MAXN = 100010; -long long ans[MAXN << 2]; //洢߶ר -long long tag[MAXN << 2]; // -inline int ls(int p){return p << 1;} //2i -inline int rs(int p){return p << 1 | 1;} //Ҷ2i+1 -int A[MAXN]; - -void push_up_sum(int p) -{ - ans[p] = ans[ls(p)] + ans[rs(p)]; -} //ϲά -void push_up_min(int p) -{ - ans[p] = min(ans[ls(p)], ans[ls(p)]); -}//άСֵ -void build_tree(int p, int L, int R) -{ - if (L == R) {ans[p] = A[L]; return;}; - //ͬôȻҶӽ - int mid = (L + R) >> 1; - build_tree(ls(p), L, mid); - build_tree(rs(p), mid + 1, R); - push_up_sum(p); -} // -inline void f(int p, int L, int R, int k) -{ - tag[p] += (long long)k; - ans[p] += (long long)k * (R - L + 1); -} //ͳһı䣬ansҪԪظ -inline void push_down(int p, int L, int R) -{ - int mid = (L + R) >> 1; - f(ls(p), L, mid, tag[p]); - f(rs(p), mid + 1, R, tag[p]); - tag[p] = 0; - //ÿθӽ㣬Դ˲´ -} -inline void update(int nL, int nR, int L, int R, int p, int k) -{ - //nL/nRΪҪ޸ĵ - //l/r/pΪǰڵ洢Լı - if (nL <= L && R <= nR) - { - ans[p] += (long long)k * (R - L + 1); - tag[p] += (long long)k; - return; - } - push_down(p, L, R); - - int mid = (L + R) >> 1; - if (nL <= mid) update(nL, nR, L, mid, ls(p), k); - if (nR > mid) update(nL, nR, mid + 1, R, rs(p), k); - push_up_sum(p); -} -long long query(int nL, int nR, int L, int R, int p) -{ - long long res = 0; - if (nL <= L && R <= nR) return ans[p]; - int mid = (L + R) >> 1; - push_down(p, L, R); - if (nL <= mid) res += query(nL, nR, L, mid, ls(p)); - if (nR > mid) res += query(nL, nR, mid + 1, R, rs(p)); - return res; -} - -int main() -{ - int n, m; scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - build_tree(1, 1, n); - - int ch, x, y, k; - while(m--) - { - scanf("%d", &ch); - if (ch == 1) - { - scanf("%d%d%d", &x, &y, &k); - update(x, y, 1, n, 1, k); - } - else if (ch == 2) - { - scanf("%d%d", &x, &y); - printf("%lld\n", query(x, y, 1, n, 1)); - } - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P3374.cpp" "b/\346\264\233\350\260\267/P3374.cpp" deleted file mode 100644 index 4db91d8..0000000 --- "a/\346\264\233\350\260\267/P3374.cpp" +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include - -using namespace std; -int ans[500010]; -long long res[500010]; -int n, m; - -int lowbit(int x) -{ - return x & -x; -} -void update(int x, int k) -{ - while(x <= n) - { - res[x] += k; - x += lowbit(x); - } -} -long long getsum(int x) -{ - long long tmp_res = 0; - while(x > 0) - { - tmp_res += res[x]; - x -= lowbit(x); - } - return tmp_res; -} - -int main() -{ - scanf("%d%d", &n, &m); - memset(ans, 0, sizeof(ans)); - memset(res, 0, sizeof(res)); - for (int i = 1; i <= n; i++) - { - scanf("%d", &ans[i]); - update(i, ans[i]); - } - int ch, x, y, k; - while(m--) - { - scanf("%d", &ch); - if (ch == 1) - { - scanf("%d%d", &x, &k); - update(x, k); - } - else if (ch == 2) - { - scanf("%d%d", &x, &y); - printf("%lld\n", getsum(y) - getsum(x - 1)); - } - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P3378.cpp" "b/\346\264\233\350\260\267/P3378.cpp" deleted file mode 100644 index 564c327..0000000 --- "a/\346\264\233\350\260\267/P3378.cpp" +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include - -using namespace std; -const int N = 1000000 + 10; -int ans[N]; -int ans_index = 0; -void put_in(int x) -{ - ans[++ans_index] = x; //β - - int cur = ans_index; - int tmp = 0; - while(cur > 1 && ans[cur >> 1] > x) //ڵ - { - //ڵӽڵн - tmp = ans[cur]; - ans[cur] = ans[cur >> 1]; - ans[cur >> 1] = tmp; - cur = cur >> 1; - } - return; -} -void put_out() -{ - ans[1] = ans[ans_index--]; //һڵͷ - - int cur = 1; - - int next, tmp; - while(cur <= ans_index) - { - if ((cur << 1) <= ans_index && (cur << 1 | 1) <= ans_index) //ӽڵ㶼 - { - next = ans[cur << 1] < ans[cur << 1 | 1] ? cur << 1 : (cur << 1 | 1); - if (ans[cur] > ans[next]) - { - tmp = ans[cur]; - ans[cur] = ans[next]; - ans[next] = tmp; - }else break; - } - else if ((cur << 1) <= ans_index) - { - next = cur << 1; - if (ans[cur] > ans[next]) - { - tmp = ans[cur]; - ans[cur] = ans[next]; - ans[next] = tmp; - }else break; - } - else - break; - - cur = next; - } - return; -} -int main() -{ - int n; scanf("%d", &n); - - int op, x; - while(n--) - { - scanf("%d", &op); - if (op == 1) - { - scanf("%d", &x); - put_in(x); - } - else if (op == 2) - printf("%d\n", ans[1]); - else if (op == 3) - put_out(); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P3383.cpp" "b/\346\264\233\350\260\267/P3383.cpp" deleted file mode 100644 index bd972c8..0000000 --- "a/\346\264\233\350\260\267/P3383.cpp" +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -using namespace std; -int Prime[100000010]; -bool Check[100000010]; -int n; -void getPrime() -{ - memset(Check, 0, sizeof(Check)); - int tot = 0; - for (int i = 2; i <= n; i++) - { - if (!Check[i]) - Prime[++tot] = i; - for (int j = 1; j <= tot; j++) - { - if (i * Prime[j] > n) - break; - Check[i * Prime[j]] = true; - if (i % Prime[j] == 0) - break; - } - } -} -int main() -{ - scanf("%d", &n); - int k; scanf("%d", &k); - getPrime(); - - while(k--) - { - scanf("%d", &n); - printf("%d\n", Prime[n]); - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P3390.cpp" "b/\346\264\233\350\260\267/P3390.cpp" deleted file mode 100644 index e4cffc3..0000000 --- "a/\346\264\233\350\260\267/P3390.cpp" +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -using namespace std; -const long long Mod = 1000000000 + 7; -long long A[128][128]; -long long res[128][128]; -long long tmp[128][128]; -long long n, k; - -void matrix_mul(long long A[][128], long long B[][128]) -{ - memset(tmp, 0, sizeof(tmp)); - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - for (int k = 1; k <= n; k++) - tmp[i][j] = (tmp[i][j] + A[i][k] * B[k][j]) % Mod; - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - A[i][j] = tmp[i][j]; - return; -} -void fastPower(long long k) -{ - while(k > 0) - { - if (k & 1) - matrix_mul(res, A); - matrix_mul(A, A); - k = k >> 1; - } - return; -} -void print() -{ - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - printf("%lld ", res[i][j]); - printf("\n"); - } -} -int main() -{ - scanf("%lld%lld", &n, &k); - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - scanf("%lld", &A[i][j]); - for (int i = 1; i <= n; i++) - res[i][i] = 1; - - fastPower(k); - print(); - return 0; -} diff --git "a/\346\264\233\350\260\267/P3392.cpp" "b/\346\264\233\350\260\267/P3392.cpp" deleted file mode 100644 index c4e1d1a..0000000 --- "a/\346\264\233\350\260\267/P3392.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; - -int A[52][52]; - -int main() -{ - int N, M; cin >> N >> M; - - memset(A, 0, sizeof(A)); - char ch; - for (int i = 1; i <= N; i++) - for (int j = 1; j <= M; j++) - { - cin >> ch; - if (ch == 'W') A[i][j] = 0; //ɫ - if (ch == 'B') A[i][j] = 1; //ɫ - if (ch == 'R') A[i][j] = 2; //ɫ - } - - int sum = 0, k = N, res = 1e9; - - for (int i = 1; i <= N - 2; i++) - for (int j = i + 1; j <= N - 1; j++) - { - sum = 0; - for (int s = 1; s <= i; s++) - for (int t = 1; t <= M; t++) - if (A[s][t] != 0) sum++; - for (int s = i + 1; s <= j; s++) - for (int t = 1; t <= M; t++) - if (A[s][t] != 1) sum++; - for (int s = j + 1; s <= k; s++) - for (int t = 1; t <= M; t++) - if (A[s][t] != 2) sum++; - if (sum <= res) res = sum; - } - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P3397.cpp" "b/\346\264\233\350\260\267/P3397.cpp" deleted file mode 100644 index a4e678b..0000000 --- "a/\346\264\233\350\260\267/P3397.cpp" +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -using namespace std; - -int A[1024][1024]; -int main() -{ - memset(A, 0, sizeof(A)); - - int n, m; scanf("%d%d", &n, &m); - - int x1, y1, x2, y2; - for (int i = 1; i <= m; i++) - { - scanf("%d%d%d%d", &x1, &y1, &x2, &y2); - for (int j = x1; j <= x2; j++) - { - A[j][y1] += 1; - A[j][y2 + 1] += -1; - } - } - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - { - A[i][j] += A[i][j - 1]; - printf("%d ", A[i][j]); - } - printf("\n"); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P3406.cpp" "b/\346\264\233\350\260\267/P3406.cpp" deleted file mode 100644 index a2558d8..0000000 --- "a/\346\264\233\350\260\267/P3406.cpp" +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -using namespace std; - - -struct node -{ - long long Ai; - long long Bi; - long long Ci; -}; -node Railway[100010]; -long long int Road[100010]; -long long dp[100010]; - -int main() -{ - int N, M; scanf("%d%d", &N, &M); - for (int i = 1; i <= M; i++) - scanf("%lld", &Road[i]); - for (int i = 1; i <= N - 1; i++) - scanf("%lld%lld%lld", &Railway[i].Ai, &Railway[i].Bi, &Railway[i].Ci); - - memset(dp, 0, sizeof(dp)); - int Start, End; - for (int i = 1; i < M; i++) - { - Start = min(Road[i], Road[i + 1]); - End = max(Road[i], Road[i + 1]); - dp[Start]++; - dp[End]--; - } - for (int i = 1; i < N; i++) - dp[i] += dp[i - 1]; - - long long res = 0; - for (int i = 1; i < N; i++) - res += min(dp[i] * Railway[i].Ai, dp[i] * Railway[i].Bi + Railway[i].Ci); - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P3601.cpp" "b/\346\264\233\350\260\267/P3601.cpp" deleted file mode 100644 index 54e3016..0000000 --- "a/\346\264\233\350\260\267/P3601.cpp" +++ /dev/null @@ -1,60 +0,0 @@ -#include - -using namespace std; -const int N = 1000000 + 10; -long long Prime[N]; -bool Check[N]; -bool isPrime[N]; -long long tot = 0; -long long L, R; -long long res = 0; -const int Mod = 666623333; - -void getPrime() -{ - for (long long i = 2; i < N; i++) - { - if (!Check[i]) - Prime[++tot] = i; - for (long long j = 1; j <= tot; j++) - { - if (i * Prime[j] > N) - break; - Check[i * Prime[j]] = true; - if (i % Prime[j] == 0) - break; - } - } -} -void getPhi() -{ - for (int i = 1; i <= tot; i++) - { - long long start; - if (L / Prime[i] <= 1) - start = 2 * Prime[i]; - else - { - start = L / Prime[i]; - while(start < L) start += Prime[i]; - } - long long End; - if (R / Prime[i] <= 1) - End = 2 * Prime[i]; - else - { - End = R / Prime[i]; - while(End < R) End += Prime[i]; - } - res += (End - start) / Prime[i]; - res %= Mod; - } -} -int main() -{ - cin >> L >> R; - getPrime(); - getPhi(); - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P3612.cpp" "b/\346\264\233\350\260\267/P3612.cpp" deleted file mode 100644 index f1883c8..0000000 --- "a/\346\264\233\350\260\267/P3612.cpp" +++ /dev/null @@ -1,30 +0,0 @@ -#include - -using namespace std; - -long long int C[64]; - -int main() -{ - string s; cin >> s; - int len = s.length(); - long long int N; cin >> N; - - C[0] = len; - for (int i = 1; i < 63; i++) - C[i] = 2 * C[i - 1]; - - while(N > len) - { - int i = 0; - for (; i < 63; i++) - if (C[i] < N && N <= C[i + 1]) - break; - if (N == C[i] + 1) N--; - else - N -= C[i] + 1; - }; - cout << s[N - 1]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P3654.cpp" "b/\346\264\233\350\260\267/P3654.cpp" deleted file mode 100644 index ad65267..0000000 --- "a/\346\264\233\350\260\267/P3654.cpp" +++ /dev/null @@ -1,53 +0,0 @@ -#include - -using namespace std; - -char A[110][110]; -char B[110][110]; - -int main() -{ - int R, C, K; cin >> R >> C >> K; - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - { cin >> A[i][j]; B[i][j] = A[i][j];}; - - for (int i = 1; i <= R; i++) - A[i][C + 1] = B[i][C + 1] = '#'; - for (int j = 1; j <= C; j++) - A[R + 1][j] = B[R + 1][j] = '#'; - - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C + 1; j++) - if (A[i][j] == '#') - for (int k = j - 1; k > max(j - K, 0); k--) - A[i][k] = '#'; - - for (int j = 1; j <= C; j++) - for (int i = 1; i <= R + 1; i++) - if (B[i][j] == '#') - for (int k = i - 1; k > max(i - K, 0); k--) - B[k][j] = '#'; - - int sum = 0; - - if (K == 1) - { - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - if (A[i][j] == '.') sum++; - cout << sum; - return 0; - } - - for (int i = 1; i <= R; i++) - for (int j = 1; j <= C; j++) - { - if (A[i][j] == '.') sum++; - if (B[i][j] == '.') sum++; - } - cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P3799.cpp" "b/\346\264\233\350\260\267/P3799.cpp" deleted file mode 100644 index a2d1a78..0000000 --- "a/\346\264\233\350\260\267/P3799.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include - -using namespace std; - -int A[5010]; -long long int Mod = 1000000000 + 7; - -int main() -{ - int n; cin >> n; - - memset(A, 0, sizeof(A)); - int tmp; - while(n--) - { - cin >> tmp; - A[tmp]++; - } - - long long int sum = 0; - for (int i = 1; i <= 5000; i++) - if (A[i] >= 2) - { - for (int j = 1; j <= (i - 1) / 2; j++) - { - sum += (long long)A[i] * (long long)(A[i] - 1) / 2 * (long long)A[j] * (long long)A[i - j]; //iѡ21 - sum %= Mod; - } - if (i % 2 == 0) - { - sum += (long long)A[i] * (long long)(A[i] - 1) / 2 * (long long)A[i / 2] * (long long)(A[i / 2] - 1) / 2; // iѡ2i/2ѡ2 - sum %= Mod; - } - if (A[i] >= 3 && A[0] >= 1) //iѡ30ѡ1 - sum += (long long)A[0] * (long long)A[i] * (long long)(A[i] - 1) * (long long)(A[i] - 2) / 6; - sum %= Mod; - } - - cout << sum; - return 0; -} diff --git "a/\346\264\233\350\260\267/P3817.cpp" "b/\346\264\233\350\260\267/P3817.cpp" deleted file mode 100644 index 3221edf..0000000 --- "a/\346\264\233\350\260\267/P3817.cpp" +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -using namespace std; - -int A[100010]; - -int main() -{ - int n, x; scanf("%d%d", &n, &x); - for (int i = 0; i < n; i++) scanf("%d", &A[i]); - - long long int sum = 0; - if (A[0] > x) { sum = A[0] - x; A[0] = x;}; - - for (int i = 1; i < n; i++) - if (A[i] + A[i - 1] > x) - { - sum += (long long)A[i] + (long long)A[i - 1] - (long long)x; - A[i] = x - A[i - 1]; - } - cout << sum; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P3842.cpp" "b/\346\264\233\350\260\267/P3842.cpp" deleted file mode 100644 index 911c587..0000000 --- "a/\346\264\233\350\260\267/P3842.cpp" +++ /dev/null @@ -1,30 +0,0 @@ -#include - -using namespace std; - -struct node -{ - int L; - int R; -}; -node A[20010]; -int B[20010][2]; //[0]߶߿ʼߣ[1]෴ - -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - cin >> A[i].L >> A[i].R; - A[0].L = A[0].R = 1; - - - memset(B, 0, sizeof(B)); - for (int i = 1; i <= n; i++) - { - B[i][0] = A[i].R - A[i].L + min(B[i - 1][0] + abs(A[i - 1].R - A[i].L), B[i - 1][1] + abs(A[i - 1].L - A[i].L)); - B[i][1] = A[i].R - A[i].L + min(B[i - 1][0] + abs(A[i - 1].R - A[i].R), B[i - 1][1] + abs(A[i - 1].L - A[i].R)); - } - - cout << min(B[n][0] + n - A[n].R, B[n][1] + n - A[n].L) + n - 1; - return 0; -} diff --git "a/\346\264\233\350\260\267/P3847.cpp" "b/\346\264\233\350\260\267/P3847.cpp" deleted file mode 100644 index b592bbb..0000000 --- "a/\346\264\233\350\260\267/P3847.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -using namespace std; -int A[3010]; -int dp[3010][3010]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) scanf("%d", &A[i]); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - if (i == j) dp[i][j] = 0; - else if (j - i == 1) - { - if (A[j] == A[i]) dp[i][j] = 0; - else dp[i][j] = 1; - } - else dp[i][j] = 0x7fffffff; - - int r; - for (int step = 2; step < n; step++) - for (int l = 1; r = l + step, r <= n; l++) - { - if (A[l] == A[r]) dp[l][r] = min(dp[l][r], dp[l + 1][r - 1]); - else dp[l][r] = min(dp[l][r], dp[l + 1][r - 1] + 1); - - dp[l][r] = min(dp[l][r], dp[l + 1][r] + 1); - dp[l][r] = min(dp[l][r], dp[l][r - 1] + 1); - } - printf("%d", dp[1][n]); - return 0; -} diff --git "a/\346\264\233\350\260\267/P3865.cpp" "b/\346\264\233\350\260\267/P3865.cpp" deleted file mode 100644 index 6212b7a..0000000 --- "a/\346\264\233\350\260\267/P3865.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -using namespace std; -int dp[100010][18]; -int ciFang[18]; -inline int read() -{ - int x=0,f=1;char ch=getchar(); - while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();} - while (isdigit(ch)){x=x*10+ch-48;ch=getchar();} - return x*f; -} -int main() -{ - ciFang[0] = 1; - for (int i = 1; i < 18; i++) - ciFang[i] = 2 * ciFang[i - 1]; - - int N, M; scanf("%d%d", &N, &M); - for (int i = 1; i <= N; i++) - dp[i][0] = read(); - for (int j = 1; j <= 18; j++) - for (int i = 1; i <= N - ciFang[j - 1] + 1; i++) - dp[i][j] = max(dp[i][j - 1], dp[i + ciFang[j - 1]][j - 1]); - - int L, R, p; - while(M--) - { - L = read(); R = read(); - p = (int)(log(R - L + 1) / log(2)); - printf("%d\n", max(dp[L][p], dp[R - ciFang[p] + 1][p])); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P4017.cpp" "b/\346\264\233\350\260\267/P4017.cpp" deleted file mode 100644 index 9bb264c..0000000 --- "a/\346\264\233\350\260\267/P4017.cpp" +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -using namespace std; - -int A[5010][5010]; //0޹ϵ1ijԣ2ij - -int eat[5010]; -int beEaten[5010]; -long long int dp[5010]; -bool T[5010]; -const long long Mod = 80112002; - -int main() -{ - int n, m; scanf("%d%d", &n, &m); - - memset(A, 0, sizeof(A)); - memset(T, 0, sizeof(T)); - memset(dp, 0, sizeof(dp)); - memset(eat, 0, sizeof(eat)); - memset(beEaten, 0, sizeof(beEaten)); - - int x, y; - while(m--) - { - scanf("%d%d", &x, &y); - A[x][y] = 1; beEaten[x]++; - A[y][x] = 2; eat[y]++; - } - - for (int i = 1; i <= n; i++) - if (!eat[i]) dp[i] = 1; - - int S[5000], s_xb = 0; - for (int i = 1; i <= n; i++) - if (!beEaten[i]) S[++s_xb] = i; - - int ans = n; - while(ans > 0) - { - bool flag = false; - for (int i = 1; i <= n; i++) - if (!T[i] && !eat[i]) - { - flag = true; - for (int j = 1; j <= n; j++) - if (A[i][j] == 1) - { - dp[j] += dp[i]; dp[j] %= Mod; - A[i][j] = A[j][i] = 0; - beEaten[i]--; - eat[j]--; - } - T[i] = true; - ans--; - } - if (!flag) break; - } - - long long int res = 0; - for (int i = 1; i <= s_xb; i++) - { - res += dp[S[i]]; - res %= Mod; - } - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P4170.cpp" "b/\346\264\233\350\260\267/P4170.cpp" deleted file mode 100644 index 8f9d753..0000000 --- "a/\346\264\233\350\260\267/P4170.cpp" +++ /dev/null @@ -1,28 +0,0 @@ -#include - -using namespace std; -int dp[52][52]; - -int main() -{ - string A; cin >> A; - int len = A.length(); - A = ' ' + A; - - memset(dp, 0x7f, sizeof(dp)); - - for (int k = 0; k < len; k++) - { - int l = 1, r; - for (; r = l + k, r <= len; l++) - { - for (int j = l; j <= r; j++) - if (l == r) - dp[l][l] = 1; - else if (A[l] == A[r]) dp[l][r] = min(dp[l + 1][r], dp[l][r - 1]); - else dp[l][r] = min(dp[l][r], dp[l][j] + dp[j + 1][r]); - } - } - cout << dp[1][len]; - return 0; -} diff --git "a/\346\264\233\350\260\267/P4387.cpp" "b/\346\264\233\350\260\267/P4387.cpp" deleted file mode 100644 index fa7eba2..0000000 --- "a/\346\264\233\350\260\267/P4387.cpp" +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include - -using namespace std; - -int in[100010]; -int out[100010]; - -int main() -{ - int t; scanf("%d", &t); - while(t--) - { - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &in[i]); - for (int i = 1; i <= n; i++) - scanf("%d", &out[i]); - - stack s; - int xb = 1; - for (int i = 1; i <= n; i++) - { - s.push(in[i]); - while(!s.empty() && s.top() == out[xb]) - { - s.pop(); - xb++; - } - } - - if (s.empty()) printf("Yes\n"); - else printf("No\n"); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P4447.cpp" "b/\346\264\233\350\260\267/P4447.cpp" deleted file mode 100644 index 03d6b5f..0000000 --- "a/\346\264\233\350\260\267/P4447.cpp" +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -using namespace std; - -int A[100010]; - -int main() -{ - int N; scanf("%d", &N); - for (int i = 1; i <= N; i++) - scanf("%d", &A[i]); - sort(A + 1, A + N + 1); - - int q_index = 0; - queue q[1000]; - - int tmp_index, tmp_min; - q[++q_index].push(A[1]); - - for (int i = 2; i <= N; i++) - { - tmp_index = 0; - tmp_min = 1000000; //޴ - for (int j = 1; j <= q_index; j++) - if (q[j].back() == A[i] - 1 && q[j].size() < tmp_min) - { - tmp_min = q[j].size(); - tmp_index = j; - } - if (tmp_index) - q[tmp_index].push(A[i]); - else q[++q_index].push(A[i]); - } - - int res = 1000000; - for (int i = 1; i <= q_index; i++) - if (q[i].size() < res) res = q[i].size(); - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P4549.cpp" "b/\346\264\233\350\260\267/P4549.cpp" deleted file mode 100644 index e20f37a..0000000 --- "a/\346\264\233\350\260\267/P4549.cpp" +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -using namespace std; -int A[21]; -int gcd(int a, int b) -{ - int tmp; - while(b) - { - tmp = a % b; - a = b; - b = tmp; - } - return a; -} -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - { - scanf("%d", &A[i]); - A[i] = abs(A[i]); - } - int res = gcd(A[1], A[2]); - for (int i = 3; i <= n; i++) - res = gcd(res, A[i]); - printf("%d", res); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P4924.cpp" "b/\346\264\233\350\260\267/P4924.cpp" deleted file mode 100644 index dd79147..0000000 --- "a/\346\264\233\350\260\267/P4924.cpp" +++ /dev/null @@ -1,55 +0,0 @@ -#include -using namespace std; - -int A[510][510]; - -int main() -{ - int n, m; cin >> n >> m; - memset(A, 0, sizeof(A)); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n; j++) - A[i][j] = (i - 1) * n + j; - - int x, y, r, z; - int LU_x, LU_y, RU_x, RU_y, RD_x, RD_y, LD_x, LD_y; - int tmp; - for (int i = 1; i <= m; i++) - { - cin >> x >> y >> r >> z; - for (int j = 1; j <= r; j++) - for (int k = 0; k < 2 * j; k++) - { - LU_x = x - j; LU_y = y - j; - RU_x = x - j; RU_y = y + j; - RD_x = x + j; RD_y = y + j; - LD_x = x + j; LD_y = y - j; - if (z) - { - tmp = A[LU_x + k][LU_y]; - A[LU_x + k][LU_y] = A[RU_x][RU_y - k]; - A[RU_x][RU_y - k] = A[RD_x - k][RD_y]; - A[RD_x - k][RD_y] = A[LD_x][LD_y + k]; - A[LD_x][LD_y + k] = tmp; - } - else - { - tmp = A[LU_x][LU_y + k]; - A[LU_x][LU_y + k] = A[LD_x - k][LD_y]; - A[LD_x - k][LD_y] = A[RD_x][RD_y - k]; - A[RD_x][RD_y - k] = A[RU_x + k][RU_y]; - A[RU_x + k][RU_y] = tmp; - } - } - } - - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - cout << A[i][j] << " "; - cout << endl; - }; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P4933.cpp" "b/\346\264\233\350\260\267/P4933.cpp" deleted file mode 100644 index 1cbd4a7..0000000 --- "a/\346\264\233\350\260\267/P4933.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -using namespace std; - -int A[1010]; -int dp[1010][40010]; //iβΪj - -const long long int Mod = 998244353; - -int main() -{ - long long int n; scanf("%lld", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - memset(dp, 0, sizeof(dp)); - - long long int sum = 0; - - for (int i = 1; i <= n; i++) - for (int j = 0; j <= 40000; j++) - { - for (int k = i - 1; k >= 1; k--) - if (0 <= j && j <= 20000 && A[i] - A[k] == j) - dp[i][j] += dp[k][j] + 1; - else if (j > 20000 && A[i] - A[k] == 20000 - j) - dp[i][j] += dp[k][j] + 1; - - sum += (long long)dp[i][j]; - sum %= Mod; - } - cout << (sum + (long long)n) % Mod; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P4994.cpp" "b/\346\264\233\350\260\267/P4994.cpp" deleted file mode 100644 index 3f16fab..0000000 --- "a/\346\264\233\350\260\267/P4994.cpp" +++ /dev/null @@ -1,22 +0,0 @@ -#include - -using namespace std; - -int A[10000000]; - -int main() -{ - int M; cin >> M; - - if (M == 1) { cout << 0; return 0;} - - A[0] = 0; - A[1] = 1; - for (int i = 2; ; i++) - { - A[i] = (A[i - 1] + A[i - 2]) % M; - if (A[i] == 1 && A[i - 1] == 0) - { cout << i - 1; return 0;} - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P4995.cpp" "b/\346\264\233\350\260\267/P4995.cpp" deleted file mode 100644 index 8688990..0000000 --- "a/\346\264\233\350\260\267/P4995.cpp" +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -using namespace std; - -int A[400]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - A[0] = 0; - int l = 0, r = n; - - sort(A, A + n + 1); - long long int sum = 0; - int dir = 1; - while(l != r) - { - sum += (long long)(A[r] - A[l]) * (long long)(A[r] - A[l]); - if (dir == 1) { l++; dir = -1;} - else { r--; dir = 1;} - } - printf("%lld", sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P5019.cpp" "b/\346\264\233\350\260\267/P5019.cpp" deleted file mode 100644 index f4ee37e..0000000 --- "a/\346\264\233\350\260\267/P5019.cpp" +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -using namespace std; - -int A[100010]; - -int main() -{ - int n; scanf("%d", &n); - - A[0] = 0; - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - int sum = 0; - for (int i = 1; i <= n; i++) - if (A[i] > A[i - 1]) - sum += A[i] - A[i - 1]; - printf("%d", sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P5020.cpp" "b/\346\264\233\350\260\267/P5020.cpp" deleted file mode 100644 index f8b7aa5..0000000 --- "a/\346\264\233\350\260\267/P5020.cpp" +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -using namespace std; - -int A[120]; -int dp[25010]; - -int main() -{ - int T; scanf("%d", &T); - while(T--) - { - int n; scanf("%d", &n); - - memset(A, 0, sizeof(A)); - memset(dp, 0, sizeof(dp)); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - sort(A + 1, A + n + 1); - - int sum = 0; - dp[0] = 1; - for (int i = 1; i <= n; i++) - { - if (dp[A[i]] == 0) - sum++; - for (int j = A[i]; j <= A[n]; j++) - dp[j] += dp[j - A[i]]; - } - printf("%d\n", sum); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P5143.cpp" "b/\346\264\233\350\260\267/P5143.cpp" deleted file mode 100644 index f957402..0000000 --- "a/\346\264\233\350\260\267/P5143.cpp" +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -using namespace std; - -struct node -{ - int x, y, z; -}; -node A[50010]; - -bool myCompare(node a, node b){return a.z < b.z;}; - -int main() -{ - int n; cin >> n; - for (int i = 0; i < n; i++) - cin >> A[i].x >> A[i].y >> A[i].z; - sort(A, A + n, myCompare); - - double sum = 0; - - for (int i = 1; i < n; i++) - sum += sqrt((A[i].x - A[i - 1].x) * (A[i].x - A[i - 1].x) + (A[i].y - A[i - 1].y) * (A[i].y - A[i - 1].y) + (A[i].z - A[i - 1].z) * (A[i].z - A[i - 1].z)); - printf("%.3f", sum); - return 0; -} diff --git "a/\346\264\233\350\260\267/P5461.cpp" "b/\346\264\233\350\260\267/P5461.cpp" deleted file mode 100644 index bb57ea9..0000000 --- "a/\346\264\233\350\260\267/P5461.cpp" +++ /dev/null @@ -1,35 +0,0 @@ -#include - -using namespace std; - -bool A[1025][1025]; - -void Dfs(int x, int y, int len) -{ - if (len == 0) return; - - for (int i = x; i < x + len / 2; i++) - for (int j = y; j < y + len / 2; j++) - A[i][j] = 0; - Dfs(x + len / 2, y + len / 2, len / 2); - Dfs(x + len / 2, y, len / 2); - Dfs(x, y + len / 2, len / 2); -} - -int main() -{ - int n; cin >> n; - n = pow(2.0, n); - - memset(A, 1, sizeof(A)); - - Dfs(1, 1, n); - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= n; j++) - cout << A[i][j] << " "; - cout << endl; - } - - return 0; -} diff --git "a/\346\264\233\350\260\267/P5462.cpp" "b/\346\264\233\350\260\267/P5462.cpp" deleted file mode 100644 index 3a86be8..0000000 --- "a/\346\264\233\350\260\267/P5462.cpp" +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -using namespace std; - -struct node -{ - int left; - int right; -}; -node A[1000010]; -int A_xb = 0; -bool myCompare(node a, node b) -{ - return a.left > b.left; -} -int main() -{ - int n; scanf("%d", &n); - stack s; - - int tmp; - - for (int i = 1; i <= n; i++) - { - scanf("%d", &tmp); - if (s.empty() || tmp > s.top()) - s.push(tmp); - else - { - A[++A_xb].left = s.top(); - s.pop(); - A[A_xb].right = tmp; - } - } - - while(!s.empty()) - { - A[++A_xb].right = s.top(); - s.pop(); - A[A_xb].left = s.top(); - s.pop(); - } - - sort(A + 1, A + A_xb + 1, myCompare); - - for (int i = 1; i <= A_xb; i++) - printf("%d %d ", A[i].left, A[i].right); - - return 0; -} diff --git "a/\346\264\233\350\260\267/P5638.cpp" "b/\346\264\233\350\260\267/P5638.cpp" deleted file mode 100644 index 3b7d841..0000000 --- "a/\346\264\233\350\260\267/P5638.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -using namespace std; - -long long A[1000010]; - -int main() -{ - int n, k; scanf("%d%d", &n, &k); - long long tot = 0; - for (int i = 1; i < n; i++) - { - scanf("%lld", &A[i]); - tot += A[i]; - } - if (k == 0) - printf("%lld", tot); - else if (k >= n - 1) - printf(0); - else - { - long long int res = 0; - long long int tmp = 0; - for (int i = 1; i <= k; i++) - tmp += A[i]; - res = max(res, tmp); - for (int i = k + 1; i <= n; i++) - { - tmp += A[i] - A[i - k]; - res = max(res, tmp); - } - printf("%lld", tot - res); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/P5788.cpp" "b/\346\264\233\350\260\267/P5788.cpp" deleted file mode 100644 index 9db83de..0000000 --- "a/\346\264\233\350\260\267/P5788.cpp" +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -using namespace std; -struct node -{ - int num; - int index; -}; -node ans[3000010]; -int ans_index = 0; -int A[3000010]; -int res[3000010]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - - ans[ans_index].index = 0; - ans[ans_index].num = 0x7fffffff; - for (int i = n; i >= 1; i--) - { - while(ans_index && A[i] >= ans[ans_index].num) ans_index--; - res[i] = ans[ans_index].index; - - ans[++ans_index].num = A[i]; - ans[ans_index].index = i; - } - for (int i = 1; i <= n; i++) - printf("%d ", res[i]); - return 0; -} diff --git "a/\346\264\233\350\260\267/P6363.cpp" "b/\346\264\233\350\260\267/P6363.cpp" deleted file mode 100644 index fb51885..0000000 --- "a/\346\264\233\350\260\267/P6363.cpp" +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include - -using namespace std; - -double Team[30][30]; -struct node -{ - double score; - char ch; -}; -node A[1024]; - -bool myCompare(node a, node b) -{ - if (a.score == b.score) return a.ch < b.ch; - return a.score > b.score; -} - -int main() -{ - int n, k; cin >> n >> k; - - //ѡֵĵ÷ֺͶ飬¼ - for (int i = 1; i <= n; i++) - cin >> A[i].score >> A[i].ch; - //iӶjӵĴ - - memset(Team, 0, sizeof(Team)); - for (int i = 1; i <= k; i++) - for (int j = 1; j <= k; j++) - cin >> Team[i][j]; - - for (int j = 1; j <= k; j++) - { - for (int i = 1; i <= k; i++) - Team[0][j] += Team[i][j]; - Team[0][j] /= k; - //ɸѡ - int tmp = 0; //¼ɸѡĶ - for (int i = 1; i <= k; i++) - if (abs(Team[i][j] - Team[0][j]) > 15) - { Team[i][j] = 0; tmp++;} - //¼ƽֵ - Team[0][j] = 0.0; - for (int i = 1; i <= k; i++) - Team[0][j] += Team[i][j]; - Team[0][j] = round(Team[0][j] / (k - tmp)); - //ȡ - - } - - //ÿλѡյ÷ - for (int i = 1; i <= n; i++) - A[i].score = round(A[i].score * 0.6 + Team[0][A[i].ch - 'A' + 1] * 0.4); - - // - sort(A + 1, A + n + 1, myCompare); - - // - for (int i = 1; i <= n; i++) - cout << A[i].score << " " << A[i].ch << endl; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P6364.cpp" "b/\346\264\233\350\260\267/P6364.cpp" deleted file mode 100644 index c47f5da..0000000 --- "a/\346\264\233\350\260\267/P6364.cpp" +++ /dev/null @@ -1,34 +0,0 @@ -#include - -using namespace std; - -int A[1000010]; -int O[1000010]; - -int main() -{ - int n; cin >> n; - for (int i = 1; i <= n; i++) - cin >> A[i]; - //˳ʼΪ1 - for (int i = 1; i <= n; i++) - O[i] = 1; - //򲻼 - for (int i = 2; i <= n; i++) - { - if (A[i] > A[i - 1]) O[i] = O[i - 1] + 1; - else if (A[i] == A[i - 1]) O[i] = O[i - 1]; - } - //򲻼 - for (int i = n - 1; i >= 1; i--) - { - if (A[i] > A[i + 1]) O[i] = max(O[i], O[i + 1] + 1); - else if (A[i] == A[i + 1]) O[i] = O[i + 1]; - } - - long long res = 0; - for (int i = 1; i <= n; i++) - res += O[i]; - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/P6365.cpp" "b/\346\264\233\350\260\267/P6365.cpp" deleted file mode 100644 index 6c5c901..0000000 --- "a/\346\264\233\350\260\267/P6365.cpp" +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -using namespace std; -long long int A[2000010]; - -int main() -{ - long long int n; scanf("%lld", &n); - - long long int a, b, A_xb = 0; - while(n--) - { - scanf("%lld%lld", &a, &b); - b = a ^ b; - A[++A_xb] = a; - if (b != a) A[++A_xb] = b; - } - - sort(A + 1, A + A_xb + 1); - - long long int M = 1, tmp = 1, num = A[A_xb]; - - for (int i = A_xb - 1; i >= 1; i--) - { - if (A[i] == A[i + 1]) - tmp++; //ʱ - else if (tmp >= M) - { - M = tmp; //ִ - tmp = 1; // - num = A[i + 1]; - } - else tmp = 1; - } - - printf("%lld", num); - return 0; -} diff --git "a/\346\264\233\350\260\267/P6366.cpp" "b/\346\264\233\350\260\267/P6366.cpp" deleted file mode 100644 index c8856ab..0000000 --- "a/\346\264\233\350\260\267/P6366.cpp" +++ /dev/null @@ -1,115 +0,0 @@ -#include - -using namespace std; - -int A[10000000]; -int A_xb = 0; - -int B[10000000]; - -void f (string s, int x) -{ - //16Ƶ - char ch = s[x]; - if (ch == 'A') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == 'B') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == 'C') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == 'D') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1;} - else if (ch == 'E') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == 'F') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == '0') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == '1') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1;} - else if (ch == '2') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == '3') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == '4') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == '5') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1;} - else if (ch == '6') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == '7') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == '8') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == '9') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1;} - return; -} - -int main() -{ - string s; cin >> s; - int len = s.length(); - - for (int i = 0; i < len; i++) - { - char ch = s[i]; - if (ch == 'A') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == 'B') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == 'C') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == 'D') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1;} - else if (ch == 'E') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == 'F') - { A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == '0') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == '1') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1;} - else if (ch == '2') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == '3') - { A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == '4') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == '5') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 1;} - else if (ch == '6') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 0;} - else if (ch == '7') - { A[++A_xb] = 0; A[++A_xb] = 1; A[++A_xb] = 1; A[++A_xb] = 1;} - else if (ch == '8') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 0;} - else if (ch == '9') - { A[++A_xb] = 1; A[++A_xb] = 0; A[++A_xb] = 0; A[++A_xb] = 1;} - } - - int start = 1; - while(A[start] == 0 && start <= 4) start++; //ȥǰ0 - - int res = 1000000000; - - B[start - 1] = 0, B[start] = 0; //һƲת - for (int i = start + 1; i <= 4 * len + 1; i++) - B[i] = (B[i - 1] + B[i - 2] + A[i - 1]) % 2; - if (!B[4 * len + 1]) - res = min(res, accumulate(B + start, B + 4 * len + 1, 0)); - - - B[start - 1] = 0, B[start] = 1; //һҪת - for (int i = start + 1; i <= 4 * len + 1; i++) - B[i] = (B[i - 1] + B[i - 2] + A[i - 1]) % 2; - if (!B[4 * len + 1]) - res = min(res, accumulate(B + start, B + 4 * len + 1, 0)); - - if (res == 1000000000) - cout << "No"; - else - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P6382.cpp" "b/\346\264\233\350\260\267/P6382.cpp" deleted file mode 100644 index 72ce8d6..0000000 --- "a/\346\264\233\350\260\267/P6382.cpp" +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - string a; cin >> a; - - int last; - int A[6]; memset(A, 0, sizeof(A)); - - if (a[0] == 'M' && a[1] == 'D' && a[2] == 'A') - { - for (int i = 7; i >= 3; i--) - if (a[i] >= '0' && a[i] <= '9') { last = a[i] - '0'; break;} - if (last == 1 || last == 9) A[1] = 1; - else if (last == 2 || last == 8) A[2] = 1; - else if (last == 3 || last == 7) A[3] = 1; - else if (last == 4 || last == 6) A[4] = 1; - else if (last == 5 || last == 0) A[5] = 1; - } - else - A[1] = A[2] = A[3] = A[4] = A[5] = 1; - - cout << A[1] << " " << A[2] << " " << A[3] << " " << A[4] << " " << A[5]; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P6686.cpp" "b/\346\264\233\350\260\267/P6686.cpp" deleted file mode 100644 index 850837b..0000000 --- "a/\346\264\233\350\260\267/P6686.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include -using namespace std; - -long long int A[200010]; -long long int B[200010]; -int main() -{ - memset(A, 0, sizeof(A)); - int N; cin >> N; - - int tmp; - for (int i = 1; i <= N; i++) - { cin >> tmp; A[tmp]++;} - - B[0] = 0; - for (int i = 1; i <= 200001; i++) - B[i] = B[i - 1] + A[i - 1]; //СB[i] - - long long int sum = 0; - long long int Mod = 998244353; - - for (int i = 1; i <= 200000; i++) - { - if (A[i] == 2) - sum += (B[min(2 * i, 200001)] - A[i]); //С߳ҳi - else if (A[i] >= 3) - sum += A[i] * (A[i] - 1) * (A[i] - 2) / 6 + (B[min(2 * i, 200001)] - A[i]) * A[i] * (A[i] - 1) / 2; - //ֱڳΪiѡȡڳΪiѡȡ2С߳ҳiѡȡ1 - sum %= Mod; - } - cout << sum; - - return 0; -} diff --git "a/\346\264\233\350\260\267/P6851.cpp" "b/\346\264\233\350\260\267/P6851.cpp" deleted file mode 100644 index 52ffd8d..0000000 --- "a/\346\264\233\350\260\267/P6851.cpp" +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -using namespace std; - -int main() -{ - long long int n; scanf("%lld", &n); - unsigned long long int res; - - if (n <= 0) { printf("%d", 0); return 0; } - else - { - res = n; - printf("%llu", 2 * res - 1); - } - return 0; -} diff --git "a/\346\264\233\350\260\267/T13706.cpp" "b/\346\264\233\350\260\267/T13706.cpp" deleted file mode 100644 index 61dcf35..0000000 --- "a/\346\264\233\350\260\267/T13706.cpp" +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include - -using namespace std; - -int H[3010][3010]; -int T[3010][3010]; // -int B[3010][3010]; // -int L[3010][3010]; // -int R[3010][3010]; // - -struct node -{ - int num; - int index; - node(int n, int i):num(n), index(i){}; -}; - -int main() -{ - int n, m; scanf("%d%d", &n, &m); - - for (int i = 1; i <= n; i++) - for (int j = 1; j <= m; j++) - scanf("%d", &H[i][j]); - - for (int i = 1; i <= n; i++) - { - stack s; - for (int j = 1; j <= m; j++) - { - while (!s.empty() && s.top().num >= H[i][j]) s.pop(); - if (s.empty()) L[i][j] = j - 1; - else L[i][j] = j - s.top().index - 1; - s.push(node(H[i][j], j)); - } - while(!s.empty()) s.pop(); - for (int j = m; j >= 1; j--) - { - while (!s.empty() && s.top().num >= H[i][j]) s.pop(); - if (s.empty()) R[i][j] = m - j; - else R[i][j] = s.top().index - j - 1; - s.push(node(H[i][j], j)); - } - } - - for (int j = 1; j <= m; j++) - { - stack s; - for (int i = 1; i <= n; i++) - { - while (!s.empty() && s.top().num >= H[i][j]) s.pop(); - if (s.empty()) T[i][j] = i - 1; - else T[i][j] = i - s.top().index - 1; - s.push(node(H[i][j], i)); - } - while(!s.empty()) s.pop(); - for (int i = n; i >= 1; i--) - { - while (!s.empty() && s.top().num >= H[i][j]) s.pop(); - if (s.empty()) B[i][j] = n - i; - else B[i][j] = s.top().index - i - 1; - s.push(node(H[i][j], i)); - } - } - - int res = 0; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= m; j++) - res = max(res, (T[i][j] + B[i][j] + L[i][j] + R[i][j] + 1) * H[i][j]); - cout << res; - - - /*int res = 0; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= m; j++) - { - int sum = 1; // - for (int x = i - 1; x >= 1 && H[x][j] >= H[i][j]; x--) - sum++; - for (int x = i + 1; x <= n && H[x][j] >= H[i][j]; x++) - sum++; - for (int y = j - 1; y >= 1 && H[i][y] >= H[i][j]; y--) - sum++; - for (int y = j + 1; y <= m && H[i][y] >= H[i][j]; y++) - sum++; - res = max(res, sum * H[i][j]); - } - cout << res;*/ - - return 0; -} diff --git "a/\346\264\233\350\260\267/T140410.cpp" "b/\346\264\233\350\260\267/T140410.cpp" deleted file mode 100644 index 2a55a84..0000000 --- "a/\346\264\233\350\260\267/T140410.cpp" +++ /dev/null @@ -1,22 +0,0 @@ -#include - -using namespace std; - -int A[100010]; - -int main() -{ - int n, q; cin >> n >> q; - for (int i = 1; i <= n; i++) - cin >> A[i]; - int L, R; - for (int i = 1; i <= q; i++) - { - cin >> L >> R; - int m = 1e9; - for (int j = L; j <= R; j++) - if (A[j] < m) m = A[j]; - cout << m - 1 << endl; - } - return 0; -} diff --git "a/\346\264\233\350\260\267/T142269B.cpp" "b/\346\264\233\350\260\267/T142269B.cpp" deleted file mode 100644 index 0c1a967..0000000 --- "a/\346\264\233\350\260\267/T142269B.cpp" +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -using namespace std; - -long long int A[1000010]; - -int main() -{ - int n, k; scanf("%d%d", &n, &k); - int a, b; - - memset(A, 0, sizeof(A)); - for (int i = 1; i <= n; i++) - { - scanf("%d%d", &a, &b); - A[a] += (long long)b; - } - - long long int res = -1; - long long int tmp; - - for (int i = 0; i <= 1000000 - k; i++) - { - tmp = min(A[i], A[i + k]); - if (tmp == 0) continue; //ijû - - if (k == 0) //⴦0 - if (tmp == 1) continue; - else res = max(res, tmp * i); - else - res = max(res, tmp * (i + i + k)); - } - - if (res == -1) cout << "NO"; - else cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/T142270A.cpp" "b/\346\264\233\350\260\267/T142270A.cpp" deleted file mode 100644 index 26ac5a3..0000000 --- "a/\346\264\233\350\260\267/T142270A.cpp" +++ /dev/null @@ -1,30 +0,0 @@ -#include - -using namespace std; - -int main() -{ - long long int a, b, c; cin >> a >> b >> c; - - if (a > b) - { - b += c; - if (b > a) - a = b = (a + b) / 2; - } - else - { - a += c; - if (a > b) - a = b = (a + b) / 2; - } - c = min(a, b); - - long long int res = sqrt(2 * c); - - while(res * (res + 1) / 2 > c) - res--; - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/T142289C.cpp" "b/\346\264\233\350\260\267/T142289C.cpp" deleted file mode 100644 index 2d2c247..0000000 --- "a/\346\264\233\350\260\267/T142289C.cpp" +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include - -using namespace std; - -int A[300010]; -bool flag[300010]; - -struct node -{ - int num; //ֵ - int times; // -}; -node T[300010]; - -int main() -{ - int n; scanf("%d", &n); - for (int i = 1; i <= n; i++) - scanf("%d", &A[i]); - sort(A + 1, A + n + 1); // - - int T_xb = 0; - for (int i = 1; i <= n; i++) - { - int j = i; - while(j < n && A[j] == A[j + 1]) j++; - //AתΪT - ++T_xb; - T[T_xb].num = A[i]; - T[T_xb].times = j - i + 1; - i = j; - } - - map MAP; - map:: iterator iter; - for (int i = 1; i <= T_xb; i++) - MAP.insert(pair(T[i].num, i)); - - - memset(flag, 0, sizeof(flag)); //ͳƸǷù - long long int res = -1; - long long int tmp_sum; - - for (int i = 1; i <= T_xb; i++) - { - if (flag[i]) continue; //Ѿ - - tmp_sum = 0; - int j = i; //Ѱһ - int next; - - do - { - tmp_sum += (long long)T[j].num * (long long)T[j].times; //һ - flag[j] = true; //Ϊ - //Ѱһ - if (T[j].num % 2 == 1) break; //һܴڣ˳ѭ - - next = (T[j].num / 2) * 3; //һֵ - - iter = MAP.find(next); - if (iter != MAP.end()) - j = iter->second; - //while(++j <= T_xb && T[j].num < next); - }while(iter != MAP.end()); - //while(j <= T_xb && T[j].num == next); - res = max(res, tmp_sum); - - } - cout << res; - - return 0; -} diff --git "a/\346\264\233\350\260\267/T145688.cpp" "b/\346\264\233\350\260\267/T145688.cpp" deleted file mode 100644 index b907ca0..0000000 --- "a/\346\264\233\350\260\267/T145688.cpp" +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -using namespace std; - -int A[1000010]; -struct node -{ - int x; - int y; -}; -node B[1000010]; -int B_index = 0; - -int main() -{ - int n, m; scanf("%d%d", &n, &m); - for (int i = 1; i <= n; i++) A[i] = i; - - int cur = 0, ch, x, y; - while(m--) - { - scanf("%d", &ch); - if (ch == 1 || ch == 2) - cur = ch, B_index = 0; - else if (ch == 3) - B_index++, scanf("%d%d", &B[B_index].x, &B[B_index].y); - else - B_index++, B[B_index].x = -1; //зת - } - - bool head = true; //ͷһ - if (cur == 2) - head = false; //ͷԶ - for (int i = 1; i <= B_index; i++) - if (B[i].x == -1) - head = !head; - else - if (head) - { - int tmp = A[B[i].x]; - A[B[i].x] = A[B[i].y]; - A[B[i].y] = tmp; - } - else - { - int tmp = A[n + 1 - B[i].x]; - A[n + 1 - B[i].x] = A[n + 1 - B[i].y]; - A[n + 1 - B[i].y] = tmp; - } - - if (head) - for (int i = 1; i <= n; i++) printf("%d ", A[i]); - else for (int i = n; i >= 1; i--) printf("%d ", A[i]); - - return 0; -} diff --git "a/\346\264\233\350\260\267/T145827.cpp" "b/\346\264\233\350\260\267/T145827.cpp" deleted file mode 100644 index 6510fee..0000000 --- "a/\346\264\233\350\260\267/T145827.cpp" +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include - -using namespace std; -struct nodeA -{ - int no_more; - long long int leave; -}; -nodeA N_A[1000010]; -int A[1000010]; -int B[1000010]; -struct nodeB -{ - int no_more; - long long int come; -}; -nodeB N_B[1000010]; -int main() -{ - int n, m, k; scanf("%d%d%d", &n, &m, &k); - for (int i = 1; i <= n; i++) - scanf("%d", &A[n - i + 1]); - long long int A_sum = 0; - for (int i = 1; i <= n; i++) - { - N_A[i].leave = A_sum; - N_A[i].no_more = A[i]; - A_sum += (long long)A[i]; - } - - - for (int i = 1; i <= m; i++) - scanf("%d", &B[i]); - sort(B + 1, B + m + 1); //С - long long int B_sum = 0; - for (int i = 1; i <= k; i++) - B_sum += (long long)B[i]; - N_B[1].come = B_sum; - N_B[1].no_more = B[k]; - for (int i = k + 1; i <= m; i++) - { - B_sum = B_sum - (long long)B[i - k] + (long long)B[i]; - N_B[i - k + 1].come = B_sum; - N_B[i - k + 1].no_more = B[i]; - } - - int A_index = n, B_index = m - k + 1; - - long long int res = 0; - int i = 1; - for (int j = 1; j <= B_index; j++) - { - while(N_A[i].no_more <= N_B[j].no_more) i++; - if (i > n) break; - res = max(res, N_B[j].come - N_A[i].leave); - } - for (int i = 1; i <= n; i++) - res += (long long)A[i]; - cout << res; - return 0; -} diff --git "a/\346\264\233\350\260\267/U129453.cpp" "b/\346\264\233\350\260\267/U129453.cpp" deleted file mode 100644 index 587d09e..0000000 --- "a/\346\264\233\350\260\267/U129453.cpp" +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -using namespace std; -long long n, k; - -long long Dfs(long long left, long long right) -{ - long long mid = (left + right) >> 1; - - long long L = mid - left - 1, R = right - mid - 1; - - if (L < k && R < k) - return 0; - else if (L < k) - return Dfs(mid, right); - else if (R < k) - return Dfs(left, mid); - - long long iter = (k << 1) + 1; - if (L < iter && R < iter) - return 1; - else if (L < iter) - return Dfs(mid, right) + 1; - else if (R < iter) - return Dfs(left, mid) + 1; - - if ((left + right) & 1) return Dfs(left, mid) + Dfs(mid, right) + 1; - else return (Dfs(left, mid) << 1) + 1; -} -int main() -{ - scanf("%lld%lld", &n, &k); - cout << 1 + Dfs(1, n + 1); - return 0; -}