By xiaruize
Stop Learning useless algorithms. --Um_nik
当你在想dp,想贪心,想hash时,都不会的Beginner已经AC了!!!
先特判n=2的情况
其他的s[0]=A且s[n−1]=B的是No
其他都是Yes
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define debug(x) cerr << #x << ": " << x << endl #define double long double const int INF = 0x3f3f3f3f; const int MOD = 1000000007; const int N = 2e5 + 10;
string s; int n;
signed main() { cin >> n; cin >> s; if (n == 2) { if (s == "AA" || s == "BB") Yes; else No; return 0; } if (s[0] == 'A' && s[n - 1] == 'B') No; else Yes; return 0; }
|
1≤N,A,B≤1018明显数学,分类讨论
- n<a,答案为0
- b>a, 答案为n−a+1
- 其他情况 答案为 an+(an−1)⋅(b−1)+min(nmoda,b−1)
前两个情况是显然的,这里解释一下第三个
首先,第一次一定取尽可能多的a使得剩下的值小于b
形式化表示就是求
{1≤i≤nimoda<b
然后就可以数学计算啦
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ALL(a) (a).begin(), (a).end() #define pb push_back #define mk make_pair #define pii pair<int, int> #define pis pair<int, string> #define sec second #define fir first #define sz(a) int((a).size()) #define rep(i, x, y) for (int i = x; i <= y; i++) #define repp(i, x, y) for (int i = x; i >= y; i--) #define Yes cout << "Yes" << endl #define YES cout << "YES" << endl #define No cout << "No" << endl #define NO cout << "NO" << endl #define debug(x) cerr << #x << ": " << x << endl #define double long double const int INF = 0x3f3f3f3f; const int MOD = 1000000007; const int N = 2e5 + 10;
int n, a, b;
signed main() { cin >> n >> a >> b; if (n < a) cout << "0" << endl; else if (b > a) cout << n - a + 1 << endl; else { cout << n / a + (n / a - 1) * (b - 1) + min(n % a, b - 1) << endl; } return 0; }
|