ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

算法比赛日志

2022-07-22 01:33:36  阅读:162  来源: 互联网

标签:door 比赛 int behind height column 算法 key 日志


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;
}

他山之石

【待加】

标签:door,比赛,int,behind,height,column,算法,key,日志
来源: https://www.cnblogs.com/shanzr/p/16504198.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有