# 蓝桥算法训练营—普及组—2023年2.9日

3 篇文章 0 订阅

## P1781 宇宙总统

https://www.luogu.com.cn/problem/P1781

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 idx = -1;
String ans = "0";
for (int i = 1; i <= n; i++) {
int len = ss.length(), m = ans.length();
if (len > m) {
idx = i;
ans = ss;
} else if (len < m) {
continue;
} else if (ss.compareTo(ans) > 0){
idx = i;
ans = ss;
}

}
out.println(idx);
out.println(ans);

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


## P1223 排队接水

https://www.luogu.com.cn/problem/P1223

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[][] arr = new int[n][2];
for (int i = 0; i < n; i++) {
arr[i][0] = i + 1;
arr[i][1] = Integer.parseInt(ss[i]);
}
Arrays.parallelSort(arr, (a, b) -> (a[1] - b[1]));
double tot = 0, cur = 0;
for (int i = 0; i < n; i++) {
out.print(arr[i][0] + " ");
tot += cur;
cur += arr[i][1];
}
out.printf("\n%.2f", tot / n);

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


## P3817 小A的糖果

https://www.luogu.com.cn/problem/P3817

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 = Integer.parseInt(nx[0]), x = Integer.parseInt(nx[1]);
int[] arr = new int[n];
long ans = 0;
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(ss[i]);
if (i > 0 && arr[i] + arr[i - 1] > x) {
ans += arr[i] - x + arr[i - 1];
arr[i] = x - arr[i - 1];
}
}

out.println(ans);

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


## P1007 独木桥

https://www.luogu.com.cn/problem/P1007

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 mn = 0, mx = 0;
String[] ss = null;
if (n > 0) ss = in.readLine().split(" ");
for (int i = 0; i < n; i++) {
int t = Integer.parseInt(ss[i]);
mn = Math.max(mn, Math.min(t, l + 1 - t));
mx = Math.max(mx, Math.max(t, l + 1 - t));
}
out.println(mn + " " + mx);

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

• 1
点赞
• 0
收藏
觉得还不错? 一键收藏
• 打赏
• 0
评论
10-21
12-23
10-17
01-12
12-14
03-31
08-05
01-18
08-03
01-07
03-11

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

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

⠀One0ne

¥2 ¥4 ¥6 ¥10 ¥20

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