【2020-BNUZ-IT节程序设计竞赛网络赛题解】E. 因为感觉打不过就全点速度与攻击了
题面
题目大意
小陈由于血量很低,所以只能在「无敌金身」的10秒内击败敌人,否则就会被打败。给你一组敌人的血量,问你能不能打败敌人。
题目思路
首先,此题的思路就是找到最大的总攻击值,只要敌人血量小于等于最大总攻击值,就会被击败。
假设使用如下情况:
使用「无敌金身」「超加速」:10回合造成伤害10x100x70x120%=84000
使用「无敌金身」「超加速」「光速神言」触发「虚影」:咏唱5回合,剩下5回合造成伤害5x100x2x70x170%=119000
明显是第二种造成伤害更多,所以我们只需要以第二种情况作为区分即可
容易卡住的点
题目太长不想读,以为是难题- cin,cout导致超时
- 开了数组,并且因为数组开小了,导致运行时错误
- 开了动态数组导致超时
- 判断条件太多导致超时
题解
了解完这些之后,题目就变得很简单了
C 语言代码
#include<stdio.h>
int main(){
int T;
scanf("%d",&T);
for(int o=0;o<T;o++){
int n;
scanf("%d",&n);
printf("Case #%d:\n",o+1);
int a;
for(int i=0;i<n;i++){
scanf("%d",&a);
if(a<=119000)
printf("Yes\n");
else
printf("No\n");
}
}
return 0;
}
C++代码
C++能过吗,cin,cout能用吗,能
#include <iostream>
#include<cstdio>
using namespace std;
int main(){
int T;
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>T;
for(int o=0;o<T;o++){
int n;
cin>>n;
cout<<"Case #"<<o+1<<":\n";
int a;
for(int i=0;i<n;i++){
cin>>a;
if(a<=119000)
cout<<"Yes\n";
else
cout<<"No\n";
}
}
return 0;
}
Java代码
由于Scanner耗费时间过长,这里我们需要用到快读
import java.io.*;
import java.util.StringTokenizer;
import java.math.BigInteger;
public class Test4 {
public static void main(String[] args) {
InputStream inputStream = System.in;//InputStream是表示字节输入流的所有类的超类
OutputStream outputStream = System.out;
//InputStream与System 没有关系.System.in是System 这个类的静态变量,只是in是InputStream类型的
InputReader sc = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(sc, out);//这里当作原来的Main函数,输入输出都在里面解决
out.close();//关闭输出流
}
static class Task {
public void solve(InputReader scan, PrintWriter out) {
int t=scan.nextInt();
for(int i=0;i<t;i++) {
out.printf("Case #%d:\n",i+1);
int n=scan.nextInt();
while(n!=0) {
int a=scan.nextInt();
if(a<=119000){
out.println("Yes");
}else{
out.println("No");
}
n--;
}
}
// out.println(ans);//输出答案
}
}
//自己写出Scanner原本的输入语法,封装在InputReader类里
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
//32768是输入缓冲区大小,随便设的
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public boolean hasNext() {
try {
String string = reader.readLine();
if (string == null) {
return false;
}
tokenizer = new StringTokenizer(string);
return tokenizer.hasMoreTokens();
} catch (IOException e) {
return false;
}
}
public BigInteger nextBigInteger() {//大数
return new BigInteger(next());
}
}
}
//加速板参照 https://www.cnblogs.com/shoulinniao/p/12113790.html
python代码
T = int(input())
for i in range(T):
n = int(input())
print("Case #{}:".format(i+1))
a = input().split()
for ii in a:
if int(ii) <= 119000:
print("Yes")
else:
print("No")
题后语
看过题数据的时候,看到有人居然用了C++的速读版写这题
QwQ,果然大佬就是大佬,可能第一发写cin,然后自闭了
这题真的是简单题,之前出的题都太难没人写,这次想着出简单点,过题人数感觉还行,很多同学都很有想法,优秀