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

2025年7月28日训练日志

1952. 三除数 - 力扣(LeetCode)

方法一:直接从1遍历到sqrt(n);

方法二:找出质因子,个数为2且总和为3的就是,因为要保证只有三个因数,其中一个数是1,另一个数是它本身,那剩下那个只能是质因子。

class Solution {
public:bool isThree(int n) {int num = n;vector<int>a(10005,0);a[1]++;for(int i=2;i*i<=num;i++){while(num%i==0){a[i]++;num/=i;}}if(num > 1) a[num]++;int cnt = 0,sum = 0;for(int i=1;i<=n;i++){if(a[i]){sum+=a[i];cnt++;}}if(cnt == 2 && sum == 3) return 1;else return 0;}
};

914. 卡牌分组 - 力扣(LeetCode)

 对每个数的个数计算最大公约数,如果最后结果大于等于2的话就可以分组

class Solution {int a[10005];
public:bool hasGroupsSizeX(vector<int>& deck) {for(int num : deck){a[num]++;}int x = -1;for(int i=0;i<=10000;i++){if(a[i]){if(x==-1){x = a[i];}else{x = __gcd(x,a[i]);}}}if(x>=2) return true;else return false;}
};

Problem - 2126D - Codeforces

贪心,按左区间排序,因为题目确保了re>=l,然后依次遍历求最大值 

#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;void solve() {int n, k;cin >> n >> k;vector<pair<int, pair<int, int>>> a(n);for (int i = 0; i < n; i++) {int l, r, re;cin >> l >> r >> re;a[i] = {l, {r, re}};}sort(a.begin(), a.end());int cur = k;for(int i=0;i<n;i++){if(a[i].first > cur) break;cur = max(cur,a[i].second.second);}cout<<cur<<endl;
}signed main() {FASTint t = 1;cin >> t;while (t--)solve();return 0;
}

 Problem - 2126C - Codeforces

因为每次都要往更高的楼层传送,因此直接用set来存数据,然后进行遍历模拟一遍就可以了 

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define endl "\n"
#define FAST ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int MOD = 1e9+7;
const int mod = 998244353;
using namespace std;void solve(){int n,k;cin>>n>>k;set<int>st;int nh;for(int i=0;i<n;i++){int h; cin>>h;if(i == k-1) nh = h;//现在的高度st.insert(h);}int t = 1;//水位,初始水位为1for(auto h : st){if(h > nh){//如果高度大于他现在的高度int cz = h - nh;//高度差if(t + cz <= nh + 1){//如果水位加上高度差值小于等于当前的高度+1的话nh = h;t+=cz;}else{cout<<"NO"<<endl;return ;}}}cout<<"YES"<<endl;
}signed main() {FASTint t = 1;cin>>t;while(t--)solve();return 0;
}

 Problem - 2124B - Codeforces

 做操作的地方只可能从第一个开始或者从第二个开始,因此只需要分别算出求最小值就可以

#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define FAST ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
using namespace std;void solve(){int n; cin>>n;int a[n];for(int i=0;i<n;i++) cin>>a[i];int ans = min(a[0]*2,a[0] + a[1]);cout<<ans<<endl;
}signed main() {FASTint t = 1;cin>>t;while(t--)solve();return 0;
}

http://www.dtcms.com/a/303558.html

相关文章:

  • 【三桥君】如何解决后端Agent和前端UI之间的交互问题?——解析AG-UI协议的神奇作用
  • 排水管网实时监测筑牢城市安全防线
  • 线程间-数据缓存机制(线程邮箱)
  • CDN架构全景图
  • STM32 usb HOST audio USB 音频设备 放音乐
  • springCloudAlibaba集成Dubbo
  • 【版本更新】火语言 0.9.94.0 更新
  • 虚拟面孔,真实革命
  • Product Hunt 每日热榜 | 2025-07-28
  • JAVA_EIGHTEEN_特殊文件
  • STM32——寄存器映射
  • LLaMA-Factory微调教程2:命令行sft微调
  • 【拓扑排序 缩点】P2272 [ZJOI2007] 最大半连通子图|省选-
  • 【跳跃游戏】
  • BUUCTF-MISC-[HBNIS2018]caesar1
  • Linux驱动22 --- RV1126 环境搭建设备树修改
  • 从零到一:我是如何用深度学习打造高性能书籍推荐系统的
  • mp核心功能
  • 零基础学习性能测试第九章:全链路追踪-项目实操
  • 猎板 PCB 控深槽工艺:5G 基站散热模块的关键支撑
  • 解决c++运行时提示:first defined here (重复定义问题)
  • **线程与进程的区别与联系**
  • Qt下使用图形视图框架实现图像上各图形绘制
  • 一个Pycharm窗口添加多个项目来满足运行多个项目的需求
  • linux常用的指令
  • HTML响应式SEO公司网站源码
  • MVSNet系列网络概述
  • 7寸工业模组 XA070Y2-L01芯显科技详细参数资料
  • MCU中的外设总线是什么?
  • 带 USB 接口的多功能 AI 降噪消回音模组 A-59P:革新语音处理体验​