牛客小白月赛26 B、G、J
三大水题一起写,方便基础不好的同学学习(好像并没有)
B. 牛牛爱数学
Solution
发现这个式子是个完全平方公式,所以有
所以答案就是
不整除的话就是-1
#include<bits/stdc++.h>
typedef long long ll;
const int N = 1e6 + 5;
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
cin >> t;
while(t--) {
ll a, b, c;
cin >> a >> b >> c;
ll p = b * c;
if(p % a != 0) cout << -1 << "\n";
else cout << p / a << "\n";
}
return 0;
} G 牛牛爱几何
Solution
画个图你就懂了
黑色部分为一个半圆减去一个三角形,算八个就行。
#include<bits/stdc++.h>
typedef long long ll;
const int N = 1e6 + 5;
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
ll n;
while(cin >> n) {
double pi = acos(-1.0);
double r = n / 2.0;
cout << fixed << setprecision(6) << pi * r * r - (n * n - r * r * pi) << "\n";
}
return 0;
} J.牛牛喜欢字符串
Solution
对于整个字符串一共会被分成 段,那么对于每一个位置
计算字符出现频率最高的
然后每个位需要 次变换。
#include<bits/stdc++.h>
typedef long long ll;
const int N = 1e6 + 5;
using namespace std;
int sum[N][26];
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int n, k;
string s;
cin >> n >> k >> s;
for(int i = 0; i < s.size(); i++) {
sum[i % k][s[i] - 'a']++;
}
int num = n / k;
ll ans = 0;
for(int i = 0; i < k; i++) {
int maxz= 0;
for(int j = 0; j < 26; j++) {
maxz = max(maxz, sum[i][j]);
}
ans += num - maxz;
}
cout << ans << "\n";
return 0;
}
查看25道真题和解析