# 结果填空题

## A

97 + 99 + 99 + 97 + 98 = 490 选法不唯一， 和唯一。

## B

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

public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);

HashSet<String> res = new HashSet<String>();
String s = in.nextLine();
int n = s.length();
for(int i = 0; i < n; i++){
for(int j = i+1; j <= n; j++){
}
}

System.out.println(res.size());
}
}


## C

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

public class Main{
public static void main(String[] args){
int first = 1, second = 1, third = 1;
int res = 0;
for(int i = 4; i <= 20190324; i++){
res = (first + second + third)%10000;
first = second;
second = third;
third = res;
}
System.out.println(res);
}
}


## D

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

public class Main{
public static Boolean find(int x){
while(x != 0){
if(x%10 == 2 || x%10 == 4){
return true;
}
x /= 10;
}
return false;
}

public static void main(String[] args) throws IOException{
File file = new File("E:\\output.txt");

if(file.exists())
file.createNewFile();				//如果指定文件不存在，新建文件

BufferedWriter out = new BufferedWriter(new FileWriter(file));
long sum = 0;
for(int i = 1; i <= 2019; i++)
{
if(find(i))	continue;

for(int j = i+1; j + i <= 2019; j++)
{
if(find(j)) continue;

for(int k = j+1; k + j <= 2019; k++)
{
if(find(k)) continue;

if(i + j + k == 2019){
sum++;
out.write(i + " " + j + "  " + k+ "\n");
}
}
}
}

out.close();
System.out.print(sum);
}
}



## E

01010101001011001001010110010110100100001000101010
00001000100000101010010000100000001001100110100101
01111011010010001000001101001011100011000000010000
01000000001010100011010000101000001010101011001011
00011111000000101000010010100010100000101100000000
11001000110101000010101100011010011010101011110111
00011011010101001001001010000001000101001110000000
10100000101000100110101010111110011000010000111010
00111000001010100001100010000001000101001100001001
11000110100001110010001001010101010101010001101000
00010000100100000101001010101110100010101010000101
11100100101001001000010000010101010100100100010100
00000010000000101011001111010001100000101010100011
10101010011100001000011000010110011110110100001000
10101010100001101010100101000010100000111011101001
10000000101100010000101100101101001011100000000100
10101001000000010100100001000100000100011110101001
00101001010101101001010100011010101101110000110101
11001010000100001100000010100101000001000111000010
00001000110000110101101000000100101001001000011101
10100101000101000000001110110010110101101010100001
00101000010000110101010000100010001001000100010101
10100001000110010001000010101001010101011111010010
00000100101000000110010100101001000001000000000010
11010000001001110111001001000011101001011011101000
00000110100010001000100000001000011101000000110011
10101000101000100010001111100010101001010000001000
10000010100101001010110000000100101010001011101000
00111100001000010000000110111000000001000000001011
10000001100111010111010001000110111010101101111000

1. 首先解决字典序最小的问题，字典序 D < < L < < R < < U
所以为了使字典序最小，我们要按照D L R U的先后顺寻来搜索。

2. 搜索的时候用一个数组记录一下当前点是由哪个点转移过来的。
最后从出口倒推到入口就可以了。

3. 因为是地图是二维的，所以要保存上一个点的横坐标和纵坐标，可以写一个pair类，并创建为二维数组，例如：pre[nx][ny].x = i, pre[nx][ny].y = j表示点（nx, ny）由（i, j）走过来。

或者直接开个三维数组，第三维大小开2，分别表示横坐标和纵坐标。
例如：pre[nx][ny][0] = i, pre[nx][ny][1] = j表示点（nx, ny）由（i, j）走过来。

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

