ACM题解Day3| To Crash or not To Crash,Integer Prefix ,I don’t want to pay for the Late Jar
学习目标:
博主介绍: 27dCnc
专题 : 数据结构帮助小白快速入门算法
👍👍👍👍👍👍👍👍👍👍👍👍
☆*: .。. o(≧▽≦)o .。.:*☆
Github今日打卡
- ACM题解
学习时间:
- 周一至周五晚上 7 点—晚上9点
- 周六上午 9 点-上午 11 点
- 周日下午 3 点-下午 6 点
学习内容:
- To Crash or not To Crash
- Integer Prefix
- I don’t want to pay for the Late Jar
- Kernel of Love
内容详细:
To Crash or not To Crash
题目考点: 逻辑
模拟
小函数
解题思路
- 只有三行,三行判断
- 判断 = 会不会遇到 H
- 每行都判断,判断哪一行先遇到
详细代码
版本一:
/******begin******/
#include<bits/stdc++.h>
#define Run 0
#define endl "\n"
using unl = __int128_t;
using ll = long long;
using namespace std;
void slove() {
string s1,s2,s3;
cin>>s1>>s2>>s3;
int a = 0 ,b = 0, c = 0;
for (int i = 0;i < 10; i++) {
if (s1[i] == '=') { //如果第一行中有 = (车) 就向后进行遍历看后面是否为空,如果不为空输出那个不为空的物体(值)
for (int j = i + 1; j < 10;j++) {
if (s1[j] != '.') {
cout<<s1[j];
return ;
}
}
}
if (s2[i] == '=') { //同理
for (int j = i + 1; j < 10;j++) {
if (s2[j] != '.') {
cout<<s2[j];
return ;
}
}
}
if (s3[i] == '=') {
for (int j = i + 1; j < 10;j++) {
if (s3[j] != '.' ) {
cout<<s3[j];
return ;
}
}
}
}
cout << "You shall pass!!!";
}
signed main() {
#if Run
int _;cin>>_;while(_--) slove();
#else
slove();
#endif
return 0;
}
/*******end*******/
版本二: 优化
#include<bits/stdc++.h>
#define Run 0
#define endl "\n"
using unl = __int128_t;
using ll = long long;
using namespace std;
/*用小函数去判断*/
bool plan(string s3,int i) {
for (int j = i + 1; j < 10;j++) {
if (s3[j] != '.' ) {
// 将结果输出
cout<<s3[j];
return true;
}
}
return false;
}
/**/
void slove() {
string s1,s2,s3;
/*将行数输入*/
cin>>s1>>s2>>s3;
int a = 0 ,b = 0, c = 0;
for (int i = 0;i < 10; i++) {
/*从第一行开始判断*/
if (s1[i] == '=') {
if (plan(s1,i)) return ;
}
/*只要一行没有满足条件就返回*/
if (s2[i] == '=') {
if (plan(s2,i)) return ;
}
if (s3[i] == '=') {
if (plan(s3,i)) return ;
}
}
cout << "You shall pass!!!";
}
signed main() {
#if Run //这里用于控制多行输入
int _;cin>>_;while(_--) slove();
#else
slove();
#endif
return 0;
}
Integer Prefix
题目考点: 函数
模拟
思路
只要遇到数字就输出,不是数字停止遍历和输出
题目意思是输出最大的数组这些数全部都要在开头,而且不能出现数字字符之外的字符
注意 如果没有数字字符就输出 -1
#include<bits/stdc++.h>
#define Run 0
#define endl "\n"
using unl = __int128_t;
using ll = long long;
using namespace std;
void slove() {
string s; cin >> s; //输入字符
bool k = true; //用于判断是否有数字字符
for (int t = 0; t < s.size(); t++) {
if (isdigit(s[t])) { //用函数来判断是否是数字字符
k = false; //这个表示有
cout << s[t]; ///如果是则边输出
} else {
break;
}
}
if (k) cout << -1; //如果存在就不会执行
}
signed main() {
#if Run
int _;cin>>_;while(_--) slove();
#else
slove();
#endif
return 0;
}
I don’t want to pay for the Late Jar
题目考点: 模拟
题目解释
给你一个总时间S和每个餐厅吃午餐的时间ti和愿意支付的额外费用fi,如果ti<=S,那么他会得到fi的幸福值,否则他会得到fi-(ti-S)的幸福值,求他在一个餐厅吃饭能得到的最大幸福值。
Problem solving: 直接判断求最大值就行了,注意有负数,初始值不能附为0。
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll d;
cin>>d;
ll n,s;
for(ll j=0;j<d;j++){
cin>>n>>s;
ll f[n],t[n];
for(int i=0;i<n;i++){
cin>>f[i]>>t[i];
}
ll max= LLONG_MIN;
for(ll i=0;i<n;i++){
if(t[i]<=s){
if(f[i]>max) max=f[i];
}else{
ll m=s+f[i]-t[i];
if(m>max) max=m;
}
}
cout<<"Case #"<<j+1<<": "<<max<<endl;
}
return 0;
}
case 情况难搞,于是就不搞函数,会更简单,或者,加给全局变量
Kernel of Love
题目考点: 模拟
斐波那契数列
gcd
规律总结
详细代码:
#include<bits/stdc++.h>
#define Run 1
#define endl "\n"
#define N 100005
using unl = __int128_t;
using ll = long long;
using namespace std;
int a[N];
void slove() {
int n; cin >> n;
a[3] = 2; a[4] = 3; // 用于初始化斐波那契数列
for (int i = 5; i <= N; i++) {
if ((i % 3 && (i + 1) % 3) || i % 3 == 0) { //这个是满足幸福夫妻的情况
a[i] = a[i - 1] + 1; //动态规划的写法
} else {
a[i] = a[i - 1]; //不满足幸福父亲的情况
}
}
cout << a[n] << endl; ///储存在数组种输出数组结果即可
//我现在也不太清楚
}
signed main() {
cin.tie(0) -> ios::sync_with_stdio(0);
cout.tie(0) -> ios::sync_with_stdio(0);
#if Run
int _;cin>>_;while(_--) slove();
#else
slove();
#endif
return 0;
}
学习产出:
- 技术笔记 2 遍
- CSDN 技术博客 3 篇
- 习的 vlog 视频 1 个
重磅消息:
GTP - 4 最新版接入服务他来了 点击链接即可查看详细
🔥如果此文对你有帮助的话,欢迎💗关注、👍点赞、⭐收藏、✍️评论,支持一下博主~
本文作者:2c237c6
本文链接:https://www.cnblogs.com/27dCnc/p/18568636
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步