问一句还有hc吗。。题不算太难。
1
// 判断n正多边形是否存在垂直边 #include<iostream> #include<vector> #include<string> using namespace std; int main() { int q; cin >> q; while (q--) { string t; cin >> t; if (t.size() <= 2) { if (stoi(t) % 4 == 0) cout << "YES" << endl; else cout << "NO" << endl; } else { string tem; tem += t[t.size() - 2]; tem += t[t.size() - 1]; if (stoi(tem) % 4 == 0) cout << "YES" << endl; else cout << "NO" << endl; } } return 0; }2
// 找全排列中的子排列 #include<iostream> #include<vector> using namespace std; const int N = 1e7; int L[N]; int main() { int t; cin >> t; int n; while (t--) { //scanf("%d", &n); cin >> n; int s; for (int i = 0; i < n; i++) { //scanf("%d", &L[i]); cin >> L[i]; if (L[i] == 1) s = i; } vector<int> ans(n, 0); int l = s - 1, r = s + 1; vector<int> tem; int maxt = 0; maxt = max(maxt, L[s]); tem.push_back(L[s]); if (maxt == tem.size()) ans[tem.size() - 1] = 1; while (l >= 0 || r < n) { if (l < 0) { tem.push_back(L[r]); maxt = max(maxt, L[r]); if (maxt == tem.size()) ans[tem.size() - 1] = 1; r++; } else if (r >= n) { tem.push_back(L[l]); maxt = max(maxt, L[l]); if (maxt == tem.size()) ans[tem.size() - 1] = 1; l--; } else { if (L[l] < L[r]) { tem.push_back(L[l]); maxt = max(maxt, L[l]); if (maxt == tem.size()) ans[tem.size() - 1] = 1; l--; } else { tem.push_back(L[r]); maxt = max(maxt, L[r]); if (maxt == tem.size()) ans[tem.size() - 1] = 1; r++; } } } for (int i = 0; i < n; i++) { cout << ans[i]; } cout << endl; } return 0; }3
// 大数gcd #include<iostream> #include<string> using namespace std; int m(string& a, int b) { int i, l = a.size(), ans = 0; for (int i = 0; i < l; i++) { ans = ans * 10 + a[i] - '0'; ans = ans % b; } return ans; } long long g(string a, long long b) { if (m(a, b) == 0) return b; return g(to_string(b), m(a, b)); } int main() { string a; long long b; cin >> a; cin >> b; long long ans = g(a, b); cout << m(a, b) << endl; cout << ans; return 0; }4
// 类似最大岛屿 #include<iostream> #include<vector> #include<string> using namespace std; void dfs(vector<string>& ve, vector<vector<bool>>& vis, int i, int j, int& tem) { if (i < 0 || i >= ve.size() || j < 0 || j >= ve[0].size() || ve[i][j] == '#' || vis[i][j]) return; vis[i][j] = true; tem++; dfs(ve, vis, i - 1, j, tem); dfs(ve, vis, i + 1, j, tem); dfs(ve, vis, i, j - 1, tem); dfs(ve, vis, i, j + 1, tem); } int main() { vector<string> ve; int n, m; cin >> n >> m; string str; int ans = 0; vector<vector<bool>> vis(n, vector<bool>(m, false)); for (int i = 0; i < n; i++) { cin >> str; ve.push_back(str); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int tem = 0; if (ve[i][j] != '#' && vis[i][j] == false) { dfs(ve, vis, i, j, tem); ans = max(ans, tem); } } } cout << ans; return 0; }
全部评论
(3) 回帖