首页 > 试题广场 >

D塔2

[编程题]D塔2
  • 热度指数:2651 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
在 D这款游戏中,英雄和小兵都可以对对方的防御塔造成伤害,但是只有当对敌方防御塔最后的伤害是由英雄造成时,才会得到相应的金钱奖励。 现在小明正在玩 D,操作英雄带着一波兵进入了对方的塔下进行攻击。已知:
1. 一共有 个小兵,小兵的攻击力为 ,所有小兵对塔的攻击是同时进行的,小兵的攻击冷却为 t0 
2. 小明的英雄有一个技能可以对塔造成伤害,伤害值为 ;英雄的普通攻击也可以对塔造成的伤害,伤害值为 。小明的英雄普通攻击的冷却为 t1 ,技能冷却为 t2  
3. 小兵的攻击,小明的普通攻击和小明的技能攻击,只要冷却时间一到,就会马上攻击;小明的普通攻击和技能攻击可以同时施展;如果小兵和英雄同时攻击,小兵的伤害算在前。 已知现在对方的塔还剩下s的血量,所有小兵的第一次攻击和英雄的第一次普通攻击和技能攻击在初始时刻同时进行,问小明可以得到破坏该塔的金钱奖励么? 注意:这里冷却是指连续两次攻击之间的等待时间,英雄的普通攻击和技能攻击的冷却两者互不干预。如果冷却是 ,某次攻击发生在时间 ,那么时间 才可以继续攻击。假定攻击立即生效。
数据范围:

输入描述:
第一行一个整数T,表示测试组数;

接下来一行一个整数s,表示塔的剩余血量;

接下来一行4个整数n,d,x,y,含义如题面;

接下来一行3个整数t0,t1,t2,含义如题面


输出描述:
对于每组测试数据输出”YES”表示小明的英雄可以补到,”NO”表示不能。(输出不包括引号)
示例1

输入

1
3
1 1 1 1
1 1 1

输出

YES
数据给的不大,暴力模拟即可,判断每个时刻有哪些攻击是可能的,把小兵攻击的判断放前面。用时间作为循环
#include<bits/stdc++.h>
using namespace std;
int T, s, n, d, x, y, t0, t1, t2;

string solve() {
    scanf("%d%d%d%d%d%d%d%d", 
		&s, &n, &d, &x, &y, &t0, &t1, &t2);
	int time = 0;
    while(s > 0) {
        if(time % t0 == 0) {
            s -= n * d;
            if(s <= 0) return "NO";
        }
        if(time % t1 == 0) {
            s -= y;
            if(s <= 0) return "YES";
        }
        if(time % t2 == 0) {
            s -= x;
            if(s <= 0) return "YES";
        }
        time++;
    }
    return "NO";
}


int main() {
    scanf("%d", &T);
    while(T--) cout<<solve()<<endl;
}
/*
1
3
1 1 1 1
1 1 1
*/


发表于 2020-02-05 11:05:17 回复(1)
模拟游戏的代码,很喜欢。python3版本的代码:有点类似于丑数的计算想法,但要更简单点。
def get_money(blood):
    res = []
    s1,s2,s3 = 0,0,0
    while blood>0:
        if s1<=s2 and s1<=s3:
            blood -= n*d
            s1 += t0
            res.append(0)
        elif s2<=s3 and s2<s1:
            blood -= y
            s2 += t1
            res.append(1)
        elif s3 <=s2 and s3<s1:
            blood -= x
            s3 += t2
            res.append(1)
    return True if res[-1]==1 else False
if __name__=='__main__':
    m = int(input())
    for _ in range(m):
        blood = int(input())
        n,d,x,y = list(map(int,input().split()))
        t0, t1, t2 = list(map(int,input().split()))
        if get_money(blood):
            print('YES')
        else:
            print('NO')

