Codeforces Raif Round 1 (Div2A ~ Div2C)
阿新 • • 發佈:2020-10-18
Link:
Codeforces https://codeforces.com/contest/1428
A. Box is Pull
讀錯題目 × 1
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<cstdlib> using namespace std; int t; int main() { ios::sync_with_stdio(false); cin >> t; int aa, bb, cc, dd; while(t--) { cin >> aa >> bb >> cc >> dd; if(aa==cc) { cout<<abs(dd-bb)<<endl;continue; } if(bb==dd) { cout<<abs(aa-cc)<<endl;continue; } cout<<abs(dd-bb)+abs(cc-aa)+2<<endl; continue; } return 0; }
B. Belted Rooms
沒反應過來題意就直接打了,浪費半小時
還 WA 了五發
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<cstdlib> using namespace std; const int MAXN = 3e5 + 10; int t, n, ans; char ch; bool headee; bool nota, notb; char chzer; int main() { cin >> t; while(t--) { cin >> n; headee = 0; ans = 0; nota = notb = false; chzer = '0'; for (int i = 0; i<n; ++i) { cin>>ch; if(!i)chzer=ch; if(ch=='-') { if(!headee)++ans; headee=1; ++ans; } else headee=0; if (ch=='>') nota=true; if(ch=='<')notb=true; } if (ch == chzer&&ch == '-') --ans; if(!nota||!notb)cout<<n<<endl; else cout<<ans<<endl; } return 0; }
C. ABBB
怎麼說呢,意外地很好寫
注意到 B 只要前面有字母都可以去掉,很好貪心
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<cstdlib> using namespace std; int t, n, ans; char ch; string s; int main() { cin >> t; while(t--) { cin >> s; n = s.length(); ans = 0; for(int Ben=0, Aen=0, i=0; i<n; ++i) { ch = s[i]; if(ch=='A') { ++Aen; } if(ch=='B') { if(Aen) { --Aen; ++ans; } else { if(Ben && !Aen) { --Ben; ++ans; } else ++Ben; } } } cout<<n-(ans<<1)<<endl; } return 0; }
D. Bouncing Boomerangs
睡了
反彈不會超過三次,所以很容易根據從哪裡進哪裡出約束一波