2024牛客3

B.Crash Test

题意:
给定 n n n种操作,将 x x x更新为 ∣ x − a i ∣ |x-a_i| xai.
求可以得到的最小值。

题解:
求所有操作的gcd,然后两种可能性,撞上和没撞上,取最小值。

代码:

#include <bits/stdc++.h>
#define int long long
using ll = long long;
using PII = std::array<int, 2>;
using namespace std;
const ll INF = 2E18 + 10;

// struct cmp{bool operator()(const int & x, const int &y) const{ return x<y;}};
const int N = 2E6 + 10;

void SINGLE_TEST() 
{
    int n,d;
    cin>>n>>d;
    vector<int> h(n+2);
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    ll g = h[1];
    for(ll i = 2; i <= n; i ++ ) g = __gcd(g, h[i]);
    d = d % g;
    cout << min(d, g - d) << "\n";
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int SAMPLES = 1;
    // cin >> SAMPLES;
    while (SAMPLES--) SINGLE_TEST();
}

L.Sudoku and Minesweeper

题意:
一个9*9的矩阵,号代表地雷,用号代替数字,要求最后满足扫雷游戏的规则。

题解:
找到一个不在边界的数字 8 8 8,其余的所有都改为*号就行了

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 6;
string s,t;
int x;
string a[N];
void solve()
{
	int n;
	for(int i=1;i<=9;i++){
		cin>>a[i];
		a[i]=' '+a[i];
	}
	int x=0,y=0;
	for(int i=2;i<9;i++){
		if(x)break;
		for(int j=2;j<9;j++){
			if(a[i][j]=='8'&&x==0){
				x=i,y=j;
				break;
			}
		}
	}
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i==x&&j==y){
				cout<<8;
			}else cout<<'*';
		}
		cout<<'\n';
	}
}

signed main()
{
    int T=1;
//    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

A.Bridging the Gap 2

题意:
一艘船,要 l l l个人操作,最多载 r r r个人。
n n n个人,每个人乘坐船一次消耗 1 1 1体力。体力为0无法坐船。问最后能不能把所有人运到对岸。

题解:
船先运送 r r r个人,再来回 n − r r − l \frac{n-r}{r-l} rlnr趟就可以了
一个人到至少到一次对岸。剩余体力记录可以来回几趟。每个人最多是来回 n − r r − l \frac{n-r}{r-l} rlnr趟。每一趟 l l l个人操作,最后比较一下能不能完成就行了

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 6;

int a[N],p[N];

void solve()
{

	int n,l,r;
	cin>>n>>l>>r;
	int sum=0,x=n-r;
	int y=x/(r-l);
	if(x%(r-l))y++;
	
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=min((a[i]-1)/2,y);
    }

	if(sum>=l*y){
		cout<<"Yes\n";
	} else {
		cout<<"No\n";
	}

}

signed main()
{
    int T=1;
//    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值