发表于 2019-08-05 11:23:25 回复(0)
这题出的我服了,输入的技能和普攻是反过来的,怎么,看谁眼神好使是不?
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        int[] cold = new int[3];
        while (in.hasNextInt()) {// 注意while处理多个case
            int blood = in.nextInt();
            int creeps = in.nextInt();
            int attack1 = in.nextInt();
            int attack3 = in.nextInt();
            int attack2 = in.nextInt();
            int cold1 = in.nextInt();
            int cold2 = in.nextInt();
            int cold3 = in.nextInt();

            Arrays.fill(cold, 0);
            attack1 *= creeps;

            while (blood > 0) {
                 //System.out.printf("%d %d %d %d\n", blood, cold[0], cold[1], cold[2]);
                if (cold[0] == 0) {
                    blood -= attack1;
                    if (blood <= 0) {
                        System.out.println("NO");
                        break;
                    }
                    cold[0] = cold1;
                }
                if (cold[1] == 0) {
                    blood -= attack2;
                    if (blood <= 0) {
                        System.out.println("YES");
                        break;
                    }
                    cold[1] = cold2;
                }
                if (cold[2] == 0) {
                    blood -= attack3;
                    if (blood <= 0) {
                        System.out.println("YES");
                        break;
                    }
                    cold[2] = cold3;
                }
                int min = Arrays.stream(cold).min().getAsInt();
                for (int i=0;i<3;i++) {
                    cold[i] -= min;
                }
            }
        }
        in.close();

        return;
    }

}

发表于 2019-06-25 16:30:40 回复(5)
直接模拟攻击过程,只有英雄普通攻击和技能攻击了结防御塔才能够“YES”,其余都是“NO”
def judge(s, n, d, x, y, t0, t1, t2):
    t = 0     # 初始时间
    # 直接模拟对战,时间t分别能够整除t0、t1、t2的时候分别可以小兵攻击、英雄普通攻击和英雄技能攻击
    while s > 0:
        if t % t0 == 0:
            # 小兵可以攻击的时间
            s -= n*d
            if s <= 0:
                return "NO"
        if t % t1 == 0:
            # 普通攻击可以施展的时间
            s -= y
            if s <= 0:
                return "YES"
        if t % t2 == 0:
            # 技能可以施展的时间
            s -= x
            if s <= 0:
                return "YES"
        t += 1
    return "NO"


if __name__ == "__main__":
    T = int(input())
    for _ in range(T):
        s = int(input())
        n, d, x, y = map(int, input().strip().split())
        t0, t1, t2 = map(int, input().strip().split())
        print(judge(s, n, d, x, y, t0, t1, t2))
编辑于 2021-02-02 14:39:54 回复(0)
#include <bits/stdc++.h>
using namespace std;
int main(){
    int T,s,n,d,x,y,t0,t1,t2;
    cin>>T;
    for(int i=0;i<T;i++){
        cin>>s>>n>>d>>x>>y>>t0>>t1>>t2;
        int cd0=1,cd1=1,cd2=1;
        while(s>0){
            if(--cd0==0){
                if((s-=n*d)<=0){
                    cout<<"NO"<<endl;
                    break;
                }
                cd0=t0;
            }
            if(--cd1==0){
                if((s-=y)<=0){
                    cout<<"YES"<<endl;
                    break;
                }
                cd1=t1;
            }
            if(--cd2==0){
                if((s-=x)<=0){
                    cout<<"YES"<<endl;
                    break;
                }
                cd2=t2;
            }
        }
    }
    return 0;
}

发表于 2019-10-11 19:55:35 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] arg){
        Scanner sc=new Scanner(System.in);
        int T=sc.nextInt();
        for(int i=0;i<T;i++){
            int s=sc.nextInt();
            int n=sc.nextInt();
            int d=sc.nextInt();
            int x=sc.nextInt();
            int y=sc.nextInt();
            int t0=sc.nextInt();
            int t1=sc.nextInt();
            int t2=sc.nextInt();
            int time=0;
            while(s>0){
                if(time%t0==0){
                    if(s<=n*d){
                        //最后一次攻击为小兵
                        System.out.println("NO");
                        break;
                    }
                    s=s-n*d;
                }
                if(time%t1==0){
                    if(s<=y){
                        //最后一次攻击为普攻
                        System.out.println("YES");
                        break;
                    }
                    s=s-y;
                }
                if(time%t2==0){
                    if(s<=x){
                        //最后一次攻击为技能
                        System.out.println("YES");
                        break;
                    }
                    s=s-x;
                }
                time++;
            }
        }
    }
}
这题目长得我脑袋都乱了
发表于 2022-08-17 22:54:07 回复(0)
package main

import "fmt"

