By xiaruize
水调歌头
苏轼
丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。 明月几时有?把酒问青天。 不知天上宫阙,今夕是何年? 我欲乘风归去,又恐琼楼玉宇,高处不胜寒。 起舞弄清影,何似在人间?
转朱阁,低绮户,照无眠。 不应有恨,何事长向别时圆? 人有悲欢离合,月有阴晴圆缺,此事古难全。 但愿人长久,千里共婵娟。
Codeforces rating涨了 qwq
Method分两种情况:
情况一 他有≥ 1 \geq1 ≥ 1 个1-buble的硬币
a n s = a + 2 b ans=a+2b a n s = a + 2 b
情况二 他没有1-buble的硬币
则他一定付不出1-buble这个金额
∴ a n s = 1 \therefore ans=1 ∴ a n s = 1
Code1 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 #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 double long double const int INF = 0x3f3f3f3f ;const int MOD = 1000000007 ;const int N = 1e5 + 10 ;int t;void solve () { int a, b; cin >> a >> b; if (a == 0 ) cout << "1" << endl; else cout << a + 2 * b + 1 << endl; } signed main () { cin >> t; while (t--) solve (); return 0 ; }
Method每次操作,我们优先降低最大值,只要最大值和次大值的差≤ 1 \leq1 ≤ 1 就一定可以完成
Code1 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 68 69 70 71 72 73 74 75 #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 double long double const int INF = 0x3f3f3f3f ;const int MOD = 1000000007 ;const int N = 2e5 + 10 ;int t;int n;int a[N];int mx, smx;void solve () { mx = smx = 0 ; cin >> n; for (int i = 1 ; i <= n; i++) cin >> a[i]; for (int i = 1 ; i <= n; i++) { if (a[i] > mx) { smx = mx; mx = a[i]; } else if (a[i] > smx) smx = a[i]; } if (mx - smx <= 1 ) YES; else NO; } signed main () { cin >> t; while (t--) solve (); return 0 ; }
Feeling赛时在这题上卡了很久。。。
Method贪心策略:
按顺序遍历,如果存在配对则一定优先选取。
Code1 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 68 #include <bits/stdc++.h> using namespace std;const int INF = 0x3f3f3f3f ;const int MOD = 1000000007 ;const int N = 2e5 + 10 ;int t;string s; int la[30 ];int now = 0 ;int ans = 0 ;void solve () { ans = 0 ; now = 0 ; s = "" ; memset (la, 0 , sizeof (la)); cin >> s; s = ' ' + s; for (int i = 1 ; i < s.size (); i++) { if (la[s[i] - 'a' ] && now < la[s[i] - 'a' ]) { for (int j = max (1 , now); j < i; j++) la[s[j] - 'a' ] = 0 ; ans += i - now - 2 ; now = i; la[s[i] - 'a' ] = 0 ; } else { la[s[i] - 'a' ] = i; } } for (int i = 0 ; i < 26 ; i++) if (la[i]) ans++; cout << ans << endl; return ; } signed main () { cin >> t; while (t--) solve (); return 0 ; }
Method并不是很难,思路很简单
可以用每个0 0 0 为界线,把数组分成几段,下面我们讨论对每一段求最大值:
因为全部删去时的值为1 1 1 ,所以任意一段的极值一定为正。
可以用前缀和维护负数的个数。(设到第i i i 位为s u m i sum_i s u m i )
对于每一段,可以O ( n ) O(n) O ( n ) 找到包含区间最大的一对( i , j ) (i,j) ( i , j ) 使得s u m i ≡ s u m j ( m o d 2 ) sum_i\equiv sum_j(mod 2) s u m i ≡ s u m j ( m o d 2 )
可以证明区间[i+1,j]为当前段中的最优答案
2 100 大 于 l o n g l o n g 的 范 围 , 统 计 一 定 不 要 统 计 值 q w q 2^{100}大于long long的范围,统计一定不要统计值qwq 2 1 0 0 大 于 l o n g l o n g 的 范 围 , 统 计 一 定 不 要 统 计 值 q w q
Code1 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 #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 double long double const int INF = 0x3f3f3f3f ;const int MOD = 1000000007 ;const int N = 2e5 + 10 ;int t;int n;int a[N];int cnt[N];int sum[N];int fo, fe;int lo, le;void solve () { memset (sum, 0 , sizeof (sum)); le = lo = fe = fo = 0 ; cin >> n; for (int i = 1 ; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1 ] + (a[i] == 2 || a[i] == -2 ); } int mx = 0 ; pii ans; for (int i = 1 ; i <= n; i++) { if (a[i] != 0 ) { cnt[i] = cnt[i - 1 ] + (a[i] < 0 ); if (cnt[i] & 1 && !fo) fo = i; if (cnt[i] & 1 ) lo = i; else le = i; } if (a[i] == 0 ) { if (fo && (sum[lo] - sum[fo]) > mx) { mx = (sum[lo] - sum[fo]); ans = {fo, lo}; } if ((sum[le] - sum[fe]) > mx) { mx = (sum[le] - sum[fe]); ans = {fe, le}; } fe = le = i; fo = lo = 0 ; cnt[i] = 0 ; } } if (fo && (sum[lo] - sum[fo]) > mx) { mx = (sum[lo] - sum[fo]); ans = {fo, lo}; } if ((sum[le] - sum[fe]) > mx) { mx = (sum[le] - sum[fe]); ans = {fe, le}; } cout << ans.fir << ' ' << n - ans.sec << endl; } signed main () { cin >> t; while (t--) solve (); return 0 ; }
Codeforces-Round-#780-(Div.3)-Tutorial