牛客周赛 Round 47
A
只需要枚举一下map即可。
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 #include <iostream> #include <map> using namespace std;int a[10 ];int main () { map<int ,int >mp; for (int i=1 ;i<=5 ;i++) { cin>>a[i]; mp[a[i]]++; } if (mp.size ()!=2 ) { cout<<"NO" <<"\n" ; } else { for (auto it:mp) { if (it.second==2 ||it.second==3 ) { cout<<"YES" <<"\n" ; return 0 ; } else { cout<<"NO" <<"\n" ; return 0 ; } } } return 0 ; }
B
注意这个题目有点诈骗的,因为一个字母也是可以的。
公共子串嘛,一个也是公共。
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 <bits/stdc++.h> using namespace std;using ll =long long ;const int N=1e5 ;int vis[27 ];inline void solve () { int n; cin >> n; vector<string>v (n+1 ); for (int i=1 ;i<=n;i++){ cin >> v[i]; map<char ,int >mp; for (auto i:v[i]){ if (!mp.count (i)) vis[i-'a' ]++,mp[i]++; } } for (int i=0 ;i<=25 ;i++){ if (vis[i]==n){ char ans='a' +i; cout << ans; break ; } } } int main () { ios::sync_with_stdio (0 );cin.tie (0 );cout.tie (0 ); int T = 1 ; while (T--) solve (); return 0 ; }
C
注意最大值需要参与进来讨论
如果最大值比所有都大,那么一定会剩下一个的了
如果是等于的话,如果有3种的话,是可以剩下东西的,如果是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 35 36 37 38 #include <bits/stdc++.h> using namespace std;#define ll long long #define li __int128 ll a[200005 ]; int main () { int n;cin>>n; ll sum=0 ; ll maxn=0 ; set<ll>st; for (int i=1 ;i<=n;i++){ cin>>a[i]; sum+=a[i]; maxn=max (a[i],maxn); } int kinds=0 ; for (int i=1 ;i<=n;i++){ if ((sum-a[i])%2 ==0 ||(sum-a[i])%2 ==1 &&a[i]>1 ) { kinds++; } } if (maxn>sum-maxn){ cout<<1 <<'\n' ; } else if (maxn==sum-maxn){ if (n>2 ){ cout<<1 <<'\n' ; } else { cout<<0 <<'\n' ; } } else { cout<<kinds; } return 0 ; }
D
打表找龟规律
每30个数字会有18个,且相对位置不变。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include <bits/stdc++.h> using namespace std;long long t,n;int a[20 ]={1 ,2 ,4 ,5 ,7 ,8 ,10 ,11 ,14 ,16 ,17 ,19 ,20 ,22 ,25 ,26 ,28 ,29 };int main () { cin>>t; while (t--){ cin>>n; n-=1 ; long long x=n%18 ; long long y=n/18 ; y=y*30 ; y+=a[x]; cout<<y<<endl; } }
E
横轴对称的+纵轴对称的-都对称的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include <bits/stdc++.h> using namespace std;typedef long long ll;const int p = 1e9 + 7 ;int n;ll binPow (ll a, int k) { ll ans = 1 ; while (k) { if (k & 1 ) ans = ans * a % p; a = a * a % p; k >>= 1 ; } return ans; } int main () { cin >> n; ll ans = binPow (4LL , n); ans = (ans + (binPow (4LL , n / 2 ) * binPow (2LL , n % 2 ) - binPow (2 , (n + 1 ) / 2 ) + p) % p) % p; cout << ans << '\n' ; return 0 ; }