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

每日刷题(算法)

我们N个真是太厉害了

思路:

我们先给数组排序,如果最小的元素不为1,那么肯定是吹牛的,我们拿一个变量记录前缀和,如果当前元素大于它前面所有元素的和+1,那么sum+1是不能到达的值。

代码:

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define pb push_back
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define lowbit(x) x&(-x)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;void solve()
{int n;cin >> n;vector<int>a(n + 1);for (int i = 1; i <= n; i++) cin >> a[i];sort(a.begin() + 1, a.end());if (a[1] != 1) {cout << 1 << '\n';return;}int sum = 1;for (int i = 2; i <= n; i++) {if (a[i] > sum + 1) {cout << sum + 1 << '\n';return;}sum += a[i];if (sum >= n) {cout << "Cool!\n";return;}}cout << "Cool!\n";}
signed main() {ios; TESTsolve();return 0;
}

折返跑

思路:

其实是一个组合数学的题目,我们只要规定每个折返至少挪一米,那么剩下的就可以随便安排,就是一个C(可用的距离,折返次数)就是答案,我们可以预处理一下1到1e6的阶乘。

代码:

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define pb push_back
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define lowbit(x) x&(-x)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;int f[N], a[N], sum[N];
int C(int n, int m) {if (n < m) return 0;if (m == 0) return 1;return f[n] * qpow(f[n - m] * f[m], mod - 2, mod) % mod;
}
void solve()
{int n, m;cin >> n >> m;cout << C(n - 2, m - 1) << '\n';}
signed main() {f[0] = 1;f[1] = 1;for (int i = 2; i <= 1e6; i++) f[i] = f[i - 1] * i % mod;ios; TESTsolve();return 0;
}

好好好数

思路:

直接将n变成k进制数,发现答案就是最大的因为,当k为1时,直接输出1。

代码:

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define pb push_back
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define lowbit(x) x&(-x)
#define pll pair<int,int>
const int N = 3e5 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 998244353;
using namespace std;vector<int>f;
int n, k;
void solve()
{cin >> n >> k;if (k == 1) {cout << 1 << '\n';return;}int ans = 1;while (n) {ans = max(ans, n % k);n /= k;}cout << ans << '\n';}signed main() {ios; TESTsolve();return 0;
}

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

相关文章:

  • 大牛直播SDK核心音视频模块探究
  • gin配置swagger文档
  • 基于ssm的快餐店点餐系统设计与实现
  • 集合框架底层使用了什么数据结构
  • Activiti7《第二式:破剑式》——工作流中的以柔克刚
  • docker快速搭建kafka
  • 基于 onsemi NCV78343 NCV78964的汽车矩阵式大灯方案
  • OpenAl o1论文:Let’s Verify Step by Step 快速解读
  • Errorresponsefromdaemon:toomanyrequests:Youhavereachedyourpullratelimit.
  • [2025]医院健康陪诊系统(源码+定制+服务)
  • Golang | Leetcode Golang题解之第405题数字转换为十六进制数
  • VB中如何使用正则表达式(Regular Expressions)
  • Docker FROM 指定基础镜像
  • 19:I2C一:程序模拟I2C通信时序
  • 最佳实践 · MySQL 分区表实战指南
  • 详细介绍 Redis 列表的应用场景
  • 游戏如何检测加速外挂
  • 【STM32 HAL库】OLED显示模块
  • Redis---卸载Redis
  • 《C++模板元编程实战》阅读记录
  • pybind11 学习笔记
  • 36.贪心算法3
  • htop(1) command
  • ODrive学习——添加485编码器支持
  • 在OSX上: 使用brew安装nginx 后,在通过编译安装第三方模块
  • C++初阶学习第六弹------标准库中的string类
  • Linux基础-Makefile的编写、以及编写第一个Linux程序:进度条(模拟在 方便下载的同时,更新图形化界面)
  • 华为云DevSecOps和DevOps
  • RESTful API设计中的GET与POST:何时及为何成为首选?
  • 秋招自我介绍