文章目录
🔥题目一
题目描述
运行限制
题解
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int count = 0;
for ( int i = 1 ; i <= 20210605 ; i++ ){
if ( isprinum(i) ){
if ( fun(i) ){
count++;
}
}
}
System.out.println(count);
}
//判断质数
public static boolean isprinum(int num){
//注意0不是素数
if ( num == 1 || num == 0 ){
return false;
}
for ( int i = 2 ; i <= Math.sqrt(num) ; i++ ){
if( num % i == 0){
return false;
}
}
return true;
}
//判断十进制位数是不是质数
public static boolean fun(int peinum){
while(peinum > 0){
int n = peinum % 10;
if ( !isprinum(n) ){
return false;
}
peinum = peinum / 10;
}
return true;
}
}
🔥题目二
题目描述
输入\出格式
样例说明
评测用例规模与约定
运行限制
题解
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
int weight = 1;
int count = 1;
int total = 1;
while (total < n) {
count++;
weight *= 3;
total += weight;
}
System.out.println(count);
}
}
砝码序号 | 砝码重量 | 总重量(可以称出的最大重量) |
---|---|---|
1 | 1 | 1 |
2 | 3 | 4 |
3 | 9 | 13 |
4 | 27 | 40 |
...... | ...... | ...... |
count=count+1 | weight=weight*3 | total=total+weight |
🔥题目三
题目描述
输入\出描述
输入输出样例
运行限制
- 最大运行时间:1s
- 最大运行内存: 128M
题解
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();//行数
int m=sc.nextInt();//列数
int t=sc.nextInt();//出水口数
int a,b;
int [][]arr=new int[n+2][m+2];//经过时间后的湿地信息
int [][]brr=new int[n+1][m+1];//当前时间湿地信息
for (int i=0;i<t;i++){
a=sc.nextInt();
b=sc.nextInt();
arr[a][b]=1;
brr[a][b]=1;
}
int count=0;
int k=sc.nextInt();//时间
for (int i=1;i<=k;i++){//时间循环
for (int j=1;j<=n;j++){//寻找当前湿地
for (int s=1;s<=m;s++){//寻找当前湿地
if (brr[j][s]==1){//当前为湿地
arr[j-1][s]=1;//经过该时间后,此地为湿地
arr[j+1][s]=1;//经过该时间后,此地为湿地
arr[j][s-1]=1;//经过该时间后,此地为湿地
arr[j][s+1]=1;//经过该时间后,此地为湿地
}
}
}
for (int j=1;j<=n;j++){//更改当前湿地信息(即经过该时间后为湿地)
for (int s=1;s<=m;s++){
if (arr[j][s]==1){
brr[j][s]=1;
if (i==k){//到达最后的时间
count++;//统计数量
}
}
}
}
}
System.out.println(count);
}
}