F
模拟
AC代码:
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x) & -(x)) #define endl '\n' #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } void solve() { string s; cin >> s; int k; cin >> k; int len = s.size(); int cnt1 = count(s.begin(), s.end(), '+'),cnt2 = count(s.begin(), s.end(), '-'); if(len % 2 == 0){ int mid = len / 2; int c = max(cnt1, cnt2) - mid; if(k >= c){ k -= c; if(k % 2 == 0){ cout << 0 << endl; } else{ cout << 2 << endl; } } else{ cout << max(cnt1, cnt2) - min(cnt1, cnt2) - 2 * k << endl; } } else{ int mid = len / 2; int c = max(cnt1, cnt2) - mid; if(k >= c){ cout << 1 << endl; } else{ cout << max(cnt1, cnt2) - min(cnt1, cnt2) - 2 * k << endl; } } return; } int main() { IOS1; //IOS2; int __t = 1; cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
I
模拟
AC代码:
/* Tips: 1.int? long long? 2.don't submit wrong answer 3.figure out logic first, then start writing please 4.know about the range 5.check if you have to input t or not 6.modulo of negative numbers is not a%b, it is a%b + abs(b) */ #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x) & -(x)) #define endl '\n' #define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef vector<long long> vll; typedef vector<char> vc; typedef long long ll; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> T power(T a, int b) { T res = 1; for (; b; b >>= 1, a = a * a) { if (b & 1) { res = res * a; } } return res; } template <typename T> inline void read(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); } x *= f; } const int INF = 0x3f3f3f3f; const int mod = 1000000007; const double PI = acos(-1.0); const double eps = 1e-6; inline int sgn(double x) { return x < -eps ? -1 : x > eps; } void solve() { int k; string a, b; cin >> k >> a >> b; int lena = a.size(); int lenb = b.size(); reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); vector<int> c(200010, 0); if(lena >= lenb){ for(int i = 0;i < lena;i++){ c[i] = a[i] - '0'; } for(int i = 0;i < lenb;i++){ int x = b[i] - '0'; if(c[i] + x >= k){ int cnt = (c[i] + x) / k; c[i] = (c[i] + x) - cnt * k; c[i + 1] += cnt; } else{ c[i] += x; } } for(int i = 0;i < lena;i++){ if(c[i] >= k){ int cnt = c[i] / k; c[i + 1] += cnt; c[i] -= k * cnt; } } if(c[lena] == 0){ for(int i = lena - 1;i >= 0;i--){ cout << c[i]; } cout << endl; } else{ for(int i = lena;i >= 0;i--){ cout << c[i]; } cout << endl; } } else{ for(int i = 0;i < lenb;i++){ c[i] = b[i] -'0'; } for(int i = 0;i < lena;i++){ int x = a[i] - '0'; if(c[i] + x >= k){ int cnt = (c[i] + x) / k; c[i] = (c[i] + x) - cnt * k; c[i + 1] += cnt; } else{ c[i] += x; } } for(int i = 0;i < lenb;i++){ if(c[i] >= k){ int cnt = c[i] / k; c[i + 1] += cnt; c[i] -= k * cnt; } } if(c[lenb] == 0){ for(int i = lenb - 1;i >= 0;i--){ cout << c[i]; } cout << endl; } else{ for(int i = lenb;i >= 0;i--){ cout << c[i]; } cout << endl; } } return; } int main() { IOS1; //IOS2; int __t = 1; // cin >> __t; for (int _t = 1; _t <= __t; _t++) { solve(); } return 0; } /* */
2022牛客寒假算法基础集训营6(2/10)
于 2022-02-15 14:57:12 首次发布