public class Main{
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

static final int N = 1005;
static int n, m;
static int[][] g = new int[N][N], st = new int[N][N], q = new int[N*N][2];
static int[][][] pre = new int[N][N][2];

public static int Int(String s){
return Integer.parseInt(s);
}

public static void bfs(int i, int j) throws IOException{
int[] dx = {1, 0, 0, -1}; // 下 左 右 上
int[] dy = {0, -1, 1, 0};

int h = 0, t = 0;
q[t][0] = i; q[t++][1] = j;

st[i][j] = 1;
while(h != t){
int x = q[h][0], y = q[h++][1];

for(int l = 0; l < 4; l++){
int nx = x + dx[l];
int ny = y + dy[l];

if(nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
if(g[nx][ny] == 1) continue;
if(st[nx][ny] == 1) continue;

q[t][0] = nx; q[t++][1] = ny;
st[nx][ny] = 1;

pre[nx][ny][0] = x; pre[nx][ny][1] = y;
if(nx == n-1 && ny == m-1) return ;
}
}
}

public static void main(String[] args) throws Exception{
String[] ss = in.readLine().split(" ");
n = Int(ss[0]);
m = Int(ss[1]);

for(int i = 0; i < n; i++){
String s = in.readLine();

for(int j = 0; j < s.length(); j++)
g[i][j] = Int(String.valueOf(s.charAt(j)));
}

bfs(0, 0);

int i = n-1, j = m-1; // 从出口回溯到入口。
String res = "";

while(i != 0 || j != 0){

if(i - pre[i][j][0] == 0){ // x不变，说明是向左或者向右。
if(j - pre[i][j][1] == 1) // 3 2 -> 3 3 说明上一个点是通过向右走到达(i,j)
res = "R" + res;
else
res = "L" + res; // 向左
}
else{
if(i - pre[i][j][0] == 1) // 2 3 -> 3 3 说明上一个点是通过向下走到达(i,j)
res = "D" + res;
else
res = "U" + res; // 向上
}

int t = i;
i = pre[i][j][0];
j = pre[t][j][1];
}
out.write(res);
out.flush();
}
}


DDDDRRURRRRRRDRRRRDDDLDDRDDDDDDDDDDDDRDDRRRURRUURRDDDDRDRRRRRRDRRURRDDDRRRRUURUUUUUUULULLUUUURRRRUULLLUUUULLUUULUURRURRURURRRDDRRRRRDDRRDDLLLDDRRDDRDDLDDDLLDDLLLDLDDDLDDRRRRRRRRRDDDDDDRR


# 程序设计题

## F

AC代码：

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

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

Scanner in = new Scanner(System.in);
int n = in.nextInt();

int res = 0;
for(int i = 1; i <= n; i++){
int x = i;
while(x != 0){
int r = x % 10;
if(r == 0 || r == 1 || r == 2 || r == 9){
res += i;
break;
}
x /= 10;
}
}

System.out.print(res);
}
}


## G

AC代码：

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

public class Main{
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

static int[][] arr = new int[100005][2];
static int[] score = new int[100005];
static int[] st = new int[100005];
public static int Int(String s){
return Integer.parseInt(s);
}

public static void main(String[] args) throws Exception{
String[] s = in.readLine().split(" ");
int N = Int(s[0]);
int M = Int(s[1]);
int T = Int(s[2]);

for(int i = 0; i < M; i++){
String[] ss = in.readLine().split(" ");
arr[i][0] = Int(ss[0]);
arr[i][1] = Int(ss[1]);
}

Arrays.sort(arr, 0, M, new Comparator<int[]>(){
public int compare(int[] a, int[] b){
if(a[0] == b[0]) return a[1] - b[1];
return a[0] - b[0];
}
});

int[] last = new int[100005];
TreeSet<Integer> set = new TreeSet<>();
for(int i = 0; i < M && arr[i][0] <= T; i++){// 处理M条信息，记录每家店的最后接单时间。初始为0

int time = arr[i][0];
int id = arr[i][1];

if(time - last[id] > 1)
score[id] -=  (time - last[id] - 1);
if(score[id] < 0) score[id] = 0;
if(score[id] <= 3) st[id] = 0;  // 要先置为false 否则如果先降到了3再加上2
// 虽然大于3，但不大于5
score[id] += 2;

if(score[id] > 5) st[id] = 1;

last[id] = time; // 记录某家店的最后接单时刻。
//out.write(score[id] + "\n");
}

int num = 0;
for(int i : set){
//out.write("s: " + score[i] + " last: "+ last[i] + "  T: "+ T + "\n");
if(last[i] < T)
score[i] -= (T - last[i]);

if(score[i] <= 3)
st[i] = 0;
if(st[i] == 1) num ++;
}

out.write(num +"");
out.flush();
}
}


## H

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

public class Main{
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

static final int N = 1000010;
static String s;
static int[] A = new int[N], B = new int[N];
static int n, cnta, cntb;

public static boolean chack(int i){
if(i < 0 || i >= n)
return false;
char c = s.charAt(i);
return c >= 'a' && c <= 'Z' || c >= 'A' && c <= 'Z';
}

public static int findl(int x) throws IOException{ // 大于等于 x 的最小值
int l = 0, r = cntb - 1;
while(l < r){
int mid = l + r>> 1;

if(B[mid] >= x) r = mid;
else l = mid + 1;
}
return l;
}

public static int findr(int x) throws IOException{
int l = 0, r = cntb - 1;
while(l < r){
int mid = l + r + 1 >> 1;
if(B[mid] <= x) l = mid;
else r = mid - 1;
}
return l;
}

public static void main(String[] args) throws Exception{
int k = Integer.parseInt(in.readLine());

n = s.length();
for(int i = 0; i < n; i++){
if(!chack(i-1)){
if(i + 4 < n && s.substring(i, i + 5).equals("Alice") && !chack(i+5))
A[cnta ++] = i;
else if(i + 2 < n && s.substring(i, i + 3).equals("Bob") && !chack(i+3))
B[cntb ++] = i;
}
}

long res = 0;
for(int i = 0; i < cnta; i++){
int l = findl(A[i] - k - 3); // 找到在合法范围内，Alice最左边的Bob

if(cntb == 0 || B[l] > A[i] + k + 5){ //没找到。
continue;
}

int r = findr(A[i] + k + 5); // 找到合法范围内，Alice最右边的Bob // 1  7

res += r - l + 1;
}
out.write(res + "");
out.flush();
}
}


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

