Codeforces Round #547 (Div. 3) D
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #547 (Div. 3) D
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
http://codeforces.com/contest/1141/problem/D
?
題目大意:
鞋子匹配,用一個小寫字母表示一種顏色。L[i]表示左腳的顏色,R[i]表示右腳的顏色,只有當L[i]和R[j]的顏色差不多了,才算匹配成功。但是,有一種特殊的顏色‘?’,該顏色可以和任意另一半鞋子匹配。
?
思路:
取出‘?’,格外判斷就好了
?
//看看會不會爆int!數(shù)組會不會少了一維! //取物問題一定要小心先手勝利的條件 #include <bits/stdc++.h> #pragma comment(linker,"/STACK:102400000,102400000") #define LL long long #define ALL(a) a.begin(), a.end() #define pb push_back #define mk make_pair #define fi first #define se second #define haha printf("haha\n")using namespace std; const int maxn = 150000 + 5; vector<pair<int, int> > l, r; bool fl[maxn], fr[maxn]; char ch[maxn]; int n;int main(){cin >> n;scanf("%s", ch);vector<pair<int, int> > wenhaol;for (int i = 0; ch[i] != '\0'; i++){if (ch[i] >= 'a' && ch[i] <= 'z')l.pb(mk(ch[i], i));else if (ch[i] == '?')wenhaol.pb(mk(ch[i] + 80, i));}sort(l.begin(), l.end());scanf("%s", ch);vector<pair<int, int> > wenhaor;for (int i = 0; ch[i] != '\0'; i++){if (ch[i] >= 'a' && ch[i] <= 'z')r.pb(mk(ch[i], i));else if (ch[i] == '?')wenhaor.pb(mk(ch[i] + 80, i));}sort(r.begin(), r.end());vector<pair<int, int> > ans;int lb = 0, rb = 0;while (lb < l.size() && rb < r.size()){//printf("lb = %d rb = %d\n", lb, rb);if (l[lb].fi == r[rb].fi){ans.pb(mk(l[lb].se, r[rb].se));fl[lb] = fr[rb] = 1;lb++, rb++;continue;}/*if (l[lb].fi == '?' + 80 || r[rb].fi == '?' + 80){ans.pb(mk(l[lb].se, r[rb].se));fl[lb] = fr[rb] = 1;lb++, rb++;continue;}*/if (l[lb].fi > r[rb].fi && l[lb].fi != '?' + 80){rb++;continue;}if (r[rb].fi > l[lb].fi && r[rb].fi != '?' + 80){lb++;continue;}}lb = 0, rb = 0;for (int i = 0; i < l.size(); i++){if (fl[i] != 1 && rb < wenhaor.size()){ans.pb(mk(l[i].se, wenhaor[rb].se));rb++;}}for (int i = 0; i < r.size(); i++){if (fr[i] != 1 && lb < wenhaol.size()){ans.pb(mk(wenhaol[lb].se, r[i].se));lb++;}}while (lb < wenhaol.size() && rb < wenhaor.size()){ans.pb(mk(wenhaol[lb].se, wenhaor[rb].se));lb++, rb++;}printf("%d\n", ans.size());for (int i = 0; i < ans.size(); i++){printf("%d %d\n", ans[i].fi + 1, ans[i].se + 1);}return 0; } View Code?
轉載于:https://www.cnblogs.com/heimao5027/p/10650300.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Codeforces Round #547 (Div. 3) D的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一、WPF 2个datagrid之间同步
- 下一篇: Unity 2018.3.1 SyncV