牛客周赛 Round 45
A
直接模拟
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <bits/stdc++.h> using namespace std;void solve () { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; if (a + b + c + d + e > 100 ) cout << "YES" ; else cout << "NO" ; } int main () { ios::sync_with_stdio (0 );cin.tie (0 ); int T = 1 ; while (T -- ) solve (); return 0 ; }
B
经过大概的模拟发现只有当行数是奇数并且列数是偶数的时候不可以。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <bits/stdc++.h> using namespace std;void solve () { int n, m; cin >> n >> m; if (n % 2 == 1 && m % 2 == 0 ) cout << "NO" ; else cout << "YES" ; } int main () { ios::sync_with_stdio (0 );cin.tie (0 ); int T = 1 ; while (T -- ) solve (); return 0 ; }
C
这个是有一个从前到后的性质可以捕捉的。
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 #include "iostream" using namespace std;int book[100010 ];int check (int x) { int k=x,sum=0 ; while (k) { sum+=k%10 ; k=k/10 ; } if (sum%2 ==0 &&book[sum]==1 ) { book[x]=1 ; return 1 ; } else return 0 ; } int main () { int n,cnt=0 ; cin>>n; for (int i=1 ;i<10 ;i++) { if (i%2 ==0 ) book[i]=1 ; } for (int i=1 ;i<=n;i++) { if (check (i)==1 ) { cnt++; } } cout<<cnt; return 0 ; }
D
直接使用双指针进行移动
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 #include <bits/stdc++.h> using namespace std;using i64 = long long ;void solve () { int n, k; cin>>n>>k; vector<int > a (n+1 ) ; for (int i=1 ; i<=n; ++i) cin>>a[i]; i64 ans = 0 ; int l = 0 ; map<int , int > mp; for (int i=1 ; i<=n; ++i) { if (mp.count (a[i])) { if (i-mp[a[i]] > k) { l = max (l, mp[a[i]]); } } mp[a[i]] = i; ans += i-l; } cout<<ans<<"\n" ; } signed main (void ) { ios::sync_with_stdio (false ); cin.tie (nullptr ); int t=1 ; while (t--) solve (); return 0 ; }
E
先记录节点为1的点然后开始遍历找到节点为2的点
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 #include <bits/stdc++.h> using namespace std;const int N = 100010 ;int n;int f[N]; int d[N]; int alls[N];int main () { cin >> n; vector<vector<int >>p (n+1 ); for (int i=1 ;i<=n-1 ;i++){ int u,v; cin >> u >> v; p[u].push_back (v),f[u]++; p[v].push_back (u),f[v]++; } for (int i=1 ;i<=n;i++) { d[i]=0 ; for (int j=0 ;j<p[i].size ();j++) { int t = p[i][j]; d[i]+=f[t]; } } int res = 0 ; for (int i=1 ;i<=n;i++) if (d[i]>=n-1 ) res++; cout << res <<endl; return 0 ; }
F
用总的三元组的数量减去一类如下:
image-20240702120504067
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 #include <iostream> #include <vector> #include <cstring> #include <string> #include <algorithm> using namespace std;int rnd (long long seed) { long long ret = seed; seed = (seed * 7 + 13 ) % 1000000007 ; return ret % 2 ; } int in[5005 ]; int main () { long long n,seed; cin>>n>>seed; long long ans = 0 ; for (int i=1 ;i<n;i++){ for (int j=i+1 ;j<=n;j++){ long long ret = seed; seed = (seed * 7 + 13 ) % 1000000007 ; if (ret & 1 ){ in[i]++; }else { in[j]++; } } } ans = n*(n-1 )*(n-2 )/6 ; for (int i=1 ;i<=n;i++){ if (in[i]>=2 ){ ans-= in[i]*(in[i]-1 )/2 ; } } cout<<ans; }