牛客多校第五场个人补题 B K H C G
B
题意
思路
一眼二分,签到题,每次把二分的结果check的时候重新给每个手表赋一下值,然后排序选前k个
代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
int a[N];
int n,m;
bool check(int k) {
vector<int>v;
for(int i=1;i<=n;i++) v.push_back(a[i]+i*k);
sort(v.begin(),v.end());
int res=0;
for(int i=0;i<k;i++) res+=v[i];
if(res<=m) return 1;
return 0;
}
void solve() {
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
int l=0,r=n;
while(l<r) {
int mid=(l+r+1)>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
}
signed main() {
IOS;
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
}
K
题意
思路
之前题意一直没搞明白wa了三发,后来才发现就是一个抽屉原理,比较签到,就是假设最坏情况然后取n-m+m+1个就可以了
代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
signed main() {
IOS;
int t = 1;
// cin >> t;
int n,m;
while(cin>>n>>m) {
if(n>m*2) {
cout<<(m+1)*2<<endl;
}
else cout<<-1<<endl;
}
}
H
题意
求|x|+|y|+|x+y| ⩽ \leqslant ⩽n和圆心在原点半径为 n 2 \frac{n}{2} 2n的圆所围面积
思路
题目不难,但是样例看了半天没看懂。后来瞎搞推出个不知道是求啥的公式过了,结果没过多久说是出题人把标程写错了。。。第一次理解的题意是对的。又交了一次最开始推的公式过了(另外多组输入属实是无语,第一次交的时候只有一组输入也能过,那不知道写个多组是干啥)。
代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
const double pi=3.141592653589793;
void solve() {
double n;
cin>>n;
double r=n/2;
cout<<fixed<<setprecision(10)<<3*r*r+pi*r*r/2-r*r<<endl;
}
signed main() {
IOS;
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
}
C
题意
思路
就是一个纯模拟的过程,用两个数组去记录0,1,然后判断是否合法就可以了,吐槽一下,题面已经保证最多错一次,为啥还会错多次???
代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MT0
#define FI
#define rep(v,s,e) for(int v = s;v < e,v++)
void solve(int);
signed main() {
#ifdef FI
cin.sync_with_stdio(0);
cin.tie(0);
#endif
int T = 1;
#ifdef MT
cin >> T;
#endif
int n;
while (cin >> n) {
solve(n);
}
return 0;
}
int cnt1[100010], cnt2[100010];
void solve(int n) {
for (int i = 0; i < n; i++) {
cnt1[i] = cnt2[i] = 0;
}
for (int i = 0; i < 3 * n; i++) {
int x;
cin >> x;
string s;
cin >> s;
if (s == "YES") {
cnt1[x]++;
} else {
cnt2[x]++;
}
}
for (int i = 0; i < n; i++) {
if (cnt1[i] == 0 && cnt2[i] == 0) {
cout << -1 << "\n";
return;
}
if (cnt1[i] > 1 && cnt2[i] > 1) {
cout << -1 << "\n";
return;
}
// if (cnt1[i] != 0 && cnt2[i] > 1) {
// cout << -1 << "\n";
// return;
// }
// if (cnt1[i] > 1 && cnt2[i] != 0) {
// cout << -1 << "\n";
// return;
// }
}
int f = 0;
for (int i = 0; i < n; i++) {
if (cnt1[i] != 0 && cnt2[i] != 0) {
f++;
}
}
if (f > 1) {
cout << -1 << "\n";
return;
} else if (f == 1) {
string ans;
for (int i = 0; i < n; i++) {
if (cnt1[i] && cnt2[i]) {
if(cnt1[i]==1||cnt2[i]==1) {
if (cnt1[i] != 1) {
ans += '1';
} else {
ans += '0';
}
}
else {
cout<<"-1\n";
return;
}
} else {
if (cnt1[i]) {
ans += '1';
} else {
ans += '0';
}
}
}
cout << ans << "\n";
return;
} else if (f == 0) {
string ans;
for (int i = 0; i < n; i++) {
if (cnt1[i]) {
ans += '1';
if (cnt1[i] == 1) {
cout << -1 << "\n";
return;
}
} else {
ans += '0';
if (cnt2[i] == 1) {
cout << -1 << "\n";
return;
}
}
}
cout << ans << "\n";
}
}
G
题意
思路
比赛时候看到很多人过以为是个签到,结果一看马拉车,一时间没啥思路,又回去看其他题了,后来找了个马拉车的板子改了改就过了,好像雀食挺板子的。
代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
typedef pair<int, int> PII;
int n;
int dp[N];
char str[N];
string S;
int ans[N];
int idx = 0;
void Manacher() {
int len = n;
str[0] = '#'; //防止越界
for (int i = 1; i <= len; i++) {
str[++idx] = '#';
str[++idx] = S[i];
}
str[++idx] = '#', str[++idx] = '@'; //最后再加一个@
int right = 0, pos = -3;
for (int i = 1; i <= idx; i++) {
if (i < right)
dp[i] = min(dp[2 * pos - i], right - i);
else
dp[right = i] = 1;
while (str[i - dp[i]] == str[i + dp[i]])
dp[i]++;
if (i + dp[i] > right)
right = i + dp[i], pos = i;
}
}
int res[N];
void solve() {
memset(ans,0,sizeof ans);
S = ' ' + S;
Manacher();
for (int i = 2; i <= idx; i++) {
ans[i / 2 - dp[i] / 2 + 1]++;
ans[i / 2 + 1]--;
}
int ans1=0;
for(int i=1;i<=n;i++)
{
ans1+=ans[i];
res[i]=ans1;
}
int x1=0,x2=0,x3=0;
for(int i=1;i<=n;i++) {
if(S[i]=='k')x1+=res[i];
if(S[i]=='f')x2+=res[i];
if(S[i]=='c')x3+=res[i];
}
cout<<x1<<' '<<x2<<' '<<x3<<endl;
}
signed main() {
IOS;
while(cin>>n>>S) {
solve();
}
}