A.OP
题目:
现在请你喊出某次神秘活动中的口号"fengqibisheng, yingyueerlai!"(不包含引号)。
思路:
这道题输出这句话就行
B.Add 9 Zeros
题目:
题意就是将数组A中的数加9后拿到B中,要求加9后在A数组中不存在。
思路:
排序后用双指针扫描,判断两个数的差值是不是7。注意要优化一下,那种两个数的差已经大于9了就不要再往后扫描了。
代码:
点击查看代码
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n;i++) {
arr[i] = scanner.nextInt();
}
Arrays.sort(arr);
int count = n;
for(int i = 0;i < n;i++) {
if(arr[i]+9>arr[n-1]) {//非常关键
break;
}
for(int j = i+1;j < n;j++) {
if(arr[j]-arr[i]>9) {
break;
}
if(arr[j]-arr[i]==9) {
count--;
break;
}
}
}
System.out.println(count);
}
}
C.Simple Game
题目:
题意:输入几个数,单个数Alice来加,双个数Bob来加,看他们的和是奇数还是偶数
思路:
首先加起来,然后判断即可
代码:
用java写会超时,同样的思路用C++写不会超时。
点击Java查看代码
import java.util.Scanner;
public class MainJ {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int S1 = 0;
int S2 = 0;
for(int i = 1;i<n+1;i++) {
if(i%2==1) {
S1+=scanner.nextInt();
}else {
S2+=scanner.nextInt();
}
}
if(Math.abs(S1-S2)%2==0) {
System.out.println("Bob");
}else {
System.out.println("Alice");
}
}
}
点击C++查看代码
#include<cstdio>
#include<iostream>
#include <algorithm>
using namespace std;
const int N = 1000010;
int n;
int q[N];
int main(){
int s1,s2;
scanf("%d",&n);
for(int i = 1;i<n+1;i++) {
if(i%2==1) {
scanf("%d",&q[i]);
s1+=q[i];
}else {
scanf("%d",&q[i]);
s2+=q[i];
}
}
if(abs(s1-s2)%2!=0){
printf("Bob");
}else{
printf("Alice");
}
return 0;
}
D.Elden Ring
题目:
题意:两个长度相同的数组,到报数是两个m的倍数的时候,两个数组的当前值交换。
思路:
代码:
点击查看代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int k = scanner.nextInt();
int[] a = new int[n];
int[] b = new int[n];
a[0] = n;
b[0] = 2*n;
for(int i = 1;i < n;i++) {
a[i] = i;
b[i] = n+i;
}
int j = 0;
for(int i = 1;i <= k;i++) {
if(i%m==0) {
j = i%n;
int temp = a[j];
a[j] = b[j];
b[j] = temp;
}
}
for(int i = 1;i < n;i++) {
System.out.print(a[i]+" ");
}
System.out.print(a[0]+" ");
for(int i = 1;i < n;i++) {
System.out.print(b[i]+" ");
}
System.out.print(b[0]+" ");
}
}
E.Steel of Heart
思路:
这道题按照题目给的思路来,我的做法是把没有用的操作都先去掉,然后再来计算。
代码:
点击查看代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int h1 = scanner.nextInt();
int h2 = scanner.nextInt();
int m = scanner.nextInt();
String[] str = new String[m];
String[] str1 = new String[m];
int[] arr = new int[m];
int[] arr1 = new int[m];
int[] arr2 = new int[m];
boolean[] coolingone = new boolean[6];
for(int i = 0 ;i < m;i++) {
str[i] = scanner.next();
arr[i] = scanner.nextInt();
if(arr[i] == 3) {
arr1[i] = scanner.nextInt();
}
}
int[] beforemm = new int[6];
int[] beforess = new int[6];
int mm = 0;
int count = 0;
int ss = 0;
boolean flag = false;
for(int i = 0;i < m;i++) {
if(arr[i] == 1) {
str1[count] = str[i];
arr2[count] = arr[i];
count++;
flag = true;
}
if(arr[i]==2) {
str1[count] = str[i];
arr2[count] = arr[i];
count++;
}
if(arr[i] == 3&&flag) {
mm = Integer.parseInt(""+str[i].charAt(0)+str[i].charAt(1));
ss = Integer.parseInt(""+str[i].charAt(3)+str[i].charAt(4));
if(!coolingone[arr1[i]]) {
str1[count] = str[i];
arr2[count] = arr[i];
count++;
beforess[arr1[i]] = ss+30;
beforemm[arr1[i]] = mm;
if(beforess[arr1[i]]>=60) {
beforemm[arr1[i]] = mm+1;
beforess[arr1[i]] -= 60;
}
coolingone[arr1[i]] = true;
}else {
if(mm<beforemm[arr1[i]]||(mm==beforemm[arr1[i]]&&ss<beforess[arr1[i]])) {
break;
}else {
str1[count] = str[i];
arr2[count] = arr[i];
count++;
beforess[arr1[i]] = ss+30;
beforemm[arr1[i]] = mm;
if(beforess[arr1[i]]>=60) {
beforemm[arr1[i]] = mm+1;
beforess[arr1[i]] -= 60;
}
coolingone[arr1[i]] = true;
}
}
}
}
for(int i = 0;i < count;i++) {
if(arr2[i]==1) {
h1+=800;
}else if(arr2[i]==2) {
h1+=h2;
}else if(arr2[i]==3) {
h1+=(h1*0.06+125)*0.1;
}
}
System.out.println(h1);
}
}