“蔚来杯“2022牛客暑期多校训练营5 补题(B、C、H、K)

“蔚来杯“2022牛客暑期多校训练营5


菜狗来继续学算法了
多校以来写出题最多的一场,虽然这场因为水题太多被喷了

B Watches

#include<bits/stdc++.h>

using namespace std;

#define int long long 

const int N = 1e5 + 10;

int a[N], b[N];
int k, n, m;

bool check(int x){
	memset(b, 0, sizeof b);
	
	for(int i = 1; i <= n; i ++ ){
		b[i] = a[i] + x * i;
	}
	
	sort(b + 1, b + n + 1);  //排序 
	
	int res = 0;
	for(int i = 1; i <= x; i ++ ){
		res += b[i];
	}
	
	if(res <= m) return true;
	return false;
}

signed main()
{
	while(scanf("%lld%lld", &n, &m) != EOF){
		bool flag = 0;  //标记一只表都买不起
		for(int i = 1; i <= n; i ++ ){
			cin>>a[i];
			if(!flag && a[i] + i <= m) flag = true; 
		}
		
		if(!flag){  //如果一只表都买不起 
			puts("0");
			continue;
		}
		
		int l = 1, r = n;  //从买一个表开始枚举 
		while(l < r){
			int mid = (l + r + 1) >> 1;
			if(check(mid)) l = mid;
			else r = mid - 1;
		}
		printf("%lld\n", r);
	}
	return 0;
}

C Bit Transmission

#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int a[N];  //储存字符串
int n;
int res;  //记录机器人报错的次数
int ci[N][2];  //n个位置0/1出现的次数
 
int main()
{
	while(scanf("%d", &n) != EOF){
	
		memset(a, 0, sizeof a);  //初始化所有数为7 
		res = 0;  //重置机器报错次数
		memset(ci, 0, sizeof ci);  //清空记录状态 
		
		for(int i = 0; i < n * 3; i ++ ){  //询问 
			int b;
			char str[5];
			
			scanf("%d", &b);
			scanf("%s", str);
			
			if(str[0] == 'Y'){
				ci[b][1] ++ ;  //记录这个位置1出现的次数 
			}
			else if(str[0] == 'N'){
				ci[b][0] ++ ;  //记录这个位置0出现的次数 
			}
		}
		
		for(int i = 0; i < n; i ++ ){  //遍历字符的每一位 
			if(ci[i][0] > 0 && ci[i][1] > 0){  //出现冲突情况 
				res ++ ;
				if(ci[i][0] > ci[i][1]){
					a[i] = 0;
				}
				else if(ci[i][0] < ci[i][1]){
					a[i] = 1;
				}
			}
			else if(ci[i][0] == 0 && ci[i][1] == 0){
				a[i] = 0;
			}
			else if(ci[i][0] > 0){
				a[i] = 0;
			}
			else if(ci[i][1] > 0){
				a[i] = 1;
			}
		}
		 
		if(res > 1){
			puts("-1");
		}
		else{
			for(int i = 0; i < n; i ++ ){
				cout<<a[i];
			}
			cout<<endl;
		}
	}
	return 0;
} 

H Cutting Papers

比赛时写出来的,推公式

#include<bits/stdc++.h>
#define pi acos(-1)

using namespace std;

int main()
{
 double n;
 while(~scanf("%lf",&n)){
  double ans=(0.5+pi/8)*n*n;
  printf("%.9lf\n",ans);
 }
 return 0;
 } 

K Headphones

#include<bits/stdc++.h>
using namespace std;
 int n,k;
int main()
{
    while(scanf("%d%d", &n, &k) != EOF)
    {
        if(n-k>=k+1)
        cout<<n+1<<"\n";//n-k + k+1
       else cout<<"-1"<<"\n";
    }
       return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值