2023码蹄杯省赛第三场题目 | 共计13道

This commit is contained in:
pronting 2023-11-23 15:15:50 +08:00
parent 02c8295802
commit 586e167e18
13 changed files with 545 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 14:01
*/
public class Main1 {
static int a, b, ans = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
a = scanner.nextInt();
b = scanner.nextInt();
for (int i = a; i <= b; i++) {
int res = 0;
if(i % 8 != 0){
for (int j = i; j >= 0; j--) {
res += j;
}
}
ans += res;
}
System.out.println(ans);
}
}

View File

@ -0,0 +1,60 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 15:51
*/
public class Main10 {
static int n, m, cnt = 0;
static int[][] g;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
m = scanner.nextInt();
g = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
g[i][j] = scanner.nextInt();
}
}
int i = 0, j = 0;
while (i < n && j < m) {
if (!check(g[i][j])) {
if (j + 1 >= m) {
j = 0;
i++;
} else {
j++;
}
}else{
cnt++;
int t = g[i][j] % 10;
if(j + t >= m){
j = 0;
i++;
}else{
j += t;
}
}
}
System.out.println(cnt);
}
private static boolean check(int a) {
boolean flag = true;
int target = (int) Math.sqrt(a);
for (int i = 2; i <= target; i++) {
if (a % i == 0) {
flag = false;
break;
}
}
return flag;
}
}

View File

@ -0,0 +1,40 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 16:03
*/
public class Main11 {
static String s2, s1;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
s1 = scanner.next();
s2 = scanner.next();
s1 = s1.replaceAll("!", "");
if (s1.contains(s2)) {
System.out.println("True");
}else{
System.out.println("False");
}
// String[] s = s2.split("");
// String[] ss = s1.split("");
// int j = 0;
// for (int i = 0; i < ss.length; i++) {
// if (ss[i].equals(s[j])) {
// j++;
// if(j == s.length) break;
// }
// }
// if(j == s.length){
// System.out.println("True");
// }else{
// System.out.println("False");
// }
}
}

View File

@ -0,0 +1,34 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 16:50
*/
public class Main12 {
static int t;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
t = scanner.nextInt();
while (t-- > 0) {
int cnt = 0;
String s0 = scanner.next();
String s = scanner.next();
for (int i = 0; i < s0.length() - s.length(); i++) {
int alter = 0;
int k = i;
for (int j = 0; j < s.length(); j++) {
if(s0.charAt(k) != s.charAt(j)){
alter++;
}
k++;
}
if(alter <= 3) cnt++;
}
System.out.println(cnt);
}
}
}

View File

@ -0,0 +1,41 @@
package priv.pront.code.mati.province.comp;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 16:24
*/
public class Main13 {
static int n;
static Set<Character> set = new HashSet<>();
static char[][] g;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
g = new char[n][n];
for (int i = 0; i < n; i++) {
g[i] =scanner.next().toCharArray();
}
int i = 0, j = 0;
while (i < n && j < n) {
if (!set.contains(g[i][j])) {
set.add(g[i][j]);
}else{
break;
}
i++;
j++;
}
if(i >= n && j >= n){
System.out.println("accept");
}else{
System.out.println("refuse");
}
}
}

View File

@ -0,0 +1,34 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 14:07
*/
public class Main2 {
static String s;
static int[] a;
static char ans = '0';
static int max = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
s = scanner.next();
a = new int[26];
for (int i = 0; i < s.length(); i++) {
char cur = s.charAt(i);
a[cur - 'A']++;
}
for (int i = 0; i < a.length; i++) {
if(a[i] > max){
max = a[i];
ans = (char) ('A' + i);
}
}
System.out.println(ans);
}
}

View File

@ -0,0 +1,25 @@
package priv.pront.code.mati.province.comp;
import java.util.Arrays;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 14:15
*/
public class Main3 {
static int n;
static int[]a ;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
Arrays.sort(a);
System.out.println(a[n - 1] - a[0]);
}
}

View File

@ -0,0 +1,47 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 14:21
*/
public class Main4 {
static int a, b, n = 0, len;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
a = scanner.nextInt();
b = scanner.nextInt();
len = (a + "").length();
for (int i = 0; i < len; i++) {
if (huzhi(a, b) != 1) {
change();
}else{
System.out.println(i);
return;
}
}
System.out.println(-1);
}
private static int huzhi(int a, int b) {
if(a % b == 0){
return b;
}
return huzhi(b,a % b);
}
private static void change(){
String aa = a + "";
String bb = b + "";
StringBuilder sba = new StringBuilder(aa.substring(1, aa.length()));
StringBuilder sbb = new StringBuilder(bb.substring(1, bb.length()));
sba.append(aa.charAt(0));
sbb.append(bb.charAt(0));
a = Integer.parseInt(sba.toString());
b = Integer.parseInt(sbb.toString());
}
}