func main() {
    var T, s, n, d, x, y, t0, t1, t2 int
    fmt.Scan(&T)
    for i := 0; i < T; i++ {
        fmt.Scan(&s)
        fmt.Scan(&n, &d, &x, &y)
        fmt.Scan(&t0, &t1, &t2)
        time := 0
        for s > 0 {
            if time % t0 == 0 {
                s -= n * d
                if s <= 0 {
                    fmt.Println("NO")
                    break
                }
            }
            if time % t1 == 0 {
                s -= y
                if s <= 0 {
                    fmt.Println("YES")
                    break
                }
            }
            if time % t2 == 0 {
                s -= x
                if s <= 0 {
                    fmt.Println("YES")
                    break
                }
            }
            time++
        }
    }
}

发表于 2022-08-04 15:13:12 回复(0)
就没有D斯林出来震怒一下吗
发表于 2021-05-10 15:54:01 回复(0)
模拟法
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int t;//测试的数据组数
    cin>>t;
    while(t--){
        int s;//剩余血量
        cin>>s;
        int n,d,x,y;//n个小兵攻击为d,英雄的技能伤害为x、普通伤害为y
        cin>>n>>d>>x>>y;
        int t0,t1,t2;//小兵的冷却时间t0,普通伤害的冷却时间t1、技能伤害t2
        cin>>t0>>t1>>t2;
        int time=0;
        while(s>0){
            if(time % t0 == 0) {
               s -= n * d;
               if(s <= 0){
                  cout<<"NO"<<endl;
                  break;
               }
            }
            if(time % t1 == 0) {
               s -= y;
               if(s <= 0){
                  cout<<"YES"<<endl;
                  break;
               }
            }
            if(time % t2 == 0) {
               s -= x;
               if(s <= 0){
                  cout<<"YES"<<endl;
                  break;
               }
            }
            time++;
         }
    }
    return 0;
}
发表于 2020-09-02 22:23:00 回复(0)
不得不说,还是太年轻。题并不很难,却被困了好久。原因就是第一个while循环中,时间的加应该放在判断血量是否为0的后面,虽然看起来区别不大,但是先加就会导致即使第一个的break执行后,后面的while也成立,再执行就覆盖了正确答案了。良好的编程习惯太重要了。
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
    int s,n,d,x,y,t0,t1,t2;
    cin>>s;
    cin>>n>>d>>x>>y;
    cin>>t0>>t1>>t2;
    int re=0;
    int bt=0,xt=0,yt=0;
    while(s>0)
    {while(bt<=yt&&bt<=xt)
    { s=s-n*d;
     if(s<=0)
     {re=0;
     break;}
     bt+=t0;
    }
    while(xt<bt&&xt<=yt)
    { s=s-x;   
     if(s<=0)
     {re=1;
     break;}
     xt+=t2; 
    }
     while(yt<bt&&yt<=xt)
    { s=s-y;
     if(s<=0)
     {re=1;
     break;} 
     yt+=t1;
    }
    }
    if(re==0)
    {cout<<"NO"<<endl;}
    else
    {cout<<"YES"<<endl;}
    }
    
}

发表于 2020-08-22 10:53:28 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Main main = new Main();
        int T = Integer.parseInt(sc.nextLine());
        while(T-- > 0){
            int s = Integer.parseInt(sc.nextLine());
            String[] strs = sc.nextLine().split(" ");
            int[] hurt = new int[4];
            for(int i = 0; i < 4; i++){
                hurt[i] = Integer.parseInt(strs[i]);
            }
            strs = sc.nextLine().split(" ");
            int[] cd = new int[3];
            for(int i = 0; i < 3; i++){
                cd[i] = Integer.parseInt(strs[i]);
            }
            System.out.println(main.helper(s, hurt, cd));
        }

    }
    private String helper(int s, int[] hurt, int[] cd){
        PriorityQueue<Node> minHeap = new PriorityQueue<>(
                (a, b) -> a.t == b.t ? a.level - b.level : a.t - b.t);
        minHeap.add(new Node(0, 0, cd[0], hurt[0] * hurt[1], "NO"));
        minHeap.add(new Node(0, 1, cd[2], hurt[2], "YES"));
        minHeap.add(new Node(0, 1, cd[1], hurt[3], "YES"));

        while(true){
            Node node = minHeap.poll();
            s -= node.hurt;
            if(s <= 0){
                return node.out;
            }
            node.t += node.cd;
            minHeap.add(node);
        }
    }
    class Node{
        //下一次攻击的时间点
        int t;
        //优先级
        int level;
        //输出结果
        String out;
        //冷却时间
        int cd;
        //伤害
        int hurt;
        public Node(int t, int level, int cd, int hurt, String out){
            this.t = t;
            this.level = level;
            this.cd = cd;
            this.hurt = hurt;
            this.out = out;
        }
    }
}

