当前位置: 首页 > news >正文

牛客周赛 Round 46 题解 C++

目录

 A 乐奈吃冰

B 素世喝茶

C 爱音开灯

D 小灯做题

E 立希喂猫

F 祥子拆团


 A 乐奈吃冰

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>using namespace std;typedef pair<int,int> PII;
typedef long long ll;const int N = 3e5 + 10,M = 1e9 + 7;int n,m;
int a[N],b[N];
bool st[N];
ll cnt;void solve()
{cin >> n >> m;if(n == 1){cout << 1;return ;}if(m > n / 2){cout << n / 2 + n;}else{cout << n + m;}
}int main()
{std::ios::sync_with_stdio(false);cin.tie(nullptr);int t = 1;while(t --){solve();}return 0;
}

B 素世喝茶

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>using namespace std;typedef pair<int,int> PII;
typedef long long ll;const int N = 3e5 + 10,M = 1e9 + 7;int n,m;
int a[N];
bool st[N];
ll cnt;void solve()
{cin >> n >> m;int mx = 0;for(int i = 1; i <= n; i ++){int x;cin >> x;if(i == m) continue;if(x > mx){mx = x;cnt = 1;}else if(x == mx){cnt ++;}}cout << cnt;
}int main()
{std::ios::sync_with_stdio(false);cin.tie(nullptr);int t = 1;while(t --){solve();}return 0;
}

C 爱音开灯

#include <iostream>
#include <cmath>using namespace std;void solve() {long long n, m;cin >> n >> m;long long cnt = 0;for (long long i = 1; i * i <= m; i++) {if(m % i == 0){if(i<=n) cnt++;if(m/i!=i&&m/i<=n) cnt++;}}if (cnt % 2 == 1) {cout << "ON";} else {cout << "OFF";}
}int main() {std::ios::sync_with_stdio(false);cin.tie(nullptr);int t = 1;while (t--) {solve();}return 0;
}

D 小灯做题

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>using namespace std;typedef pair<int,int> PII;
typedef long long ll;const int N = 3e5 + 10,M = 1e9 + 7;ll n,m;
int a[N];
bool st[N];
ll cnt;
int k,res;int mex(int a,int b){if(a + b == 1){return 2;}else{if(a == 0 || b == 0){return 1;}else{return 0;}}
}void dfs(int a,int b,int c,int sum){if(sum > 3 || a == k || b == k || c == k){res=min(res,sum);return ;}dfs(a,b,mex(a,b),sum+1);dfs(a,mex(a,c),c,sum+1);dfs(mex(b,c),b,c,sum+1);
}void solve()
{cin >> n;while(n --){int a,b,c;cin >> a >> b >> c >> k;res = N;if(a == k || b == k || c == k){cout << 0 << "\n";continue;}if(k >= 3){cout << -1 << "\n";continue;}dfs(a,b,c,0);cout << res << "\n";}}
int main()
{std::ios::sync_with_stdio(false);cin.tie(nullptr);int t = 1;while(t --){solve();}return 0;
}

E 立希喂猫

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>using namespace std;typedef pair<int,int> PII;
typedef long long ll;
#define x first
#define y secondconst int N = 3e5 + 10,M = 1e9 + 7;ll n,m;
ll s1[N],s2[N];
ll c[N];
bool st[N];
ll cnt;PII a[N];void solve()
{cin >> n;for(int i = 1; i <= n ;i ++){cin >> a[i].y;}for(int i = 1; i <= n ;i ++){cin >> a[i].x;}sort(a+1,a+1+n);for(int i = 1; i <= n ; i ++){s1[i] += s1[i-1] + a[i].y * a[i].x;s2[i] += s2[i-1] + a[i].y;}cin >> m;while(m --){int t;cin >> t;ll res = 0;pair<int,int> p(t,0);int id_1 = upper_bound(a + 1,a+ n + 1,p) - a;res += s1[id_1 - 1];res += (s2[n] - s2[id_1 - 1]) * t; cout << res << "\n";}return ;
}
int main()
{std::ios::sync_with_stdio(false);cin.tie(nullptr);int t = 1;while(t --){solve();}return 0;
}

F 祥子拆团

没代码思路,后面补

http://www.lryc.cn/news/368659.html

相关文章:

  • 9.3 Go 接口的多态性
  • Java通过字符串字段匹配形成树形结构
  • 数字孪生智慧水利:精准管理与智能决策的新时代
  • 基于ChatGLM3的本地问答机器人部署流程
  • 归并排序——逆序数对的统计
  • 基于截图和模拟点击的自动化压测工具开发(MFC)
  • 力扣每日一题 6/10
  • [知识点] 内存顺序属性的用途和行为
  • JAVA Mongodb 深入学习(二)索引的创建和优化
  • 转让北京劳务分包地基基础施工资质条件和流程
  • Python基础——字符串
  • AP的数据库性能到底重要吗?
  • Vue3【二】 VSCode需要安装的Vue语法插件
  • 设置路径别名
  • 人事信息管理系统(Java+MySQL)
  • Python 中生成器与普通函数的区别
  • 最小栈、栈的弹出(C++)
  • 20240607每日通信--------VUE3前端引入scoket-io,后端引入Netty-SocketIO,我成功了,希望一起交流沟通
  • Tomcat源码解析(八):一个请求的执行流程(附Tomcat整体总结)
  • python使用gdb进行堆栈查看与调试
  • 【DevOps】路由与路由器详细介绍:原理、功能、类型及应用场景
  • 【WP|9】深入解析WordPress [add_shortcode]函数
  • Qt QStackedWidget类详细分析
  • Java数据结构与算法(leetcode热题881. 救生艇)
  • react+wijmo所遇问题
  • 手撕设计模式——克隆对象之原型模式
  • LangChain基础知识入门
  • Objective-C的初始化方法中,应该如何读写属性
  • 基于Python+Flask框架实现的新冠疫情可视化的设计与实现
  • 大学生如何学习C语言编程?