最近又变怠惰了~~。努力找回状态吧。
A:签到题。
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<string,int> pii; const int N = 1e6+5; const int M = 2e5+5; const LL Mod = 1e9+7; #define rg register #define pi acos(-1) #define INF 1e9 #define CT0 cin.tie(0),cout.tie(0) #define IO ios::sync_with_stdio(false) #define dbg(ax) cout << "now this num is " << ax << endl; namespace FASTIO{ inline LL read(){ LL x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } void print(int x){ if(x < 0){x = -x;putchar('-');} if(x > 9) print(x/10); putchar(x%10+'0'); } } using namespace FASTIO; void FRE(){/*freopen("data1.in","r",stdin); freopen("data1.out","w",stdout);*/} int p[105]; int main() { int ca;ca = read(); while(ca--) { int n;n = read(); for(rg int i = 1;i <= n;++i) p[i] = read(); for(rg int i = n;i >= 1;--i) printf("%d%c",p[i],i == 1 ? ' ' : ' '); } // system("pause"); }
B:签到题。
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<string,int> pii; const int N = 1e5+5; const int M = 2e5+5; const LL Mod = 1e9+7; #define rg register #define pi acos(-1) #define INF 1e9 #define CT0 cin.tie(0),cout.tie(0) #define IO ios::sync_with_stdio(false) #define dbg(ax) cout << "now this num is " << ax << endl; namespace FASTIO{ inline LL read(){ LL x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } void print(int x){ if(x < 0){x = -x;putchar('-');} if(x > 9) print(x/10); putchar(x%10+'0'); } } using namespace FASTIO; void FRE(){/*freopen("data1.in","r",stdin); freopen("data1.out","w",stdout);*/} int a[N]; int main() { int ca;ca = read(); while(ca--) { int n;n = read(); LL sum = 0,ans = 0,dis = 0; for(rg int i = 1;i <= n;++i) a[i] = read(); for(rg int i = 1;i <= n;++i) { // printf("sum is %lld dis is %lld ",sum,dis); if(a[i] == 0) continue; if(a[i] < 0) { a[i] = -a[i]; if(sum >= a[i]) sum -= a[i]; else { a[i] -= sum,ans += a[i],sum = 0; dis += a[i]; } } else sum += a[i]; } sum -= min(sum,dis); ans += sum; printf("%lld ",ans); } // system("pause"); }
C:这题一开始一直觉得是构造。。
首先,我们考虑前k个位置,假设前k个位置都已经放置好了。
那么这里就是一个类似滑动窗口,对于下一个k的块,我们减去了a[1],加上了a[k+1]。
那么,如果要保持平衡,显然a[k+1] = a[1]。
那么我们继续移动,就可以发现,对于所有同余的位置,他们的值都应该是一样的。
所以就变成了去判断同余的位置是否都一样。
并且这里要统计0和1的个数是否超过了k/2.如果超过了就说明也不行。
这里的"?",我们可以不去管,因为如果满足另外两个条件,那么肯定存在一种摆法,满足条件。
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<string,int> pii; const int N = 1e5+5; const int M = 2e5+5; const LL Mod = 1e9+7; #define rg register #define pi acos(-1) #define INF 1e9 #define CT0 cin.tie(0),cout.tie(0) #define IO ios::sync_with_stdio(false) #define dbg(ax) cout << "now this num is " << ax << endl; namespace FASTIO{ inline LL read(){ LL x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } void print(int x){ if(x < 0){x = -x;putchar('-');} if(x > 9) print(x/10); putchar(x%10+'0'); } } using namespace FASTIO; void FRE(){/*freopen("data1.in","r",stdin); freopen("data1.out","w",stdout);*/} int main() { IO;CT0; int ca;cin >> ca; while(ca--) { int n,k;cin >> n >> k; string s;cin >> s; int len = s.size(); bool flag = false; int num[2] = {0}; for(rg int i = 0;i < k;++i) { int one = 0,zero = 0; for(rg int j = i;j < len;j += k) { if(s[j] == '?') continue; if(s[j] == '1') one++; else zero++; } if(zero != 0 && one != 0) flag = true; else if(zero != 0) num[0]++; else if(one != 0) num[1]++; } if(max(num[0],num[1]) > k/2) flag = true; if(flag) cout << "NO" << endl; else cout << "YES" << endl; } // system("pause"); }
D:博弈论。
其实就是几种情况的分类思考。
1:如果一开始两点之间的距离 <= da,那么alice可以一步直接到。
2:现在,先考虑图为一个无穷大的图。
如果db <= 2*da,那么alice肯定可以走到,因为只要不断保持在da的距离,bob肯定会走到头先。
否则,肯定走不到。
这里因为考虑的是无穷大的图,但是正常的图,肯定不是这样的。
如果当图限制起作用,就是da*2 >= 直径。
那么只要Alice站在直径中点,就可以走到其他任意的点。
然后就可以做了。。直径这里还是蛮妙的。
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<string,int> pii; const int N = 2e5+5; const int M = 2e5+5; const LL Mod = 1e9+7; #define rg register #define pi acos(-1) #define INF 1e9 #define CT0 cin.tie(0),cout.tie(0) #define IO ios::sync_with_stdio(false) #define dbg(ax) cout << "now this num is " << ax << endl; namespace FASTIO{ inline LL read(){ LL x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } void print(int x){ if(x < 0){x = -x;putchar('-');} if(x > 9) print(x/10); putchar(x%10+'0'); } } using namespace FASTIO; void FRE(){/*freopen("data1.in","r",stdin); freopen("data1.out","w",stdout);*/} vector<int> G[N]; int tot,mx,rt1,rt2,n,a,b,da,db; int dep[N],lg[N<<1],dfn[N<<1],st[N<<1][25],dis[N]; void dfs(int u,int fa) { dep[u] = dep[fa]+1; dfn[u] = ++tot; st[tot][0] = u; if(dep[u] > mx) mx = dep[u],rt1 = u; for(auto v : G[u]) { if(v == fa) continue; dfs(v,u); st[++tot][0] = u; } } int D_dis(int u,int fa) { dis[u] = dis[fa]+1; if(dis[u] > mx) mx = dis[u],rt2 = u; for(auto v : G[u]) if(v != fa) D_dis(v,u); } void Init() { lg[1] = 0;for(rg int i = 2;i <= tot;++i) lg[i] = lg[i>>1]+1; for(rg int j = 1;(1<<j) <= tot;++j) { for(rg int i = 1;i+(1<<j)-1 <= tot;++i) { if(dep[st[i][j-1]] <= dep[st[i+(1<<j-1)][j-1]]) st[i][j] = st[i][j-1]; else st[i][j] = st[i+(1<<j-1)][j-1]; } } } int LCA(int x,int y) { x = dfn[x],y = dfn[y]; if(x > y) swap(x,y); int k = lg[y-x+1]; if(dep[st[x][k]] < dep[st[y-(1<<k)+1][k]]) return st[x][k]; else return st[y-(1<<k)+1][k]; } int Dis(int u,int v) { return dep[u]+dep[v]-2*dep[LCA(u,v)]; } int main() { int ca;ca = read(); while(ca--) { tot = 0,mx = -1; n = read(),a = read(),b = read(),da = read(),db = read(); for(rg int i = 1;i <= n;++i) G[i].clear(); for(rg int i = 1;i < n;++i) { int u,v;u = read(),v = read(); G[u].push_back(v); G[v].push_back(u); } dep[0] = 0;dfs(1,0); Init(); mx = -1,dis[0] = 0;D_dis(rt1,0); int tdis = Dis(a,b); if(da >= tdis) printf("Alice "); else if(db <= 2*da) printf("Alice "); else { int D_len = Dis(rt1,rt2); if(2*da >= D_len) printf("Alice "); else printf("Bob "); } } // system("pause"); }