cf每日刷题c++
目录
Square Year(800)
Not Quite a Palindromic String(900)
Down with Brackets(900)
Square Year(800)
https://codeforces.com/problemset/problem/2114/A
#include <iostream>
#include <cmath>
using namespace std;
void solve()
{int n;cin >> n;int k = sqrt(n);if (k * k != n){cout << -1 << endl;return;}cout << 0 << " " << k << endl;
}
int main()
{int t;cin >> t;while (t--){solve();}return 0;
}
Not Quite a Palindromic String(900)
https://codeforces.com/problemset/problem/2114/B
#include <iostream>
#include <algorithm>
using namespace std;
void solve()
{int n, k;cin >> n >> k;int zero = 0;int one = 0;char t;for (int i = 0; i < n; i++){cin >> t;if (t == '0'){zero++;}else if (t == '1'){one++;}}int l = max(one, zero) - n / 2;int r = zero / 2 + one / 2;if (k >= l && k <= r){if (l % 2 == 1){if (k % 2 == 1){cout << "YES" << endl;return;}}else if (l % 2 == 0){if (k % 2 == 0){cout << "YES" << endl;return;}}}cout << "NO" << endl;return;
}
int main()
{int t;cin >> t;while (t--){solve();}return 0;
}
Down with Brackets(900)
https://codeforces.com/problemset/problem/2110/B
#include <iostream>
#include <string>
using namespace std;
void solve()
{string n;cin >> n;int res = 0;for (int i = 1; i < n.size() - 1; i++){if (n[i] == '('){res++;}else{res--;}if (res < 0){cout << "YES" << endl;return;}}if (res == 0){cout << "NO" << endl;return;}else{cout << "NO" << endl;return;}
}
int main()
{int t;cin >> t;while (t--){solve();}return 0;
}