首页 > 试题广场 >

D塔2

[编程题]D塔2
  • 热度指数:2659 时间限制: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
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)
这题输入数据的方式真叫人服了,害我排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)