img
西安理工大学2024年程序设计校赛(校外同步赛)
A
img
1 2 3 4 5 6 7 8 9 10 11 12 13 #include <bits/stdc++.h> using namespace std; signed main () { char c; cin >> c; if (c == 'A' || c == 'B' || c == 'C' ) cout << "YES" << endl; else cout << "NO" << endl; return 0 ; }
B
img
牛马()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #include <bits/stdc++.h> using namespace std; signed main () { string a = "" , b = "" , c = "" ; string s; getline (cin,a); getline (cin,b); getline (cin,c); if (a == "Vertebrates" ){ if (b == "Bird" ){ if (c == "Haunted Den" ){ cout << "Pigeons" << endl; } else { cout << "Eagle" << endl; } } else { if (c == "Haunted Den" ){ cout << "People" << endl; } else { cout << "Cow" << endl; } } } else { if (b == "Insect" ){ if (c == "Herbivorous" ){ cout << "Caterpillar" << endl; } else { cout << "Fleas" << endl; } } else { if (c == "Haunted Den" ){ cout << "Worms" << endl; } else { cout << "Leeches" << endl; } } } return 0 ; }
C
img
结论题目(我才不写高精度)
给左边式子*2,然后均值不等式
左边大于或等于右边
等于当且仅当三者相等
image-20240320200757189
1 2 3 4 5 6 7 8 9 10 #include <bits/stdc++.h> using namespace std; int main () { string x,y,z; cin>>x>>y>>z; if (x==z&&x==y) cout<<"=" ; else cout<<">" ; return 0 ; }
D
img
后手直接走对角线
然后直接算最多能走多少个对角线
然后如果还能继续走
那就后手输了
否则后手赢了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include <bits/stdc++.h> using namespace std; int main () { long long int t,d,k,i,ans,p; cin >> t; for (i=0 ;i<t;i++) { cin >> d >> k; ans=d/(k*sqrt (2 )); long double x=ans*k,y=x; if ((x+k)*(x+k)+y*y<=d*d) { cout<<"Parry" <<endl; } else cout<<"Mercedes" <<endl; } return 0 ; }
E
img
大概看看就行(反正也是粘贴的)掌握一下大概
暴力枚举3个点
然后计算面积(如果面积为0就退出,然后计算圆的半径)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 #include "bits/stdc++.h" double solve (int x0, int y0, int x1, int y1, int x2, int y2) { x1 -= x0; y1 -= y0; x2 -= x0; y2 -= y0; int S = std::abs (x1 * y2 - x2 * y1); if (S == 0 ) return 0. ; double a[3 ] = {std::sqrt (x1 * x1 + y1 * y1), std::sqrt (x2 * x2 + y2 * y2), std::sqrt ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))}; std::sort (a, a + 3 ); double cos1 = (a[0 ] * a[0 ] + a[2 ] * a[2 ] - a[1 ] * a[1 ]) / (2 * a[0 ] * a[2 ]); double cos2 = (a[1 ] * a[1 ] + a[2 ] * a[2 ] - a[0 ] * a[0 ]) / (2 * a[1 ] * a[2 ]); double fenmu = std::sqrt ((1 + cos1) / (1 - cos1)) + std::sqrt ((1 + cos2) / (1 - cos2)) + 2 ; double ans = a[2 ] / fenmu; if (std::isinf (ans)) return 0. ; return ans; } int main () { std::ios::sync_with_stdio (0 ); std::cin.tie (0 ); int n; std::cin >> n; std::vector<std::pair<int ,int > > a (n); for (int i = 0 ; i < n; i ++) { std::cin >> a[i].first >> a[i].second; } double ans = 0. ; for (int i = 0 ; i < n; i ++) { for (int j = i + 1 ; j < n; j ++) { for (int k = j + 1 ; k < n; k ++) { ans = std::max (ans, solve (a[i].first, a[i].second, a[j].first, a[j].second, a[k].first, a[k].second) ); } } } std::cout << std::fixed << std::setprecision (6 ); std::cout << ans << "\n" ; return 0 ; }
F
img
树状数组太适合了阿喂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 #include <bits/stdc++.h> using namespace std;int sum[1000005 ];int lowbit (int x) { return x & -x; } void add (int x, int k) { while (x <= 1000000 ) { sum[x] += k; x += lowbit (x); } } int query (int x) { int res = 0 ; while (x) { res += sum[x]; x -= lowbit (x); } return res; } int a[200005 ];int main () { ios::sync_with_stdio (0 ); cin.tie (0 ); cout.tie (0 ); int n, q, m; cin >> n >> q >> m; long long ans = 0 ; for (int i = 1 ; i <= n ; i++) { cin >> a[i]; add (a[i], 1 ); ans += query (m / a[i]); } while (q--) { int op; cin >> op; if (op == 1 ) { int pos, k; cin >> pos >> k; ans -= query (m / a[pos]); add (a[pos], -1 ); a[pos] = k; add (a[pos], 1 ); ans += query (m / a[pos]); } else { cout << ans << "\n" ; } } return 0 ; }
G
img
直接dfs
注意是从高位向低位dfs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; long long m,n;void dfs (long long x) { int y = x % 10 ; if (x > 10 ) m++; if (y - 2 >= 0 && (x * 10 + y - 2 ) <= n) dfs (x * 10 + y - 2 ); if (y + 2 <= 9 && (x * 10 + y + 2 ) <= n) dfs (x * 10 + y + 2 ); } void solve () { cin >> n; for (int i = 1 ;i < 10 ;i++) dfs (i); cout << m << '\n' ; } int main () { ios::sync_with_stdio (false ); cin.tie (0 ); int t = 1 ; while (t--) solve (); return 0 ; }
I
img
显然确实如此()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include <bits/stdc++.h> using namespace std;#define ll long long int main () { int t; cin>>t; while (t--){ int n; cin>>n; ll sum=0 ,flag=0 ; for (int i=0 ;i<n;i++){ ll x; cin>>x; if (x%2 ==1 )flag=1 ; } if (flag){ cout<<"halo" <<endl; } else { cout<<"parry" <<endl; } } return 0 ; }
H
img
直接二分那个值
然后算出最大的需要增加的
看看会不会增加到0就可以了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 #include <bits/stdc++.h> using namespace std;int n,x[100005 ],y[100005 ];bool check (int mid) { int l=1e9 ,r=-1e9 ,maxx=0 ; for (int i=1 ;i<=n;i++) { if (y[i]<mid) { maxx=max (maxx,mid-y[i]); l=min (l,x[i]); r=max (r,x[i]); } } for (int i=1 ;i<=n;i++) { if (x[i]>=l&&x[i]<=r) { if (y[i]+maxx>0 ) { return false ; } } } return true ; } signed main () { ios::sync_with_stdio (0 ); cin.tie (0 ); cout.tie (0 ); cin>>n; for (int i=1 ;i<=n;i++) { cin>>x[i]>>y[i]; } int l=-1e9 ,r=0 ; while (l<r) { int mid=l+r+1 >>1 ; if (check (mid)) { l=mid; } else { r=mid-1 ; } } cout<<l; return 0 ; }
L
img
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include <bits/stdc++.h> using namespace std;vector<char >ch; int main () { ios::sync_with_stdio (0 ); int n,m,cnt = 1 ; cin>> n>>m; string s; cin >> s; while (m--) { int op;cin >>op; if (op == 1 ) cnt++; else if (op == 2 ){ int p ; char c; cin >> p >> c; if ((p == 1 && cnt %2 ==1 ) || (p==2 && cnt % 2 ==0 ) ) s.insert (s.begin (),c); else if ((p == 2 && cnt %2 ==1 ) || (p == 1 && cnt %2 ==0 )) s.push_back (c); } } if (cnt %2 ==0 ){ for (int i = s.size ()-1 ;i>=0 ;i--)cout << s[i]; } else cout << s; return 0 ; }
img