算法比赛日志
2022/7/23 1:25:00
本文主要是介绍算法比赛日志,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
20220722 CF
具体名称
Educational Codeforces Round 132 (Rated for Div. 2)
年轻人的第一次比赛,颇具纪念意义(虽然就做了俩签到题)。
A. Three Doors
There are three doors in front of you, numbered from \(1\) to \(3\) from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.
There are three keys — one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.
Can you open all the doors?
读题
- obtain v.获得;(尤指经努力)赢得;存在;流行;沿袭
复现
第一次写英语题,读题读得颇为心急,还好读完就能做。
感觉条件很宽裕,门的数目也限制为3就不需要写搜索,我就直接两次判断整模拟了hhh,非常不优雅
代码
#include <iostream> using namespace std; int door[4]; int main(){ int t;cin>>t; while (t--) { int flag=1,x;cin >> x; for (int i = 1; i <= 3; i++)cin >> door[i]; if(door[x]==0){ flag=0; } if(door[door[x]]==0){ flag=0; } if(flag)cout<<"YES\n"; else cout<<"NO\n"; } return 0; }
他山之石
【待加】
B. Also Try Minecraft
You are beta testing the new secret Terraria update. This update will add quests to the game!
Simply, the world map can be represented as an array of length nn, where the \(i\)-th column of the world has height \(a_i\).
There are mm quests you have to test. The \(j\)-th of them is represented by two integers \(s_j\) and \(t_j\). In this quest, you have to go from the column \(s_j\) to the column \(t_j\). At the start of the quest, you are appearing at the column \(s_j\).
In one move, you can go from the column \(x\) to the column \(x−1\) or to the column \(x+1\). In this version, you have Spectre Boots, which allow you to fly. Since it is a beta version, they are bugged, so they only allow you to fly when you are going up and have infinite fly duration. When you are moving from the column with the height pp to the column with the height \(q\), then you get some amount of fall damage. If the height \(p\) is greater than the height \(q\), you get \(p−q\) fall damage, otherwise you fly up and get 00 damage.
For each of the given quests, determine the minimum amount of fall damage you can get during this quest
读题
-
be represented as 被表示为
-
infinite adj.极大的;无法衡量的;无限的;无穷尽的 n.无限的事物;无穷尽的事物;上帝
复现
一眼前后缀,调试了几下就过了。
代码
#include <iostream> using namespace std; int a[100010]; long long sum[100010]; long long sum2[100010]; int n,m; void query(int from,int to){ if(from<=to)cout<<sum[to]-sum[from]<<endl; else cout<<sum2[to]-sum2[from]<<endl; } int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; sum[i]=sum[i-1]; if(a[i]>a[i-1])continue; if(i==1)continue; sum[i]+=a[i-1]-a[i]; } for(int i=n;i>=1;i--){ sum2[i]=sum2[i+1]; if(a[i]>a[i+1])continue; if(i==n)continue; sum2[i]+=a[i+1]-a[i]; } int from,to; while(m--){ cin>>from>>to; query(from,to); } return 0; }
他山之石
【待加】
这篇关于算法比赛日志的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-27消息中间件底层原理资料详解
- 2024-11-27RocketMQ底层原理资料详解:新手入门教程
- 2024-11-27MQ底层原理资料详解:新手入门教程
- 2024-11-27MQ项目开发资料入门教程
- 2024-11-27RocketMQ源码资料详解:新手入门教程
- 2024-11-27本地多文件上传简易教程
- 2024-11-26消息中间件源码剖析教程
- 2024-11-26JAVA语音识别项目资料的收集与应用
- 2024-11-26Java语音识别项目资料:入门级教程与实战指南
- 2024-11-26SpringAI:Java 开发的智能新利器