发表于 2020-08-14 13:46:20 回复(0)
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int i=0; i<T; i++){
            int s = sc.nextInt();
            int n = sc.nextInt();
            int d = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            int t0 = sc.nextInt();
            int t1 = sc.nextInt();
            int t2 = sc.nextInt();
            int tm = 1;
            // 所有小兵的第一次攻击和英雄的第一次攻击在初始时刻同时进行,先处理
            s -= n*d;
            if(s<=0){
                System.out.println("NO");
                continue;
            }
            s -= (x+y);
            if(s<=0){
                System.out.println("YES");
                continue;
            }
            // 处理之后的攻击
            while(s > 0){
                if(tm%t0 ==0){
                    s -= n*d;
                    if(s<=0){
                        System.out.println("NO");
                        break;
                    }
                }
                if(tm%t1 ==0){
                    s -= y;
                    if(s<=0){
                        System.out.println("YES");
                        break;
                    }
                }
                if(tm%t2 ==0){
                    s -= x;
                    if(s<=0){
                        System.out.println("YES");
                        break;
                    }
                }
                tm++;
            }
        }
    }
}

发表于 2020-06-30 11:46:34 回复(0)
暴力模拟,大家的代码好简洁啊,我写的怎么这么繁琐?

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author wangda
 */
public class D塔2 {

    /** 小兵攻击冷却时间  */
    private int soldierCoolDownTime;
    /** 英雄技能攻击冷却时间 */
    private int heroSkillCoolDownTime;
    /** 英雄普通攻击冷却时间 */
    private int heroNormalCoolDownTime;

    /** 小兵数量 */
    private int soldierCount;
    /** 小兵攻击值 */
    private int soldierAttackValue;
    /** 英雄技能攻击值 */
    private int heroSkillAttackValue;
    /** 英雄普通攻击值 */
    private int heroNormalAttackValue;

    /** 生命力 */
    private int lifeForce = 0;


    /** 小兵攻击时间点 */
    private int soldierAttackTime = 0;
    /** 英雄技能攻击时间点 */
    private int heroSkillAttackTime = 0;
    /** 英雄普通攻击时间点 */
    private int heroNormalAttackTime = 0;


    /**
     * 英雄是否能得到奖励
     * @return true:能得到奖励  false:不能得到奖励
     */
    public boolean canHeroGetAward() {
        int timeAxis = 0;
        while(true) {
            // 小兵攻击
            if (timeAxis >= soldierAttackTime) {
                lifeForce = lifeForce - soldierCount*soldierAttackValue;
                soldierAttackTime = timeAxis + soldierCoolDownTime;
                if (lifeForce <= 0) {
                    return false;
                }
            }

            // 英雄技能攻击
            if (timeAxis >= heroSkillAttackTime) {
                lifeForce = lifeForce - heroSkillAttackValue;
                heroSkillAttackTime = timeAxis + heroSkillCoolDownTime;
                if (lifeForce <=0) {
                    return true;
                }
            }

            // 英雄普通攻击
            if (timeAxis >= heroNormalAttackTime) {
                lifeForce = lifeForce - heroNormalAttackValue;
                heroNormalAttackTime = timeAxis + heroNormalCoolDownTime;
                if (lifeForce <=0) {
                    return true;
                }
            }

            // 时间向前滚动
            timeAxis ++;
        }
    }

    /**
     * 解析参数
     * @param lifeForce 生命值
     * @param attackValue 攻击值
     * @param coolDownValue 冷却值
     */
    public void parse(String lifeForce, String attackValue, String coolDownValue) {
        this.lifeForce = Integer.parseInt(lifeForce);

        String[] attackArray = attackValue.split(" ");
        this.soldierCount = Integer.parseInt(attackArray[0]);
        this.soldierAttackValue = Integer.parseInt(attackArray[1]);
        this.heroSkillAttackValue = Integer.parseInt(attackArray[2]);
        this.heroNormalAttackValue = Integer.parseInt(attackArray[3]);

        String[] coolDownArray = coolDownValue.split(" ");
        this.soldierCoolDownTime = Integer.parseInt(coolDownArray[0]);
        this.heroNormalCoolDownTime = Integer.parseInt(coolDownArray[1]);
        this.heroSkillCoolDownTime = Integer.parseInt(coolDownArray[2]);
    }

