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

牛客周赛99

Round 99

直接遍历看看有没有两个相同的9(int/string都可以)

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){ios::sync_with_stdio(false);        // 禁用同步cin.tie(nullptr);                   // 解除cin与cout绑定string s;cin >> s;int i;for ( i = 1; i < s.size(); i++) {if (s[i - 1] == s[i] && s[i] == '9') {cout << "YES" << endl;break;}}if (i == s.size()) {cout<<"NO"<<endl;}return 0;
}

 缺陷型电脑

 

遍历找到ASCLL 在int型下最大的值

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t, n;
string s;
int max_s = 0;
int main() {ios::sync_with_stdio(false);        // 禁用同步cin.tie(nullptr);                   // 解除cin与cout绑定cin >> t;while (t--) {cin >> n >> s;max_s = 0;for (int i = 0; i < n; i++) {if (max_s < s[i]) {max_s = (int)s[i];}}cout << max_s << endl;}return 0;
}

 小苯的洞数构造

 题目的意思就是0——9组成的数的权值(相当于)等于K,且这个数最小

分三种情况:n==0    1

                      n 为奇数   4后接n/2个8   (4,48,488,……)

                      n为偶数  n/2个8(8,88,……)

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int t, n;
int main() {ios::sync_with_stdio(false);        // 禁用同步cin.tie(nullptr);                   // 解除cin与cout绑定cin >> t;while (t--) {cin >> n;if (n == 0) {cout << 1 << endl;}
//       else if (n == 1) {
//            cout << 4 << endl;
//        }else {if (n % 2 == 1) {for (int i = 0; i < (n + 1)/2; i++) {if (i == 0) {cout << 4;}else {cout << 8;}}cout << endl;}else {for (int i = 0; i < n / 2; i++) {cout << 8;}cout << endl;}}}return 0;
}

前缀和

找规律:当p%x==0 为奇数                              2*(p / x)- 1

p%x!=0 为偶数                                              2 * (p - p / x)

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll t, x, p;
int main() {ios::sync_with_stdio(false);        // 禁用同步cin.tie(nullptr);                   // 解除cin与cout绑定cin >> t;while (t--) {cin >> x >> p;if (p % x == 0) {cout << 2*(p / x)- 1 << endl;}else {cout << 2 * (p - p / x) << endl;}}return 0;
}

小宇

 我这题的解题思路可能不是特别好

  1. 遍历数组a,对于每个元素a[i]
    • 如果a[i] == i,说明该元素已经在正确的位置,不需要修改,跳过。
    • 否则,统计该元素出现的次数。如果是第一次出现,sum(操作次数)加1,并在q中记录该元素出现次数为1;如果已经出现过,则增加其出现次数。
    • 从后往前遍历数组a,检查是否可以减少操作次数:
      • 如果a[i] > ia[i] > a[i-1],并且该元素在q中只出现一次(it->second == 1),则可以通过一次操作将其修改为i,从而减少操作次数(sum--)。
      • 如果a[i] > ia[i] <= a[i-1],或者该元素出现多次,则无法通过当前操作减少次数,直接跳出循环。

大概就是它(后面出现一直a[i] > i && a[i] > a[i - 1]且只出现一次时)或(本身就为a[i])可以不用变为i,剩下的都要变。

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int t, n;
int a[200005];
int main() {ios::sync_with_stdio(false);        // 禁用同步cin.tie(nullptr);                   // 解除cin与cout绑定cin >> t;while (t--) {map<int,int> q;cin >> n;int sum = 0;a[0] = 0;for (int i = 1; i <= n; i++) {cin >> a[i];}for (int i = 1; i <= n; i++) {if (a[i] == i) {continue;}else {auto it = q.find(a[i]);if (it == q.end()) {sum++;q.insert({ a[i],1 });}else {it->second++;}}}for (int i = n; i > 0; i--) {auto it = q.find(a[i]);if (a[i] > i && a[i] > a[i - 1] && it!=q.end()&&it->second == 1) {sum--;}else {if (a[i] > i && it != q.end()&& it->second == 1) {sum--;}break;}}cout << sum << endl;}return 0;
}

 汉堡猪猪分糖果

考虑按高位到低位贪心,若到某一位时剩余数量不足以分给 m 个人,那么只给一部分人在该位进行分配,使得剩下的糖果可以在下一位恰好均分 m 份。

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll t, n, m;
int main() {ios::sync_with_stdio(false);        // 禁用同步cin.tie(nullptr);                   // 解除cin与cout绑定cin >> t;while (t--) {cin >> n >> m;int q = 1<<30;int sum = 0;while (q > 0) {if (q * m <= n) {n -= q * m;sum += q;}else {if (m * (q - 1) <= n) {int ff = n - (q - 1) * m;n -= q * ((ff + q - 1) / q);}}q >>=1;}cout << sum << endl;}return 0;
}

 

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

相关文章:

  • 关于 栈帧变化完整流程图(函数嵌套)
  • 大模型面试:RAG与Agent相关
  • 《Redis》集群
  • 【Note】《Kafka: The Definitive Guide》 第二章 Installing Kafka:Kafka 安装与运行
  • Redis--主从复制详解
  • 【Docker基础】Docker容器挂载方式深度解析:--volume与--mount参数对比
  • QT6 源(155)模型视图架构里的列表视图 QListView:接着学习成员函数,信号函数,附上本类的源代码带注释。
  • HCIA-网络地址转换(NAT)
  • CppCon 2018 学习:Woes of Scope Guards and Unique_Resource
  • 抖音小游戏(IAA)巨量引擎投放指南
  • [shadPS4] 内存管理 | 权限管理 |文件系统 | 挂载和句柄
  • 【BTC】数据结构
  • 7,TCP服务器
  • JavaScript基础语法之运算符和控制流
  • 李宏毅NLP-8-语音模型
  • 【管理学】组织纪律性与创新性的失衡导致的问题
  • Redis事务机制
  • [论文阅读]VGGFace2: A dataset for recognising faces across pose and age
  • Linux-磁盘管理
  • 【前端工程化】前端工作中的业务规范有哪些
  • 基于评估方法论评估一个大模型的准确度
  • 文心开源大模型ERNIE-4.5-0.3B-Paddle私有化部署保姆级教程及技术架构探索
  • Java面试宝典:网络编程
  • 基于Pandas和FineBI的昆明职位数据分析与可视化实现(五) - 基于随机森林算法预测职位分类
  • 【星闪】Hi2821 | Pinctrl、GPIO + LED灯和按键输入例程
  • 字符函数和字符串函数(下)- 暴力匹配算法
  • python pip 下载慢
  • 在 Dokploy 中为 PostgreSQL 搭建 PgBouncer 数据库连接池(图文)
  • 【influxdb3】如何使用 SQL 对时间序列数据进行聚合查询
  • Golang读取ZIP压缩包并显示Gin静态html网站