当前位置:网站首页>牛客小白月赛50
牛客小白月赛50
2022-06-26 15:47:00 【Changersh】
A.跳跃

签到题
需要注意的一个坑就是,题目没有特别说明,那么除法就应该不是整除的,所以把除法的分母乘过去即可
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include<unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 100002;
const int MOD = 1e9 + 7;
int n, k;
int a[N];
int main() {
scanf("%d %d", &n, &k);
scanf("%d", &a[0]);
int res = 0;
for (int i = 1; i < n; i++) {
scanf("%d", &a[i]);
if ((a[i] > a[i - 1] * k) || (a[i] * k < a[i - 1]))
res++;
}
printf("%d", res);
return 0;
}
B.减法和除法

数学
要求最少的操作数,即每次操作之后得到的数更小,也就是操作之前比较 n / 2 和 n - x 的大小,选择小的那个操作
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e4 + 5;
const int MOD = 1e9 + 7;
int main() {
int n, x;
scanf("%d %d", &n, &x);
int res = 0;
while (n > 0) {
if (n / 2 < n - x) {
n /= 2;
} else {
n -= x;
}
res++;
}
printf("%d", res);
return 0;
}
C.减法和求余


数学
首先要分析出来,只有0 1 2 这三种情况,0 是全是0,不用操作了。1 是进行一次操作一,或者一次操作二
一次操作二:全是1,减一即可
一次操作一:同时对一个>=2的数取余,余数为0,说明,这一堆数字有非 1 的 最大公约数
剩下的都是操作两次的
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
// 只可能是 0 1 2 三种情况
int n;
int a[N];
int f0 = 1, f1 = 1; // 分别判断是否全是0,或者是否全是1 / 0
int gcd_(int a, int b) {
return b == 0 ? a : gcd_(b, a % b);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] != 0) f0 = 0; // 并非全是0
if (a[i] > 1) f1 = 0;
}
if (f0) puts("0");
// 对于 1 步,那就是 要么全是 1 / 0,要么就是他们有相同的gcd
else {
int g = a[0];
for (int i = 1; i < n; i++) {
g = gcd_(g, a[i]); // 求 gcd
}
if (g > 1 || f1) puts("1");
else puts("2");
}
return 0;
}
D.生日



计算贡献

总的方案数就是 2^n
总共分三种情况,第 i 天,与第 2i 和 2i + 1 天有关
第一种情况,确定了两个数字,还剩下 2^n - 2^种方案数
第二种情况,确定了三个数字,还剩下2^n - 3^种方案数
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include<unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const ll MOD = 1e9 + 7;
int n;
ll a[N];
ll p2[N]; // 预处理 2 ^n
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
p2[0] = 1;
for (int i = 1; i < n + 6; i++) {
p2[i] = p2[i - 1] * 2ll % MOD;
}
ll res = 0;
for (int i = 1; i <= n; i++) {
if (n < 2 * i) {
break;
}
else if (n < 2 * i + 1) {
res = res + p2[n - 2] * (a[i] ^ a[2 * i]) % MOD;
res %= MOD;
} else {
res = res + p2[n - 3] * ((a[i] ^ a[2 * i]) + (a[i] ^ a[2 * i + 1]) + (a[2 * i + 1] ^ a[2 * i]) + (a[i] ^ a[2 * i] ^ a[2 * i + 1])) % MOD;
res %= MOD;
}
}
printf("%lld", res);
return 0;
}
边栏推荐
- (一)keras手写数字体识别并识别自己写的数字
- 补齐短板-开源IM项目OpenIM关于初始化/登录/好友接口文档介绍
- 还存在过有键盘的kindle?
- 面试踩坑总结一
- The first batch in the industry! Tencent cloud security and privacy computing products based on angel powerfl passed CFCA evaluation
- Canvas three dot flashing animation
- 为什么图像分割任务中经常用到编码器和解码器结构?
- Selenium chrome disable JS disable pictures
- R语言plotly可视化:小提琴图、多分类变量小提琴图、分组(grouped)小提琴图、分裂的分组小提琴图、每个小提琴图内部分为两组数据、每个分组占小提琴图的一半、自定义小提琴图的调色板、抖动数据点
- Svg rising Color Bubble animation
猜你喜欢

Solana扩容机制分析(2):牺牲可用性换取高效率的极端尝试 | CatcherVC Research

JVM notes

TweenMax+SVG切换颜色动画场景

今年高考英语AI得分134,复旦武大校友这项研究有点意思

『C语言』题集 of ⑩

svg上升的彩色气泡动画

Simple use of tensor

Tencent Peking University's sparse large model training acceleration program het was selected into the VLDB of the international summit

Summary of data interface API used in word search and translation applications

Application of ansible automation
随机推荐
「干货」NFT 上中下游产业链全景分析
Net基于girdview控件实现删除与编辑行数据
振动式液量检测装置
手机上怎么开户?在线开户安全么?
STEPN 新手入门及进阶
Development, deployment and online process of NFT project (2)
[problem solving] the loading / downloading time of the new version of webots texture and other resource files is too long
[thinking] what were you buying when you bought NFT?
6 自定义层
golang 1.18 go work 使用
清华“神奇药水”登Nature:逆转干细胞分化,比诺奖成果更进一步,网友:不靠精子卵子就能创造生命了?!...
R语言plotly可视化:小提琴图、多分类变量小提琴图、分组(grouped)小提琴图、分裂的分组小提琴图、每个小提琴图内部分为两组数据、每个分组占小提琴图的一半、自定义小提琴图的调色板、抖动数据点
R语言使用cor函数计算相关性矩阵进行相关性分析,使用corrgram包可视化相关性矩阵、行和列使用主成分分析重新排序、下三角形中使用平滑的拟合线和置信椭圆,上三角形中使用散点图、对角线最小值和最大值
如何辨别合约问题
(DFS search) acwing 2005 horseshoe
NFT Platform Security Guide (1)
[untitled]
4 自定义模型训练
「幹貨」NFT 上中下遊產業鏈全景分析
Audio and video learning (III) -- SIP protocol