标签:bool password hid view des tree lap pen ++
A. Sweet Problem
#include<bits/stdc++.h> #define rep(i, n) for(int i=0;i!=n;++i) #define per(i, n) for(int i=n-1;i>=0;--i) #define Rep(i, sta, n) for(int i=sta;i!=n;++i) #define rep1(i, n) for(int i=1;i<=n;++i) #define per1(i, n) for(int i=n;i>=1;--i) #define Rep1(i, sta, n) for(int i=sta;i<=n;++i) #define L k<<1 #define R k<<1|1 #define inf (0x3f3f3f3f) #define llinf (1e18) #define mid (tree[k].l+tree[k].r)>>1 #define ALL(A) A.begin(),A.end() #define SIZE(A) ((int)A.size()) #define PII pair<int,int> typedef long long i64; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--){ vector<int> arr(3); for(auto& v:arr) cin >> v; sort(arr.begin(),arr.end()); if(arr[2] >= arr[0] + arr[1]){ cout << arr[0] + arr[1] <<‘\n‘; continue; } int differ = arr[2] - arr[1]; int sum = differ; arr[2] -= differ; arr[0] -= differ; sum += arr[0] / 2 + arr[1]; cout << sum <<‘\n‘; } return 0; }
B. PIN Codes
#include<bits/stdc++.h> #define rep(i, n) for(int i=0;i!=n;++i) #define per(i, n) for(int i=n-1;i>=0;--i) #define Rep(i, sta, n) for(int i=sta;i!=n;++i) #define rep1(i, n) for(int i=1;i<=n;++i) #define per1(i, n) for(int i=n;i>=1;--i) #define Rep1(i, sta, n) for(int i=sta;i<=n;++i) #define L k<<1 #define R k<<1|1 #define inf (0x3f3f3f3f) #define llinf (1e18) #define mid (tree[k].l+tree[k].r)>>1 #define ALL(A) A.begin(),A.end() #define SIZE(A) ((int)A.size()) #define PII pair<int,int> typedef long long i64; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t,n; cin >> t; while(t--){ cin >> n; map<string,int> mp; vector<int> arr(11,0); vector<string> vs; string str; int index = 0; while(n--){ cin >> str; vs.push_back(str); if(!mp.count(str)) mp[str] = ++index;//hash ++arr[mp[str]]; } int sum = accumulate(arr.begin(),arr.end(),0) - index; cout << sum <<‘\n‘; set<string> s; for(auto it=mp.begin();it!=mp.end();++it) s.insert(it->first); for(auto v:vs){ string tmp = v; if(arr[mp[v]] > 1){ for(int i=0;i!=10;++i){ v[0] = ‘0‘ + i; if(!s.count(v)){ s.insert(v); cout << v <<‘\n‘; --arr[mp[tmp]]; break; } } } else cout << v <<‘\n‘; } } return 0; }
C. Everyone is a Winner!
#include<bits/stdc++.h> #define rep(i, n) for(int i=0;i!=n;++i) #define per(i, n) for(int i=n-1;i>=0;--i) #define Rep(i, sta, n) for(int i=sta;i!=n;++i) #define rep1(i, n) for(int i=1;i<=n;++i) #define per1(i, n) for(int i=n;i>=1;--i) #define Rep1(i, sta, n) for(int i=sta;i<=n;++i) #define L k<<1 #define R k<<1|1 #define inf (0x3f3f3f3f) #define llinf (1e18) #define mid (tree[k].l+tree[k].r)>>1 #define ALL(A) A.begin(),A.end() #define SIZE(A) ((int)A.size()) #define PII pair<int,int> typedef long long i64; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t,n; cin >> t; while(t--){ cin >> n; set<int> s; s.insert(0); for(int i=1;i<=sqrt(n);++i){ s.insert(n/i); s.insert(i); } cout << s.size() <<‘\n‘; for(auto v: s) cout << v <<" "; cout << ‘\n‘; } return 0; }
D. Secret Passwords
#include<bits/stdc++.h> #define rep(i, n) for(int i=0;i!=n;++i) #define per(i, n) for(int i=n-1;i>=0;--i) #define Rep(i, sta, n) for(int i=sta;i!=n;++i) #define rep1(i, n) for(int i=1;i<=n;++i) #define per1(i, n) for(int i=n;i>=1;--i) #define Rep1(i, sta, n) for(int i=sta;i<=n;++i) #define L k<<1 #define R k<<1|1 #define inf (0x3f3f3f3f) #define llinf (1e18) #define mid (tree[k].l+tree[k].r)>>1 #define ALL(A) A.begin(),A.end() #define SIZE(A) ((int)A.size()) #define PII pair<int,int> typedef long long i64; using namespace std; vector<int> pa(26); int find(int cur){ if(pa[cur] != cur) pa[cur] = find(pa[cur]); return pa[cur]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); vector<bool> arr(26,false); vector<string> vs; rep(i,26) pa[i] = i; int n; cin >> n; string str; while(n--){ cin >> str; sort(str.begin(),str.end()); str.erase(unique(ALL(str)),str.end()); vs.push_back(str); for(int i=0;i!=SIZE(str);++i) arr[str[i] - ‘a‘] = true; } for(auto s: vs){ int u = s[0] - ‘a‘; for(int i = 1;i!=SIZE(s);++i){ int pA = find(u); int pB = find(s[i] - ‘a‘); pa[pA] = pB; } } int sum = 0; for(int i=0;i!=26;++i){ if(find(i) == i && arr[i]) ++sum; } cout << sum <<‘\n‘; return 0; }
E. Editor
题解:假设 ( 值为1,)值为-1,因为要满足匹配,所以总和一定为0,可以用线段树解决,如果出现前缀和小于0的情况,一定是不满足的,在满足的情况下求最大嵌套层数就是求最大前缀和
#include<bits/stdc++.h> #define rep(i, n) for(int i=0;i!=n;++i) #define per(i, n) for(int i=n-1;i>=0;--i) #define Rep(i, sta, n) for(int i=sta;i!=n;++i) #define rep1(i, n) for(int i=1;i<=n;++i) #define per1(i, n) for(int i=n;i>=1;--i) #define Rep1(i, sta, n) for(int i=sta;i<=n;++i) #define L rt<<1 #define R rt<<1|1 #define inf (0x3f3f3f3f) #define llinf (1e18) #define ALL(A) A.begin(),A.end() #define SIZE(A) ((int)A.size()) #define PII pair<int,int> typedef long long i64; using namespace std; const int maxn = 1e6 + 32; int sum[maxn<<2],ma[maxn<<2],mi[maxn<<2]; void update(int rt,int l,int r,int pos,int value){ if(l == r){ sum[rt] = ma[rt] = mi[rt] = value; return; } int mid = (l + r) >> 1; if(pos <= mid) update(L,l,mid,pos,value); else update(R,mid+1,r,pos,value); sum[rt] = sum[L] + sum[R]; ma[rt] = max(ma[L],sum[L]+ma[R]); mi[rt] = min(mi[L],sum[L]+mi[R]); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,index = 1; cin >> n; string cmd; cin >> cmd; for(auto c: cmd){ if(c == ‘(‘) update(1,1,n,index,1); else if(c == ‘L‘) {if(index > 1) --index;} else if(c == ‘R‘) ++index; else if(c == ‘)‘) update(1,1,n,index,-1); else update(1,1,n,index,0); if(sum[1]==0&&mi[1]>=0) cout << ma[1] <<" "; else cout << -1 <<" "; } cout << ‘\n‘; return 0; }
F. Economic Difficulties
标签:bool password hid view des tree lap pen ++
原文地址:https://www.cnblogs.com/newstartCY/p/12070990.html