行业知识
蓝桥杯算法赛 第 6 场 小白入门赛 解题报告 | 珂学家 | 简单场 + 元宵节日快乐
前言
整体评价
��为适逢元宵节,所以这场以娱乐为主。
A. 元宵节快乐
题型: 签到
节日快乐,出题人也说出来自己的心愿, 祝大家AK快乐!
import java.util.Scanner;public class Main { public static void main(String[] args) { System.out.println("Today AK!"); }} B. 猜灯谜
思路: 模拟
按题意模拟即可,环状结构
import java.io.BufferedInputStream;import java.util.ArrayList;import java.util.List;import java.util.Scanner;import java.util.stream.Collectors;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i
C. 数学奇才
思路: 思维题
可以贪心逆序从右到左翻转,每次翻转保证最右的非负数多一项,题意保证最多有n次。
所以,必然存在操作序列,使得数组元素全变非负形态。
∑ i = 0 i = n − 1 a b s ( a i ) \sum_{i=0}^{i=n-1} abs(a_i) i=0∑i=n−1abs(ai)
import java.io.BufferedInputStream;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); int n = sc.nextInt(); long[] arr = new long[n]; long sum = 0; for (int i = 0; i
D. 你不干?有的是帕鲁干
思路: 解方程
假设第一个元素为y, 那么
( y + 2 ) 2 − y 2 = 4 ( y + 1 ) = x (y + 2) ^ 2 - y ^ 2 = 4(y + 1) = x (y+2)2−y2=4(y+1)=x
那么该y为
y = x / 4 − 1 y=x/4 - 1 y=x/4−1
这边需要保证x是4的倍数,同时y必须为>=1的奇数
import java.io.BufferedInputStream;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); int t = sc.nextInt(); while (t-- > 0) { long x = sc.nextLong(); if (x % 4 != 0) { System.out.println("No"); } else { long y = x / 4 - 1; if (y System.out.println("No"); } else { System.out.println("Yes"); System.out.println((y) + " " + (y + 2)); } } } }} public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); int n = sc.nextInt(); int[] arr = new int[n]; int[] brr = new int[n]; for (int i = 0; i
上一篇:苹果服务器怎么断开网络?
下一篇:公司域名怎么回事?