牛客小白月赛100部分题解

比赛地址:牛客小白月赛100_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ


A.ACM中的A题

#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull = unsigned long long
void solve() {
	ll a,b,c;
	cin>>a>>b>>c;
	a*=2;
	if(a+b>c&&a+c>b&&b+c>a)
	{
		cout<<"Yes";
		return;	
	}
	a/=2;
	b*=2;
	if(a+b>c&&a+c>b&&b+c>a)
	{
		cout<<"Yes";
		return;	
	}
	b/=2;
	c*=2;
	if(a+b>c&&a+c>b&&b+c>a)
	{
		cout<<"Yes";
		return;	
	}
	cout<<"No";
} 

signed main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    ll t = 1; 
    // std::cin >> t;
    while (t--) {
        solve();
    }
}


B.ACM中的C题

#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull = unsigned long long
void solve() {
	ll a,b,c;
	cin>>a;
    if(a==1)
    {
        cout<<-1;
        return;
    }
    else
    {
        cout<<(a/2+a%2);
        return;
    }
} 

signed main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    ll t = 1; 
    // std::cin >> t;
    while (t--) {
        solve();
    }
}


C.ACM中的M题

#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull = unsigned long long
void solve() {
	ll a,b,c;
    map<int,int> mp;
	cin>>a;
    if(a==1)
    {
        cout<<-1;
        return;
    }
    else
    {
        int sum=0;
        for(int i=1;i<=a;++i)
        {
            cin>>b;
        }
        for(int i=1;i<=a;++i)
        {
            cin>>b;
            mp[b]++;
            
        }
        for(map<int,int>::iterator it = mp.begin();it!=mp.end();it++)
        {
            if(it->second==1)
            {
                cout<<-1;
                return;
            }
            else
            {
                sum+=(it->second/2+it->second%2);
            }
        }
        cout<<sum;
        return;
    }
} 

signed main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    ll t = 1; 
    // std::cin >> t;
    while (t--) {
        solve();
    }
}


E.ACM中的CM题

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;  // 读入地雷的数量
    vector<int> a(n);  // 存储地雷的位置

    for (int i = 0; i < n; ++i) {
        cin >> a[i];  // 读入每个地雷的位置
    }

    // 对地雷的位置进行排序,方便后续处理
    sort(a.begin(), a.end());

    // 初始化最小时间,最坏情况下是 n(每个地雷都单独处理)
    int minTime = n;

    // 遍历所有可能的排雷能力 m
    for (int m = 0; m < n; ++m) {
        int ans = m;  // 当前排雷能力 m 需要的时间
        
        // 当前位置初始化为第一个地雷
        int pos = a[0];
        
        // 处理所有地雷
        while (1) {
            ans++;  // 每次需要处理的时间增加
            
            // 查找当前能力 m + 1 可以覆盖的最远位置
            pos = upper_bound(a.begin(), a.end(), pos + m) - a.begin();
            
            if (pos == n) break;  // 如果所有地雷都被处理,退出循环
            
            // 更新当前位置为新的地雷位置
            pos = a[pos];
        }

        // 更新最小时间
        minTime = min(minTime, ans);
    }

    cout << minTime << endl;  // 输出最小时间
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值