18广工新生赛
01:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int n; int main(){ int T; scanf("%d", &T); while(T--){ scanf("%d", &n); int f = 1, t; while(n--){ scanf("%d", &t); if(!t) f = 0; } if(f) puts("WeRide.ai"); else puts("Transform Mobility With Autonomous Driving"); } return 0; }
02:
由于每个数有50% += a 50% -= a所以 数的期望是不变的。
所以就求和的时候 就用前缀合就求和一下就好了。
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int a[N]; int main(){ int n, m, T; scanf("%d", &T); while(T--){ scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i] += a[i-1]; int op, l, r; while(m--){ scanf("%d%d%d", &op, &l, &r); if(op == 2){ printf("%d\n", a[r] - a[l-1]); } } } return 0; }
03:
如果是矩形的话,那么一定是在直径上,然后找到一个直径,然后就枚举可能存在的矩形,如果存在矩形,则弧长相等。
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 305; int a[N]; int n; int L = 0; inline int cal(int x, int y){ if(x > n) x -= n; if(y > n) y -= n; if(x > y) swap(x, y); return min(a[y]-a[x], a[x]+L-a[y]); } int main(){ while(~scanf("%d", &n)){ for(int i = 2; i <= n; ++i){ scanf("%d", &a[i]); a[i] += a[i-1]; } scanf("%d", &L); L += a[n]; int ans = 0; if(L&1) { printf("0\n"); continue; } for(int i = 1; i <= n; ++i){ for(int j = i+1; j <= n; ++j){ if(cal(i,j) != L/2) continue; for(int k = i+1; k < j; ++k){ for(int z = j+1; z < i+n; ++z){ int t1 = cal(i,k), t2 = cal(j,z); if(t1 == t2) ans++; else if(t1 < t2) break; } } } } cout << ans/2 << endl; } return 0; }
04:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; char s[N]; int main(){ int n, T; scanf("%d", &T); while(T--){ scanf("%d", &n); getchar(); int ans = 0, len; while(n--){ cin.getline(s, N); if(s[0] == 'i') ans += 4; else if(s[0] == 'b') ans += 1; else if(s[0] == 'l') ans += 8; else if(s[0] == 'd') ans += 8; else if(s[0] == 'c') ans += 1; else if(s[0] == 'f') ans += 4; } ans = (ans+1023) / 1024; printf("%d\n", ans); } return 0; }
05:
爆搜找规律。
爆搜代码:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 5e5 + 100; int sta[N]; int Max, gg; void dfs(int b, int l, int lt, int cnt){ if(lt == 0){ Max = max(Max, l); if(gg == l){ for(int i = 1; i < cnt; ++i) cout << sta[i] << ' '; cout << endl; } } for(int i = b; i <= lt; ++i){ sta[cnt] = i; dfs(i+1, l*i, lt-i, cnt+1); } } int main(){ int n; while(cin >> n){ gg = -1; Max = 0; dfs(1, 1, n, 1); gg = Max; dfs(1, 1, n, 1); } return 0; }
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; LL Min[N], Max[N]; vector<int> v; void init(){ v.pb(2); v.pb(3); for(int i = 6; i <= 200; ++i){ int t = v.size(); if(v[0] != 2 && v[t-1] == v[t-2]+1) ++v[t-1]; else if(v[0] != 2){ --v[t-1]; v.insert(v.begin(), 2); } else { int f = 1; for(int i = t-2; i >= 0; i--){ if(v[i]+1 != v[i+1]){ ++v[i]; f = 0; break; } } if(f) ++v[t-1]; } Min[i] = i-1; Max[i] = 1; for(int x : v){ Max[i] *= x; } } } vector<int> vc; int main(){ int T, n; scanf("%d", &T); init(); Min[1] = Max[1] = 1; Min[2] = Max[2] = 2; Min[3] = 2; Max[3] = 3; Min[4] = 3; Max[4] = 4; Min[5] = 4; Max[5] = 6; while(T--){ scanf("%d", &n); printf("%lld %lld\n", Min[n], Max[n]); } return 0; }
06:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int a[N]; int main(){ int T, n; scanf("%d", &T); while(T--){ scanf("%d", &n); int ans = 1; for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); int f = 1; for(int i = 2; i <= n; ++i){ if(a[i] == a[i-1]+1) ++f; else f = 1; ans = max(ans, f); } printf("%d\n", ans); } return 0; }
07:
由样例分析可得就是和墙围成半圆,这时候面积最大。
0的时候是无解
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; double pi = acos(-1); int main(){ int T; double n; scanf("%d", &T); while(T--){ scanf("%lf", &n); double ans = n*n/pi/2; if(abs(ans) < 1e-8) puts("Impossble"); else printf("%.8f\n", ans); } return 0; }
08:
题解:我们可以从样例分析中发现,我们可以经过4次跳跃之后返回到原来的这个地方。
也就是说,我们每次走到一个新的位置之后,我们可以遍历他的所有因子,再返回到这个位置,然后继续按原来的路径行事。
我们不用管他怎么走,只需要明白每出现一个数会对答案产生什么影响就好了。
最后 是 x -> -x 。
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int vis[N]; void init(){ for(int i = 2; i < N; ++i){ for(int j = i+i, t = 2; j < N; j+=i, t++){ vis[j] += t; } } } int main(){ init(); int n; while(~scanf("%d", &n)){ LL sum = 0; for(int i = 2; i <= n; ++i){ sum += vis[i]; } printf("%lld\n", sum*4+n-1); } return 0; }
09:
题目写的是会把数修改掉。
所以我们只需要从后往前做,每次遇到新的数的时候,都判断一下他会不会对答案产生影响。
如果产生影响的话,那么肯定就是 在他后面的修改 位置是在他后面的。
然后 平方和是 n*(n+1)*(n+2) / 6
这个地方会爆LL,除法不能先取模数,然后在做乘法。
模数也不是质数,所以不能求逆元。
可以用int128做,或者连续的3个数一定就有2的倍数或者3的倍数,所以也可以先除再做。
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = 123456789; const int N = 1e5 + 100; int T; int a[N]; LL cal(int x){ __int128 v = x; v = v * (v+1) * (v*2+1)/6; v %= mod; return v; } int main(){ scanf("%d", &T); while(T--){ int n, m; scanf("%d%d", &n, &m); LL ans = 0; for(int i = 1; i <= m; ++i) scanf("%d", &a[i]); int lat = n+1; for(int i = m; i >= 1; --i){ if(lat <= a[i]) continue; ans += cal(lat-a[i]); ans %= mod; lat = a[i]; } ans = (ans%mod)+mod; ans %= mod; printf("%lld\n", ans); } return 0; }
10:
直接模拟就好了。 不会map的可以去写一下。
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; char mp[N]; map<string, int> ms; string str, s; int main(){ int n; ios::sync_with_stdio(false); cin.tie(0); mp['A'] = mp['B'] = mp['C'] = '2'; mp['D'] = mp['E'] = mp['F'] = '3'; mp['G'] = mp['H'] = mp['I'] = '4'; mp['J'] = mp['K'] = mp['L'] = '5'; mp['M'] = mp['N'] = mp['O'] = '6'; mp['P'] = mp['R'] = mp['S'] = '7'; mp['T'] = mp['U'] = mp['V'] = '8'; mp['W'] = mp['X'] = mp['Y'] = '9'; while(cin >> n){ ms.clear(); for(int i = 1; i <= n; ++i){ cin >> str; s.clear(); for(int j = 0; j < str.size(); ++j){ if(isalpha(str[j])){ s.pb(mp[str[j]]); } else if(isdigit(str[j])) s.pb(str[j]); if(s.size() == 3) s.pb('-'); } ms[s]++; } int f = 0; //cout << "FFF" << endl; for(auto it = ms.begin(); it != ms.end(); ++it){ if(it->se > 1){ f = 1; cout << it->fi << " " << it->se << endl;; } } if(!f) puts("No duplicates."); } return 0; }
11:
题意:要有半数及以上的A或者B,然后求最大。
我们把每类人都算分开,然后排序。
然后肯定是把所以的11都放进去。
然后就是把 01 和 10 配对, 配对的时候肯定就是大的先放进去。
这样就会剩下m个01 或者是 m个10。
我们刚开始放进去k个11。
那么我们可以从剩下的01(10)和00当中选k个,需要每次都取大的。
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; vector<int> vc[4]; bool cmp(int x, int y){ return x > y; } int main(){ int n, op, v; while(~scanf("%d", &n)){ for(int i = 0; i < 4; ++i) vc[i].clear(); for(int i = 1; i <= n; ++i){ scanf("%d%d", &op, &v); if(op == 11) vc[0].pb(v); if(op == 10) vc[1].pb(v); if(op == 1) vc[2].pb(v); if(op == 0) vc[3].pb(v); } for(int i = 1; i < 3; ++i) sort(vc[i].begin(), vc[i].end(), cmp); int num = vc[0].size(); LL ans = 0; for(int i = 0; i < vc[0].size(); ++i) ans += vc[0][i]; int t1 = min(vc[1].size(), vc[2].size()); for(int i = 0; i < t1; ++i){ ans += vc[1][i] + vc[2][i]; } for(int i = t1; i < vc[1].size(); ++i) vc[3].pb(vc[1][i]); for(int i = t1; i < vc[2].size(); ++i) vc[3].pb(vc[2][i]); sort(vc[3].begin(), vc[3].end(), cmp); for(int i = 0; i < num && i < vc[3].size(); ++i){ ans += vc[3][i]; } printf("%lld\n", ans); } return 0; }
12:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; set<int> s; int main(){ int T; scanf("%d", &T); while(T--){ int b; scanf("%d", &b); for(int i = 1; i <= 1000; ++i){ int tmp = b/__gcd(b,i); s.insert(tmp); } cout << s.size() << endl; s.clear(); } return 0; }
13:
#include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); #define LL long long #define ULL unsigned LL #define fi first #define se second #define pb push_back #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int main(){ int T, n; scanf("%d", &T); for(int _cas = 1; _cas <= T; _cas++){ if(_cas>1) puts(""); scanf("%d", &n); while(n!=1){ if(n&1){ printf("%d*3+1=%d\n",n,n*3+1); n = n*3 +1; } else printf("%d/2=%d\n",n,n/2), n/=2; } } return 0; }