    public static void main(String[] args) {
        // 读取数据
        try {
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader reader = new BufferedReader(isr);
            String groupNumStr = reader.readLine();
            int groupNum = Integer.parseInt(groupNumStr);
            for (int i = 0; i < groupNum; i++) {
                String lifeForceStr = reader.readLine();
                String attackValueStr = reader.readLine();
                String coolDownValueStr = reader.readLine();

                // 解析数据
                D塔2 o = new D塔2();
                o.parse(lifeForceStr, attackValueStr, coolDownValueStr);

                // 执行程序
                boolean canGet = o.canHeroGetAward();
                System.out.println(canGet? "YES": "NO");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

}



发表于 2020-06-27 13:23:58 回复(0)
Java 30行以内代码。思路,统计不同兵种的累计冷却时间,按照累计冷却时间排序(根据题意,小兵时间和英雄时间相同小兵排前面), 时间越短的可以越先完成冷却,再次进行攻击,每次攻击后,增加一次该兵种的冷却时间,从新按照累计冷却时间排序,重复操作,直到某次攻击使得塔血量为0,记录该兵种。
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- > 0) {
            int s = sc.nextInt();
            int n = sc.nextInt(), d = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();
            int t0 = sc.nextInt(), t1 = sc.nextInt(), t2 = sc.nextInt();
            int[][] a = new int[3][4];//伤害值, 累计时间, id(区分小兵和英雄), 冷却时间
            a[0][0] = d*n; a[0][1] = 0; a[0][2] = 0; a[0][3] = t0;// 小兵
            a[1][0] = x; a[1][1] = 0; a[1][2] = 1; a[1][3] = t2;//技能
            a[2][0] = y; a[2][1] = 0; a[2][2] = 2; a[2][3] = t1;// 普通攻击
            boolean isH = true;
            while(s > 0) {
                Arrays.sort(a, (o1, o2)-> o1[1] == o2[1] ? o1[2] - o2[2] : o1[1] - o2[1]);
                s -= a[0][0]; a[0][1] += a[0][3];
                if(s <= 0 && a[0][2] == 0) 
                    isH = false;
            }
            if(!isH) 
                System.out.println("NO");
            else
                System.out.println("YES");
        }
    }
}




编辑于 2020-06-23 18:06:32 回复(0)
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <sstream>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
int main(){
    int T;
    cin>>T;
    while (T){
        int s;
        cin>>s;
        int n,d,x,y;
        int t0,t1,t2;
        cin>>n>>d>>x>>y>>t0>>t1>>t2;
        if(n*d >= s){
            cout<<"NO"<<endl;
        }else if(n*d+x+y >= s){
            cout<<"YES"<<endl;
        }else{
            s -= n*d+x+y;
            int num = 1;
            int res = false;
            while(1){
                if(num%t0 == 0){
                    s -= n*d;
                    if(s <= 0)
                        break;
                }
                if(num%t2 == 0){
                    s -= x;
                    if(s <= 0) {
                        res = true;
                        break;
                    }
                }
                if(num%t1 == 0){
                    s -= y;
                    if(s <= 0) {
                        res = true;
                        break;
                    }
                }
                ++num;
            }
            if(res)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
        --T;
    }
    return 0;
}




发表于 2020-06-07 15:19:17 回复(1)
这题输入数据的方式真叫人服了,害我排bug排了好久。。。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author: coderjjp
 * @Date: 2020-05-11 17:07
 * @Description: D塔2
 * @version: 1.0
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        int s, n, d, x, y, t0, t1, t2;
        String[] line3, line4;
        while (T-- > 0){
            s = Integer.parseInt(br.readLine());
            line3 = br.readLine().split(" ");
            n = Integer.parseInt(line3[0]);
            d = Integer.parseInt(line3[1]);//小兵攻击
            int nd = n*d;
            x = Integer.parseInt(line3[2]);//技能攻击
            y = Integer.parseInt(line3[3]);//普通攻击
            line4 = br.readLine().split(" ");
            t0 = Integer.parseInt(line4[0]);
            t1 = Integer.parseInt(line4[1]);
            t2 = Integer.parseInt(line4[2]);
            int c0 = 0, c1 = 0, c2 = 0;
            while (true){
                if (c0 == 0){
                    s -= nd;
                    c0 += t0;
                    if (s <= 0){
                        System.out.println("NO");
                        break;
                    }
                }
                if (c1 == 0){
                    s -= x;
                    c1 += t2;
                }
                if (c2 == 0){
                    s -= y;
                    c2 += t1;
                }
                if (s <= 0){
                    System.out.println("YES");
                    break;
                }
                int min = Math.min(Math.min(c0, c1), c2);
                c0 -= min;
                c1 -= min;
                c2 -= min;
            }
        }
    }
}


