2021.10.4 训练

A - Gamer Hemose

题意:

给定长度为n的数组为你的攻击伤害值,h为敌人的健康值,你可以选择不同的攻击扣掉敌人相应的健康值,相同攻击不可以连续使用,问你最少需要多少次将敌人的健康值扣为0或负数。

分析 :

思维题。选择伤害值最高的两个攻击交替使用即可,(开始使用循环来实现这部分的代码,但是T掉了)
用取模代替循环。

AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<deque>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#include<tuple>

using namespace std;

typedef long long ll;

int t,n,h,ans;

int main(){
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>n>>h;
        int a[n];
        ans=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        int m1=a[n-1]+a[n-2];
        ans=(h/m1)*2;
        int m2=h%m1;
        if(m2!=0){
            if(m2>a[n-1]) ans=ans+2;
            else ans=ans+1;
        }

        cout<<ans<<endl;
    }
    return 0;
}

B - Hemose Shopping

题意:

给定一个长度为n的数组,可以交换下标相差为x的两个数,问能否将该数组变为递增。

分析 :

思维题。当存在交换盲区时,若交换盲区部分的数字不为递增排列,则不能将该数组元素变为递增排列。

交换盲区如下图
蓝色区域即为交换盲区
图中蓝色区域即为交换盲区,易得其区间表示为:(n-1-x,x)开区间
判断该区间内的序列是否为增即可。

AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<deque>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#include<tuple>

using namespace std;

typedef long long ll;

int t,x,n;

int main(){
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
        cin>>n>>x;
        int a[n],b[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[i]=a[i];
        }
        sort(a,a+n);
        int flag=1;
        for(int i=n-x;i<x;i++){
            if(a[i]!=b[i]){
                flag=0;break;
            }
        }
        if(flag) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

待续。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值