A.Who is The 19th ZUCCPC Champion
签到题,输出即可。
B.Jiubei and Overwatch
题目:
Jiubei loves playing Overwatch even if it is a long time since the last update. Now he is using a damage skill to kill enemies.
The skill will damage all enemies simultaneously and the damage is determined by the time Jiubei charges this skill. The skill has a charging period division number kk, and two damage increase numbers x,yx,y. If he charged for tt seconds, the damage is calculated as follows:
If t≤k, the damage is t×x.
Otherwise, the damage is k×x+(t−k)×y.
Jiubei has nn enemies, and the ii-th enemy's health is aiai.
Please tell Jiubei how long it takes to charge his skill to kill all of his enemies. Note that the skill can only be used once.
Additionally, an enemy is killed if and only if his health is not greater than the damage he/she take.
思路:
首先找到能够承受伤害最大的敌人,然后再分两种情况求解t。如果前面伤害高的时候就能够击败,就直接用前面的公式计算就可以了。
代码:
点击查看代码
import java.util.Scanner;
public class MainB {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while(T-->0) {
int n = scanner.nextInt();
int k = scanner.nextInt();
int x = scanner.nextInt();
int y = scanner.nextInt();
int max = 0;
int now = 0;
for(int i = 0;i < n;i++) {
now = scanner.nextInt();
if(now>max) {
max = now;
}
}
int t=0;
if(x*k>max) {
t = max/x;
if(max%x!=0) {
t++;
}
}else {
max = max -k*x;
t = k+max/y;
if(max%y!=0) {
t++;
}
}
System.out.println(t);
}
}
}
C.Ah, It's Yesterday Once More
题目:
Boboge remembers The 2021 ICPC Asia Nanjing Regional Contest, Problem D. The problem gives you an array a and asks you how many times the expression "Swap ai and aj" has been executed if you call Sort(a) which is implemented by the following Algorithm 1.
As the algorithm looks quite like the normal bubble sort, Boboge wants you to construct a permutation of length n as the array a, so that the number of times the expression "Swap ai and aj" has been executed equals to the number of times the expression "Swap aj and aj+1" has been executed when we call Sort(a) and BubbleSort(a) respectively.
A permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4,5] is also not a permutation (n=4 but there is 5 in the array).
思路:
这道题逆序输出即可。
代码:
点击查看代码
import java.util.Scanner;
public class MainC {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while(T-->0) {
int n = scanner.nextInt();
for(int i = n;i>0;i--) {
System.out.print(i+" ");
}
System.out.println();
}
}
}
F.Sum of Numerators
题目:
给出两个数k和n,给一个序列,分子是1到n,分母是2的k次方,求约分后所有分子的和。
例如:
思路:
首先把没有约分的全部加起来,然后减去一些约分过后的就能得到结果。这种方式用java写会超时,用C++写不会。
代码:
点击查看代码
import java.util.Scanner;
public class MainF {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while(T-->0) {
long n = scanner.nextLong();
long k = scanner.nextLong();
long sum = n*(n+1)/2;
while(n>0 && k>0){
n >>= 1;
sum -= n*(n+1)/2;
k--;
}
// long m = n;
// sum += m*(m+1)/2;
System.out.println(sum);
}
}
}