发表于 2020-05-11 17:56:27 回复(0)
#include <bits/stdc++.h>
using namespace std;

struct Attack
{
    int type; // 0 solid, 1 xiaoming simple, 2 xiaoming special
    int attack_time;
    int damage;
    Attack(int x, int y, int z): type(x), attack_time(y), damage(z) {}
};

struct cmp
{
    bool operator()(const Attack &a, const Attack &b)
    {
        if(a.attack_time == b.attack_time) return a.type>b.type;
        return a.attack_time > b.attack_time;
    }
};

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int s;
        cin>>s;
        int n, d, x, y;
        cin>>n>>d>>x>>y;
        int t0, t1, t2;
        cin>>t0>>t1>>t2;
        priority_queue<Attack, vector<Attack>, cmp> P;
        P.push(Attack(0, 0, n*d)), P.push(Attack(1, 0, y)), P.push(Attack(2, 0, x));
        int sum = 0;
        while(sum < s)
        {
            Attack t = P.top();
            P.pop();
            sum += t.damage;
            if(sum>=s)
            {
                if(t.type==0) cout<<"NO"<<endl;
                else cout<<"YES"<<endl;
                break;
            }
            int cur_time = 0;
            if(t.type==0) cur_time = t.attack_time + t0;
            else if(t.type==1) cur_time = t.attack_time + t1;
            else if(t.type==2) cur_time = t.attack_time + t2;
            Attack r = Attack(t.type, cur_time, t.damage);
            P.push(r);
        }
    }
    return 0;
}

发表于 2019-12-26 19:29:08 回复(0)
def my_cmp(h1,h2):
    if cmp(h1[0],h2[0])!=0:
        return cmp(h1[0],h2[0])
    else:
        return cmp(h1[2],h2[2])

case_num=input()
for i in range(case_num):
    s=input()
    n,d,x,y=map(int,raw_input().strip().split(' '))
    t=map(int,raw_input().strip().split(' '))
    q=[]
    q.append((0,n*d,0))
    q.append((0,x,1))
    q.append((0,y,2))
    
    while s>0:
        now,hurt,name=q[0]
        del(q[0])
        s-=hurt
        if s<=0:
            if name == 0:
                print 'NO'
            else:
                print 'YES'
            break
        else:
            q.append((now+t[name],hurt,name))
        q.sort(cmp=my_cmp)

利用队列的思想,但是卡在一个数据点上不知道为什么
数据点如下
2818
2 18 3 18
30 12 36
希望能有大佬解答下
发表于 2019-10-13 21:58:52 回复(0)
对每个时间点,判断小兵和英雄的攻击是否发动。若小兵攻击后血量不大于0,则NO,若英雄攻击后血量不大于0,则YES。
T = int(input())
for _ in range(T):
    s = int(input())
    n,d,x,y = map(int,input().split())
    t0,t1,t2 = map(int,input().split())
    t = 0
    while 1:
        if t%t0 == 0:
            s -= n*d
        if s <=0:
            print('NO')
            break
        if t%t1 == 0:
            s -= y
        if t%t2 == 0:
            s -= x
        if s <=0:
            print('YES')
            break
        t += 1


发表于 2019-09-10 22:39:34 回复(0)
看了前排的提交答案,为什么每次普通攻击和技能能同时释放的时候就一定是一起释放呢??
比如输入
1
8
3 1 2 1
1 1 2

剩余8血;3小兵,每个小兵1攻击机,英雄技能伤害2,冷却时间2;普通攻击1,冷却1;

方案1: 小兵攻击8-3=5;  英雄普通攻击和技能一起上:5-1-2=2; 小兵再次攻击 2-3<0  输出NO

方案2: 小兵攻击8-3=5;  英雄普通攻击: 5-1=4; 小兵攻击:4-3=1;英雄普通攻击/技能攻击都可以:1-1=0/1-2<0   输出YES

看了C++第一名的答案,感觉不太对啊,求大佬解释一下
发表于 2019-07-24 15:59:08 回复(3)