当前位置: 首页> 娱乐> 影视 > 牛客小白月赛100部分题解

牛客小白月赛100部分题解

时间:2025/7/10 3:58:03来源:https://blog.csdn.net/song0789/article/details/142001781 浏览次数:0次

比赛地址:牛客小白月赛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;// 遍历所有可能的排雷能力 mfor (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;
}

关键字:牛客小白月赛100部分题解

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: