牛客小白月赛103 A--B--C
牛客小白月赛103
冰冰的正多边形----A
找最小的大于等于三的边,搓个三角形就好
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stdio.h>
#include<vector>//Vector动态容器
#include<algorithm>
#include<stack>//栈
#include<unordered_map>//哈希表
#include<map>//图
#include<list>//链表
#include<queue>//队列
#include<set>
#define ll long long
using namespace std;
ll a[1000];
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool flag=false;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int i=0;
for(;i<n-2;i++){
if(n>2&&a[i]==a[i+1]&&a[i]==a[i+2]){
flag=true;
break;
}
}
if(!flag)cout<<"no"<<endl;
else cout<<"yes"<<endl<<3*a[i]<<endl;
}
return 0;
}
冰冰的电子邮箱
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stdio.h>
#include<vector>//Vector动态容器
#include<algorithm>
#include<stack>//栈
#include<unordered_map>//哈希表
#include<map>//图
#include<list>//链表
#include<queue>//队列
#include<set>
#define ll long long
using namespace std;
bool check2(char c) {
// 检查是否为字母
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
return true;
}
// 检查是否为数字
if (c >= '0' && c <= '9') {
return true;
}
// 其他情况返回 false
return false;
}
bool check(const string& email) {
int loca = email.find('@');
// 检查是否有 '@' 符号以及位置是否合法
if (loca == string::npos || loca == 0 || loca == email.size() - 1) {//没找到 起始 结束
return false;
}
string localPart = email.substr(0, loca);//截取
string domainPart = email.substr(loca + 1);//截取
// 检查 local-part
if (localPart.length() < 1 || localPart.length() > 64) {
return false;
}
if (localPart.front() == '.' || localPart.back() == '.') {
return false;
}
for (char c : localPart) {
if (!(isalnum(c) || c == '.')) {
return false;
}
}
// 检查 domain
if (domainPart.length() < 1 || domainPart.length() > 255) {
return false;
}
if (domainPart.front() == '.' || domainPart.back() == '.' || domainPart.front() == '-' || domainPart.back() == '-') {
return false;
}
for (char c : domainPart) {
if (!(check2(c) || c == '.' || c == '-')) {
return false;
}
}
return true;
}
int main() {
int t;
cin >> t;
cin.ignore(); // 忽略换行符
while(t--){
string email;
getline(cin, email); // 读取字符串
if (check(email)) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
return 0;
}
冰冰的异或
错误解 显而易见1e18爆炸
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stdio.h>
#include<vector>//Vector动态容器
#include<algorithm>
#include<stack>//栈
#include<unordered_map>//哈希表
#include<map>//图
#include<list>//链表
#include<queue>//队列
#include<set>
#define ll long long
using namespace std;
long long calculate_mex(long long n) {
set<long long>ans;
for (long long i = 1; i <= n; i++) {
for (long long j = 1; j <= n; j++) {
ans.insert(i ^ j);//计算可能的结果
}
}
long long mex = 0;
while (ans.count(mex)) {//只要存在就继续++最后刚好停下来
mex++;
}
return mex;
}
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << calculate_mex(n) << endl;
}
return 0;
}
正解
对于任意 i和 j,其异或结果的最大值为 n⊕n,这将是全 1 的结果
考虑所有可能的 i 和 j 的组合,我们可以生成的异或结果的范围是从 0 到 2n
在这个范围内的每一个数都可以推导出来
1=2^0=0001 1,2特判
2=2^1=0010
4=2^2=0100
8=2^3=1000
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<stdio.h>
#include<vector>//Vector动态容器
#include<algorithm>
#include<stack>//栈
#include<unordered_map>//哈希表
#include<map>//图
#include<list>//链表
#include<queue>//队列
#include<set>
#define ll long long
using namespace std;
#define ll long long
int t;
int main()
{
cin>>t;
while(t--){
ll n,sum=1;
cin>>n;
if(n==1||n==2) {cout<<"1"<<endl;}
else{
while(sum<n)
sum=sum*2;
cout<<sum<<endl;
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现