public class Main{
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

static final int N = 1000010;
static String s;
static int[] A = new int[N], B = new int[N];
static int n;

public static boolean chack(int i){
if(i < 0 || i >= n)
return false;
char c = s.charAt(i);
return c >= 'a' && c <= 'Z' || c >= 'A' && c <= 'Z';
}

public static void main(String[] args) throws Exception{
int k = Integer.parseInt(in.readLine());

n = s.length();
int cnta = 0, cntb = 0;
for(int i = 0; i < n; i++){
if(!chack(i-1)){ // 注意不要用 == 判断是否相等。
if(i + 4 < n && s.substring(i, i + 5).equals("Alice") && !chack(i+5))
A[cnta ++] = i;
else if(i + 2 < n && s.substring(i, i + 3).equals("Bob") && !chack(i+3))
B[cntb ++] = i;
}
}

int l = 0, r = -1;
long res = 0;
if(cntb == 0 || cnta == 0) res = 0;
else
for(int i = 0; i < cnta; i++){
// 先判断r+1是不是在范围内， 再 r++;
while(r + 1 < cntb && B[r + 1] <= A[i] + 5 + k)
r++;
// 找到第一个在合法区间内的Bob
while(l <= r && B[l] + 3 + k < A[i])
l++;

res += r - l + 1;
}
out.write(res + "");
out.flush();
}
}


## I

1 3
5 4 3 2 1

A + B - (C - D - E - F - G)

A + B + D + E + F + G - C

A + B + D + E + F + G - C

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

public class Main{
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

public static int Int(String s){
return Integer.parseInt(s);
}

public static void main(String[] args) throws Exception{
String[] s = in.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int m = Integer.parseInt(s[1]);

String[] arr = in.readLine().split(" ");

int len = n + m + 1;
long sum = 0;
if(m == 0){ // 全是加号
for(int i = 0; i < len; i++)
sum += Integer.parseInt(arr[i]);
}
else{
int max = 0, min = 0;

for(int i = 0; i < len; i++){
if(Int(arr[min]) > Int(arr[i]))
min = i;
if(Int(arr[max]) < Int(arr[i]))
max = i;
}

sum = Int(arr[max]) - Int(arr[min]);

for(int i = 0; i < len; i++){
if(i != min && i != max)
sum += Math.abs(Int(arr[i]));
}

}
out.write(sum + "");
out.flush();
}

}


## J

（ S i − 1 ， S i ， S i + 1 ） （S_{i-1}，S_i ，S{i+1}） — > （ S i ， S i − 1 ， S i + 1 ） （S_{i}，S_{i-1} ，S{i+1}）

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

public class Main{
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

static final int N = 300010;

static long[] S = new long[N];
static int[] st = new int[N];

public static long Int(String s){
return Long.parseLong(s);
}

public static void main(String[] args) throws IOException{
int T = Integer.parseInt(in.readLine());

while(T != 0){
T --;
int n = Integer.parseInt(in.readLine());

String[] s = in.readLine().split(" ");

S[0] = 0;

for(int i = 1; i <= n; i++){
S[i] = Int(s[i-1]); // 得到前缀和数组
S[i] += S[i-1];
}

long s0 = 0, sn = S[n]; // 记录s0 和 sn 的值，以便排序后找到他们的位置

if(s0 > sn){ // 对于sn < 0的情况，我们将其值调换，仍作为s0是最小值 sn是最大值处理。
long temp = s0;
s0 = sn;
sn = temp;
}

Arrays.sort(S, 0, n + 1);

for(int i = 0; i <= n; i++){
if(s0 == S[i]){
s0 = i;
break;
}
}

for(int i = 0; i <= n; i++){
if(sn == S[i]){
sn = i;
break;
}
}

long[] a = new long[N];

Arrays.fill(st, 0);
int l = 0, r = n;
// 隔一个取一个
for(int i = (int) s0; i >= 0; i -= 2){
a[l ++] = S[i];
st[i] = 1;
}

for(int i = (int) sn; i <= n; i += 2){
a[r --] = S[i];
st[i] = 1;
}

for(int i = 0; i <= n; i++){
if(st[i] == 0)
a[l ++] = S[i];
}

// 查找答案
long res = 0;
for(int i = 1; i <= n; i++){
res = Math.max(res, Math.abs(a[i] - a[i-1]));
}

out.write(res + "\n");
out.flush();
}
}
}


05-06 1421
03-30 1113
03-24
07-19 1万+
04-01 1万+
06-04 1万+
03-28 7802
04-15 1万+
04-01 1万+
03-06 4976
03-28 1812
11-20
04-05 4790
©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试