Codeforces Round #296 (Div. 2)
许久未上过博客,正如许久没写过题目, 如今许多模板题都敲不来了,不禁想“论练题的重要性”,先把这几次cf补一下 。
总的来说,Codeforces Round #297 (Div. 2) 并不难(至少前4题) a手速, b,c stl, d小技巧
B. Error Correct System
1 /***Good Luck***/ 2 #define _CRT_SECURE_NO_WARNINGS 3 #include <iostream> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <string> 8 #include <algorithm> 9 #include <stack> 10 #include <map> 11 #include <queue> 12 #include <vector> 13 #include <set> 14 #include <functional> 15 #include <cmath> 16 #include <numeric> 17 18 #define ll long long 19 #define Zero(x) memset((x),0, sizeof(x)) 20 #define Neg(x) memset((x), -1, sizeof(x)) 21 #define dg(x) cout << #x << " = " << x << endl; 22 #define pk(x) push_back(x) 23 #define pii pair<int, int> 24 using namespace std; 25 int OK = 1; 26 int n; 27 string s, t; 28 map<pair<char, char>, int > mp, rmp; 29 int main(){ 30 //freopen("data.out", "w", stdout); 31 //freopen("data.in", "r", stdin); 32 //cin.sync_with_stdio(false); 33 while(cin >> n){ 34 cin >> s >>t; 35 mp.clear(); 36 rmp.clear(); 37 int ans = 0; 38 for(int i = 0; i< n;++i){ 39 if(s[i] != t[i]){ 40 mp[make_pair(s[i], t[i])] = i + 1; 41 rmp[make_pair(t[i], s[i])] = i + 1; 42 ans++; 43 } 44 } 45 auto mb = mp.begin(), rmb = rmp.begin(); 46 bool flag = false; 47 int ansa, ansb; 48 while(!mp.empty() && !rmp.empty()){ 49 mb = mp.begin(); 50 rmb = rmp.begin(); 51 if(mb->first.first == rmb->first.first){ 52 flag = true; 53 ansa = mb->second; 54 ansb = rmb->second; 55 } 56 57 if(mb->first > rmb->first) { 58 rmp.erase(rmb); 59 }else if(mb->first < rmb->first){ 60 mp.erase(mb); 61 }else { 62 ans -= 2; 63 cout << ans << endl; 64 cout << mb->second << " " << rmb->second << endl; 65 return 0; 66 } 67 } 68 if(flag){ 69 cout << --ans <<endl;; 70 cout << ansa << " " << ansb <<endl; 71 }else { 72 cout << ans << endl; 73 cout << "-1 -1" << endl; 74 } 75 76 } 77 }
C. Glass Carving
1 /***Good Luck***/ 2 #define _CRT_SECURE_NO_WARNINGS 3 #include <iostream> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <string> 8 #include <algorithm> 9 #include <stack> 10 #include <map> 11 #include <queue> 12 #include <vector> 13 #include <set> 14 #include <functional> 15 #include <cmath> 16 #include <numeric> 17 18 #define ll long long 19 #define Zero(x) memset((x),0, sizeof(x)) 20 #define Neg(x) memset((x), -1, sizeof(x)) 21 #define dg(x) cout << #x << " = " << x << endl; 22 #define pk(x) push_back(x) 23 #define pii pair<int, int> 24 using namespace std; 25 int OK = 1; 26 int n, w, h; 27 int main(){ 28 //freopen("data.out", "w", stdout); 29 //freopen("data.in", "r", stdin); 30 cin.sync_with_stdio(false); 31 cin >> w >> h >> n; 32 string c; 33 int line; 34 map <int, pii> mpw, mph; 35 multiset<int> sw, sh; 36 mpw[0] = make_pair(0, w); 37 sw.insert(w); 38 mph[0] = make_pair(0, h); 39 sh.insert(h); 40 map <int, pii>::iterator it; 41 multiset<int>::iterator it1; 42 pair<int, pii> t; 43 for (int i = 0; i < n; ++i){ 44 cin >> c >> line; 45 if (c == "V"){ 46 it = mpw.lower_bound(line); 47 --it; 48 t = *it; 49 50 mpw.erase(it); 51 mpw[t.first] = make_pair(t.first, line); 52 mpw[line] = make_pair(line, t.second.second); 53 it1 = sw.find(t.second.second - t.second.first); 54 sw.erase(it1); 55 sw.insert(line - t.first); 56 sw.insert(t.second.second - line); 57 } 58 else { 59 it = mph.lower_bound(line); 60 --it; 61 t = *it; 62 mph.erase(it); 63 mph[t.first] = make_pair(t.first, line); 64 mph[line] = make_pair(line, t.second.second); 65 it1 = sh.find(t.second.second - t.second.first); 66 sh.erase(it1); 67 sh.insert(line - t.first); 68 sh.insert(t.second.second - line); 69 } 70 cout << (ll)(*(sw.rbegin()))* (ll)(*(sh.rbegin())) << endl; 71 } 72 73 }
D. Clique Problem
1 #include <vector> 2 #include <set> 3 #include <functional> 4 #include <cmath> 5 #include <numeric> 6 7 #define ll long long 8 #define Zero(x) memset((x),0, sizeof(x)) 9 #define Neg(x) memset((x), -1, sizeof(x)) 10 #define dg(x) cout << #x << " = " << x 11 #define pk(x) push_back(x) 12 using namespace std; 13 #define maxn 200001 14 #define mod 10007 15 #define eps 1e-9 16 const int inf=0x7fffffff; 17 struct node 18 { 19 int x,y; 20 }; 21 22 node a[maxn]; 23 bool cmp(node aa,node bb) 24 { 25 if(aa.x==bb.x) 26 return aa.y<bb.y; 27 return aa.x<bb.x; 28 } 29 int main() 30 { 31 int n,aa,bb; 32 cin>>n; 33 for(int i=0;i<n;i++) 34 { 35 scanf("%d%d",&aa,&bb); 36 a[i].x=aa+bb; 37 a[i].y=aa-bb; 38 } 39 sort(a,a+n,cmp); 40 int l=-inf; 41 int ans=0; 42 for(int i=0;i<n;i++) 43 { 44 if(a[i].y>=l) 45 { 46 l=a[i].x; 47 ans++; 48 } 49 } 50 cout<<ans<<endl; 51 }