View File

@ -0,0 +1,28 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 14:33
*/
public class Main5 {
static int n;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
if(i % 3 != 0){
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
}else{
System.out.print("|");
}
System.out.println();
}
}
}

View File

@ -0,0 +1,34 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 14:35
*/
public class Main6 {
static int n;
static String s;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
s = scanner.next();
sb.append(s.charAt(0));
int idx = 1;
int nal = 0;
while(idx < s.length()) {
if(nal == n - 1){
sb.append(s.charAt(idx));
nal = 0;
}else{
nal++;
}
idx++;
}
System.out.println(sb.toString());
}
}

View File

@ -0,0 +1,92 @@
package priv.pront.code.mati.province.comp;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 14:50
*/
public class Main7 {
static int n;
static int[] dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
while (n-- > 0) {
int n = scanner.nextInt();
int m = scanner.nextInt();
int t1 = -1, t2 = -1;
int x = 0, y = 0, z = -1, h = -1;
boolean[][] st = new boolean[n][m];
boolean flag1 = false;
boolean flag2 = false;
char[][] g = new char[n][m];
Queue<int[]> queue = new LinkedList<>();
Queue<int[]> queue1 = new LinkedList<>();
for (int i = 0; i < n; i++) {
g[i] = scanner.next().toCharArray();
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (g[i][j] == 'P') {
x = i; y = j;
}
}
}
queue.add(new int[]{x, y ,0});
st[x][y] = true;
while (!queue.isEmpty()) {
int[] poll = queue.poll();
if(g[poll[0]][poll[1]] == 'K'){
flag1 = true;
t1 = poll[2];
z = poll[0];
h =poll[1];
break;
}
for (int i = 0; i < 4; i++) {
int nx = dx[i] + poll[0];
int ny = dy[i] + poll[1];
if(nx < 0 || nx >= n|| ny < 0 || ny >= m || st[nx][ny] || g[nx][ny] == '#' || g[nx][ny] == 'E') continue;
st[nx][ny] = true;
queue.add(new int[]{nx, ny, poll[2] + 1});
}
}
if(z == -1){
System.out.println("No solution");
continue;
}
st = new boolean[n][m];
queue1.add(new int[]{z, h, 0});
st[z][h] = true;
while (!queue1.isEmpty()) {
int[] poll = queue1.poll();
if(g[poll[0]][poll[1]] == 'E'){
flag2 = true;
t2 = poll[2];
break;
}
for (int i = 0; i < 4; i++) {
int nx = dx[i] + poll[0];
int ny = dy[i] + poll[1];
if(nx < 0 || nx >= n|| ny < 0 || ny >= m || st[nx][ny] || g[nx][ny] == '#' ) continue;
st[nx][ny] = true;
queue1.add(new int[]{nx, ny, poll[2] + 1});
}
}
if (!flag1 || !flag2) {
System.out.println("No solution");
}else{
System.out.println(t1 + t2);
}
}
}
}

View File

@ -0,0 +1,49 @@
package priv.pront.code.mati.province.comp;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 15:21
*/
// FIXME
public class Main8 {
static int n, ans = 0, ridx = 499;
static int[][] g;
static List<List<Integer>> list = new ArrayList<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
g = new int[1005][1005];
for (int i = 0; i < 1005; i++) list.add(new ArrayList<>());
for (int i = 0; i < n; i++) {
int row = scanner.nextInt();
int col = scanner.nextInt();
list.get(row).add(col);
}
for (int i = 0; i < 1000; i++) {
int alter = 0;
ans += ridx + 1;
if (list.get(i).size() > 0) {
List<Integer> integers = list.get(i);
for (Integer integer : integers) {
alter += (i - integer);
}
}
if (ridx + alter > 999) {
ridx = 999;
} else if(ridx + alter < 0) {
ridx = 0;
}else{
ridx += alter;
}
}
System.out.println(ans);
}
}

View File

@ -0,0 +1,33 @@
package priv.pront.code.mati.province.comp;
import java.util.Scanner;
/**
* @Description:
* @Author: pront
* @Time:2023-11-18 15:40
*/
public class Main9 {
static int n;
static int a = 0, b = 0, c = 0;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
String s = i + "";
if((i % 3 == 0 || s.contains("3")) && (i % 5 == 0 || s.contains("5"))) {
c++;
}else if(i % 5 == 0 || s.contains("5")) {
b++;
}else if(i % 3 == 0 || s.contains("3")){
a++;
}
}
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}