#include<bits/stdc++.h> usingnamespace std; intmain(){ int n, m; cin >> n >> m; vector<vector<int>> nums(n,vector<int>(m)); for (auto& i : nums) { for (auto& j : i) { cin >> j; } } for (int j = 0; j < m; j++) { for (int i = n - 1; i >= 0; i--) { cout << nums[i][j] << ' '; } cout << endl; } return0; }
BJTU-ALGO 1007
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<bits/stdc++.h> #define square(x) ((x)*(x)) usingnamespace std; intmain(){ int N; double R, C = 0.0; cin >> N >> R; vector<pair<double, double>> points(N, pair<double, double>()); for (int i = 0; i < N; i++) { cin >> points[i].first >> points[i].second; } for (int i = 1; i < N; i++) { C += sqrt(square(points[i].first - points[i - 1].first) + square(points[i].second - points[i - 1].second)); } C += sqrt(square(points[0].first - points[N - 1].first) + square(points[0].second - points[N - 1].second)); cout << setiosflags(ios::fixed) << setprecision(2); cout << C + acos(-1) * 2.0 * R << endl; return0; }
intproduct_counts(int i){ int ans = 0; for (int j = 1; j <= i; j++) { if (i % j == 0) { ans++; } } return ans; }
intmain(){ int K; bool s = false; cin >> K; for (int i = 1; i <= 2000; i++) { if (product_counts(i) == K) { cout << i << endl; s = true; } } cout << (s ? "" : "NO SOLUTION\n"); return0; }
//AC代码 #include<bits/stdc++.h> usingnamespace std; using ll = longlong; ll ans = 0; int n, k;
voiddfs(int last_sum, int last_num,int cur_depth){ if (cur_depth == k - 1) { if (n - last_sum >= last_num) {//减少一层深度就过了 ans++; } return; } for (int i = last_num; i <= n - last_sum; i++) { dfs(last_sum + i, i, cur_depth + 1); } }
intmain(){ cin >> n >> k; for (int i = 1; i <= n / k + 1; i++) { dfs(i, i, 1); } cout << ans << endl; return0; }
//80分代码 #include<bits/stdc++.h> usingnamespace std; using ll = longlong; ll ans = 0; int n, k;
voiddfs(int last_sum, int last_num, int cur_depth){ if (cur_depth == k) { if (last_sum == n) { ans++; } return; } for (int i = last_num; i = n - last_sum; i++) { dfs(last_sum + i, i, cur_depth + 1); } }
intmain(){ cin >> n >> k; for (int i = 1; i <= n / k + 1; i++) { dfs(i, i, 1); } cout << ans << endl; return0; }
BJTU-ALGO 1106
本题最佳解法是直接计算卡特兰数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//本题实际上是计算卡特兰数的裸题 #include<bits/stdc++.h> usingnamespace std; using ll = longlong; intmain(){ int n; cin >> n; ll ans = 1;//卡特兰数 for (int i = 2 * n; i >= n + 2; i--) { ans *= i; } for (int i = n; i >= 2; i--) { ans /= i; } cout << ans << endl; return0; }