蓝桥算法训练营—普及组—2023年2.5日（Java）

3 篇文章 0 订阅

接金币

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

static StreamTokenizer st = new StreamTokenizer(in);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

public static void main(String[] args) throws Exception{

while (t-- > 0) {
// 测试用例中会有空行，加一下判断
int n = Integer.parseInt(s);

int[][] arr = new int[n][2];
for (int i = 0; i < n; i++) {
arr[i][0] = Integer.parseInt(ss[0]);
arr[i][1] = Integer.parseInt(ss[1]);
}
Arrays.sort(arr, (a, b) -> (a[1] - b[1]));
int cur = 0, time = 0;
boolean flag = false;
for (int i = 0; i < n; i++) {
if (Math.abs(cur - arr[i][0]) > arr[i][1] - time) {
flag = true;
break;
}
cur = arr[i][0];
time = arr[i][1];
}
if (flag) {
out.println("Notabletocatch");
} else {
out.println("Abletocatch");
}
}

out.flush();
in.close();
}
}


又是毕业季I

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

static StreamTokenizer st = new StreamTokenizer(in);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

public static void main(String[] args) throws Exception{

out.println(Integer.parseInt(ss[0]) / Integer.parseInt(ss[1]));

out.flush();
in.close();
}
}


删数问题

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

static StreamTokenizer st = new StreamTokenizer(in);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

public static void main(String[] args) throws Exception{

int n = ch.length;
StringBuilder sb = new StringBuilder();
int st = -1;
for (int i = 0; i < n - k; i++) {
char c = '9';
for (int j = st + 1; j <= k + i; j++) {
if (ch[j] < c) {
c = ch[j];
st = j;
}
}
sb.append(c);
}
int idx = 0, len = sb.length();
// 去除前导0
while (idx < len && sb.charAt(idx) == '0') idx++;
String ans = sb.substring(idx);
// 判断去除前导0后为空字符串的情况
if (!ans.equals(""))out.println(ans);
else out.print("0");

out.flush();
in.close();
}
}


谈判

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

static StreamTokenizer st = new StreamTokenizer(in);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

public static void main(String[] args) throws Exception{

PriorityQueue<Long> pq = new PriorityQueue<>();

for (int i = 0; i < n; i++) {
st.nextToken();
pq.offer((long)st.nval);
}
long ans = 0L;
while (pq.size() > 1) {
long a = pq.poll(), b = pq.poll();
ans += a + b;
pq.offer(a + b);
}

out.println(ans);

out.flush();
in.close();
}
}

• 1
点赞
• 1
收藏
觉得还不错? 一键收藏
• 0
评论
04-30 4088
04-08 6566
02-09 5377
03-06 4474
02-22 4423
02-06 2756
04-12 5386
02-07 612
07-10 1276
07-12 202

“相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。