Codeforces Round #732 (Div. 2)
C被叉了嗚嗚嗚
A. AquaMoon and Two Arrays
題意
給一個可操作數組aaa和一個目標數組bbb,每次操作選aaa中兩個元素,將其中一個?1-1?1,另一個+1+1+1. 但要保證所有元素一直是非負的。問有沒有可能把aaa變成bbb。如果可以,輸出你的操作步驟。
數據保證sum{a}≤100,n≤100sum\{a\}\leq 100, n\leq 100sum{a}≤100,n≤100,不要你操作次數最少,但要小于100100100次.
分析
既然要小于100次等于還是得控制,這不還是要找最少嘛(惱)
不過也可以n3n^3n3暴力就是了
代碼
#include <bits/stdc++.h> #define fors(i, a, b) for(int i = (a); i <= (b); ++i) #define lson k<<1 #define rson k<<1|1 #define pb push_back #define lowbit(x) ((x)&(-(x))) #define mem(a) memset(a, 0, sizeof(a)) #define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0) #define int long long const int inf = 0x3f3f3f3f; const double dinf = 1e100; typedef long long ll; //const ll linf = 9223372036854775807LL; // const ll linf = 1e18; using namespace std;signed main() {DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--){int n;cin >> n;int a[n], b[n];int sa = 0, sb = 0;for(int i = 0; i < n; ++i) cin >> a[i], sa += a[i];for(int i = 0; i < n; ++i) cin >> b[i], sb += b[i];if(sa != sb){cout << -1 << endl;continue;}vector<int> c;vector<int> d;int i, j;while(1){bool flag = 1;for(int i = 0; i < n; ++i){if(a[i] != b[i]){flag = 0;break;}}if(flag) break;for(i = 0; i < n; ++i){for(j = 0; j < n; ++j){if(a[i] > b[i] && a[j] < b[j]){break;}}while(a[i] > b[i] && a[j] < b[j]){a[i]--, a[j]++;c.pb(i), d.pb(j);}}}cout << c.size() << endl;for(int i = 0; i < c.size(); ++i){cout << c[i] + 1 << ' ' << d[i] + 1 << endl;}}return 0; }B. Aquamoon and Stolen String
題意
給出nnn(nnn為奇數)個長度為mmm的串,然后將其中n?1n-1n?1個串兩兩配對,配對的串會隨機交換相同位置的字符,給出配對完后被打亂順序的n?1n-1n?1個串,要你找出是哪個串沒有配對。
分析
由于不管怎么配對怎么變,每個字符交換后的下標都是不變的,只是變了所在的字符串。
所以用一個二維數組統計,a[i][j]a[i][j]a[i][j]表示字符iii在位置jjj出現過幾次。配對后再把出現的字符減去,最后二維數組里留下的那個字符就是未配對字符串的。
代碼
#include <bits/stdc++.h> #define fors(i, a, b) for(int i = (a); i <= (b); ++i) #define lson k<<1 #define rson k<<1|1 #define pb push_back #define lowbit(x) ((x)&(-(x))) #define mem(a) memset(a, 0, sizeof(a)) #define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0) #define int long long const int inf = 0x3f3f3f3f; const double dinf = 1e100; typedef long long ll; //const ll linf = 9223372036854775807LL; // const ll linf = 1e18; using namespace std; const int maxn = 1e5 + 10; map<char, int> mp[maxn]; signed main() {DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--){int n, m;cin >> n >> m;for(int i = 0; i < m; ++i) mp[i].clear();for(int i = 0; i < n; ++i){string s;cin >> s;for(int j = 0; j < m; ++j){mp[j][s[j]]++;}}for(int i = 0; i < n - 1; ++i){string s;cin >> s;for(int j = 0; j < m; ++j){mp[j][s[j]]--;}}for(int i = 0; i < m; ++i){for(auto x : mp[i]){if(x.second == 1){cout << x.first;break;}}}cout << endl;}return 0; }C. AquaMoon and Strange Sort
題意
給一個長度nnn的數組,要通過相鄰數對交換排成不下降序列。問是否可以保證每個數進行交換的次數為偶數。
分析
直接sort得到每個數可以在哪個區間內,如果原來的下標是奇數,就必在區間內占有一個奇數下標;原來是偶數,就必須在區間內占有一個偶數下標。看最后能否容得下即可。
代碼
#include <bits/stdc++.h> #define fors(i, a, b) for(int i = (a); i <= (b); ++i) #define lson k<<1 #define rson k<<1|1 #define pb push_back #define lowbit(x) ((x)&(-(x))) #define mem(a) memset(a, 0, sizeof(a)) #define DDLC_ESCAPE_PLAN_FAILED ios::sync_with_stdio(false), cin.tie(0) #define int long long const int inf = 0x3f3f3f3f; const double dinf = 1e100; typedef long long ll; //const ll linf = 9223372036854775807LL; // const ll linf = 1e18; using namespace std; const int maxn = 1e5 + 10; struct node {int idx, val; }a[maxn]; bool cmp(const node& x, const node& y) {return x.val < y.val; } signed main() {DDLC_ESCAPE_PLAN_FAILED;int t;cin >> t;while(t--){mem(a);int n;cin >> n;fors(i, 1, n) cin >> a[i].val, a[i].idx = i;sort(a + 1, a + 1 + n, cmp);bool flag = 1;int i = 1;for(; i <= n; ){vector<int> st;st.pb(a[i].idx);int org = i;i++;while(a[i].val == a[org].val && i <= n) st.pb(a[i++].idx);int tot = i - org;int odd, even;if(!(tot & 1)) odd = even = tot / 2;else if(org & 1) odd = (tot + 1) / 2, even = tot / 2;else odd = tot / 2, even = (tot + 1) / 2;for(auto x : st){if(x & 1) odd--;else even--;}if(odd < 0 || even < 0){flag = 0;break;}}if(flag) cout << "YES" << endl;else cout << "NO" << endl;}return 0; }總結
以上是生活随笔為你收集整理的Codeforces Round #732 (Div. 2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Sydney 免费wordpress企业
- 下一篇: OCM实战之RAC集群打补丁