可惜了这场差点上大分。
A: 水题
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> pii; const int N = 1e3 + 5; const int M = 2e4 + 5; const double eps = 1e-6; const LL Mod = 1e9 + 7; #define pi acos(-1) #define INF 1e18 #define dbg(ax) cout << "now this num is " << ax << endl; inline long long ADD(long long x,long long y) {return (x + y) % Mod;} inline long long DEC(long long x,long long y) {return (x - y + Mod) % Mod;} inline long long MUL(long long x,long long y) {return x * y % Mod;} void solve() { string s;cin >> s; int pos = 0; for(int i = 0;i < s.size();++i) { if(s[i] < s[pos]) pos = i; } string ans = ""; for(int i = 0;i < s.size();++i) if(i != pos) ans += s[i]; cout << s[pos] << " " << ans << endl; } int main() { int ca;scanf("%d",&ca); while(ca--) { solve(); } // system("pause"); return 0; }
B:可以发现最终一定会陷入循环中,且因为和次数有关,循环的长度肯定<=n。
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> pii; const int N = 2e3 + 5; const int M = 2e4 + 5; const double eps = 1e-6; const LL Mod = 1e9 + 7; #define pi acos(-1) #define INF 1e18 #define dbg(ax) cout << "now this num is " << ax << endl; inline long long ADD(long long x,long long y) {return (x + y) % Mod;} inline long long DEC(long long x,long long y) {return (x - y + Mod) % Mod;} inline long long MUL(long long x,long long y) {return x * y % Mod;} int a[N]; int b[N][N],cnt[N]; void solve() { int n;scanf("%d",&n); for(int i = 1;i <= n;++i) scanf("%d",&a[i]),b[0][i] = a[i]; for(int j = 1;j <= n;++j) { memset(cnt,0,sizeof(cnt)); for(int i = 1;i <= n;++i) cnt[b[j - 1][i]]++; for(int i = 1;i <= n;++i) b[j][i] = cnt[b[j - 1][i]]; } int q;scanf("%d",&q); while(q--) { int x,k;scanf("%d %d",&x,&k); k = min(k,n); printf("%d ",b[k][x]); } } int main() { int ca;scanf("%d",&ca); while(ca--) { solve(); } //system("pause"); return 0; }
C:可以发现,如果我们个数不够其实是可以操作0来凑的,但是如果要操作1,那么就一定要拿这位全是1的来。
所以说只有当所有的位的1的个数 % k == 0时,才能操作出来。
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> pii; const int N = 2e5 + 5; const int M = 2e4 + 5; const double eps = 1e-6; const LL Mod = 1e9 + 7; #define pi acos(-1) #define INF 1e18 #define dbg(ax) cout << "now this num is " << ax << endl; inline long long ADD(long long x,long long y) {return (x + y) % Mod;} inline long long DEC(long long x,long long y) {return (x - y + Mod) % Mod;} inline long long MUL(long long x,long long y) {return x * y % Mod;} int a[N]; vector<int> ans; int bit[30]; void solve() { memset(bit,0,sizeof(bit)); int n;scanf("%d",&n); for(int i = 1;i <= n;++i) { scanf("%d",&a[i]); for(int j = 0;j < 30;++j) { int g = (a[i] >> j) & 1; bit[j] += g; } } ans.clear(); ans.push_back(1); for(int k = 2;k <= n;++k) { int f = 0; for(int j = 0;j < 30;++j) { if(bit[j] % k != 0) f = 1; } if(f == 0) ans.push_back(k); } for(auto v : ans) printf("%d ",v); printf(" "); } int main() { int ca;scanf("%d",&ca); while(ca--) { solve(); } //system("pause"); return 0; }
D:赛时想的差不多了,但是bug一直没找出来。
一开始的思路确实有点漏洞,一直考虑了线性的一个序列,但是它走的方式其实可以是上下上下来回跳的。
所以就不线性考虑了。首先有个很显然的结论,dp[i]的值肯定是第一次跳到的最小。
基于这个思路,考虑对bfs,然后线段树上维护跳到i的最小dp数就行,因为每个只会被操作一次,所以是nlogn的复杂度。
// Author: levil #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> pii; const int N = 3e5 + 5; const int M = 2e4 + 5; const double eps = 1e-6; const LL Mod = 1e9 + 7; #define pi acos(-1) #define INF 0x3f3f3f #define dbg(ax) cout << "now this num is " << ax << endl; inline long long ADD(long long x,long long y) {return (x + y) % Mod;} inline long long DEC(long long x,long long y) {return (x - y + Mod) % Mod;} inline long long MUL(long long x,long long y) {return x * y % Mod;} int a[N],b[N],n; pii pre[N]; LL dp[N]; queue<int> Q; vector<int> vec; struct Node{int L,r,f;}node[N << 2]; void Pushup(int idx) {node[idx].f = node[idx << 1].f & node[idx << 1 | 1].f;} void build(int L,int r,int idx) { node[idx].L = L,node[idx].r = r; if(L == r) { if(L == n) node[idx].f = 1; else node[idx].f = 0; return ; } int mid = (L + r) >> 1; build(L,mid,idx << 1); build(mid + 1,r,idx << 1 | 1); Pushup(idx); } void update(int L,int r,int id,int idx) { if(node[idx].L >= L && node[idx].r <= r && node[idx].f) return ; if(node[idx].L == node[idx].r) { node[idx].f = 1; int ed = node[idx].L + b[node[idx].L]; if(dp[ed] == 0 && ed != n) { Q.push(ed); dp[ed] = dp[id] + 1; pre[ed].first = id; pre[ed].second = node[idx].L; } return ; } int mid = (node[idx].L + node[idx].r) >> 1; if(mid >= L) update(L,r,id,idx << 1); if(mid < r) update(L,r,id,idx << 1 | 1); Pushup(idx); } bool vis[N]; int BFS() { Q.push(n); dp[n] = 0; while(!Q.empty()) { int u = Q.front(); Q.pop(); if(u - a[u] <= 0) return u; update(u - a[u],u,u,1); } return -1; } void solve() { scanf("%d",&n); for(int i = 1;i <= n;++i) scanf("%d",&a[i]); for(int i = 1;i <= n;++i) scanf("%d",&b[i]); build(1,n,1); int ans = BFS(); if(ans == -1) printf("-1 "); else { printf("%lld ",dp[ans] + 1); vec.push_back(0); while(ans != n) { vec.push_back(pre[ans].second); ans = pre[ans].first; } reverse(vec.begin(),vec.end()); for(auto v : vec) printf("%d ",v); } } int main() { //int ca;scanf("%d",&ca); //while(ca--) { solve(); //} //system("pause"); return 0; } /* 5 0 0 1 4 2 0 2 0 1 0 */