A. Chunga-Changa
#include <bits/stdc++.h> using namespace std; long long x, y, z; int main() { long long ans = 0, cnt = 0; scanf("%lld%lld%lld", &x, &y, &z); ans = (x + y) / z; long long p1 = x % z, p2 = y % z; if(z - p1 < z - p2) { if(p2 >= z - p1) cnt = z - p1; } else { if(p1 >= z - p2) cnt = z - p2; } printf("%lld %lld ", ans, cnt); return 0; }
B. Split a Number
By Golden_miner, contest: Codeforces Round #567 (Div. 2), problem: (B) Split a Number, Accepted, # #include <bits/stdc++.h> using namespace std; int N; string s, ans, temp; string add(string a, string b) { string c; int len1 = a.length(); int len2 = b.length(); int len = max(len1, len2); for(int i = len1; i < len; i ++) a = "0" + a; for(int i = len2; i < len; i ++) b= "0" + b; int ok = 0; for(int i = len - 1; i >= 0; i --) { char temp = a[i] + b[i] - '0' + ok; if(temp > '9') { ok = 1; temp -= 10; } else ok = 0; c = temp + c; } if(ok) c = "1" + c; return c; } string DelZero(string t) { string ans = ""; int temp = 0; for(int i = 0; t[i]; i ++) { if(t[i] != '0') { temp = i; break; } } ans = t.substr(temp, t.length() - temp); return ans; } string Sum(int x) { string num1 = s.substr(0, x); string num2 = s.substr(x, N - x); string ans = add(num1, num2); return ans; } bool Bigger(string &a, string &b) { if(a.length() > b.length()) return true; else if(a.length() < b.length()) return false; else { int len = a.length(); for(int i = 0; i < len; i ++) { if(a[i] == b[i]) continue; if(a[i] > b[i]) return true; return false; } } } int main() { scanf("%d", &N); cin >> s; ans = s; int pos = (N - 1) / 2, p = pos; int cnt = 0; while(p >= 0 && cnt <= 1) { if(s[p + 1] != '0') { temp = Sum(p + 1); if(Bigger(ans, temp)) ans = temp; cnt ++; } p --; } p = pos; cnt = 0; while(p < N - 1 && cnt <= 0) { if(s[p + 1] != '0') { temp = Sum(p + 1); if(Bigger(ans, temp)) ans = temp; cnt ++; } p ++; } for(int i = 0; i < ans.length();i ++) { printf("%c", ans[i]); } return 0; }
C. Flag
#include <bits/stdc++.h> using namespace std; char mp[1010][1010]; int dp[1010][1010]; int N, M; int main() { scanf("%d%d", &N, &M); for(int i = 1; i <= N; i ++) scanf("%s", mp[i] + 1); memset(dp, 0, sizeof(dp)); for(int i = N; i >= 1; i --) { for(int j = 1; j <= M; j ++) if(mp[i][j] == mp[i + 1][j]) dp[i][j] = dp[i + 1][j] + 1; else dp[i][j] = 1; } long long ans = 0; for(int i = 1; i <= N; i ++) { for(int j = 1, k = 0; j <= M; j ++) { int h = dp[i][j]; if(i + 3 * h - 1 <= N && mp[i][j] != mp[i + h][j] && dp[i + h][j] == h && mp[i + h][j] != mp[i + 2 * h][j] && dp[i + 2 * h][j] >= h) { if(k && mp[i][j] == mp[i][j - 1] && dp[i][j - 1] == h && mp[i + h][j] == mp[i + h][j - 1] && dp[i + h][j - 1] == h && mp[i + 2 * h][j] == mp[i + 2 * h][j - 1] && dp[i + 2 * h][j - 1] >= h) ++ k; else k = 1; } else k = 0; ans += k; } } printf("%lld ", ans); return 0; }
D. Irrigation
#include <bits/stdc++.h> using namespace std; #define MAX 500010 #define LL long long #define MOD 1000000007 struct node{ int id; LL q; }; bool cmp(node a,node b){ return a.q<b.q; } node rr[MAX]; int ans[MAX]; int s[MAX*5]; int a[MAX]; vector<int> e[MAX]; void update(int l,int r,int tt,int k){ if(l==r){ s[tt]++; return ; } int mid=(l+r)/2; if(mid<k) update(mid+1,r,tt*2+1,k); else update(l,mid,tt*2,k); s[tt]=s[tt*2]+s[tt*2+1]; } int query(int l,int r,int tt,int k){ if(l==r) return l; int mid=(l+r)/2; if(s[tt*2]<k) return query(mid+1,r,tt*2+1,k-s[tt*2]); else return query(l,mid,tt*2,k); } int main(){ int n,m,q,x; scanf("%d%d%d",&n,&m,&q); for(int i=1;i<=n;i++){ scanf("%d",&x); a[x]++; } LL st=n+1; int sz=0; for(int i=1;i<=m;i++){ e[a[i]].push_back(i); st=min((LL)a[i],st); } sz=e[st].size(); for(int i=0;i<e[st].size();i++){ update(1,m,1,e[st][i]); } LL y,pre=n; for(int i=1;i<=q;i++){ scanf("%lld",&y); rr[i].id=i; rr[i].q=y; } sort(rr+1,rr+1+q,cmp); for(int i=1;i<=q;i++){ LL y=rr[i].q-pre; if(st>n){ ans[rr[i].id]=(y-1)%m+1; } else{ while(y>sz&&st<=n){ y-=sz; pre+=sz; st++; sz+=e[st].size(); for(int j=0;j<e[st].size();j++){ update(1,m,1,e[st][j]); } } if(st>n){ ans[rr[i].id]=(y-1)%m+1; } else ans[rr[i].id]=query(1,m,1,y); } } printf(" "); for(int i=1;i<=q;i++) printf("%d ",ans[i]); return 0; }
一万年更新一次 最近的活终于要做完了 开开心心
十一会有大把的时间可以刷题 8