MC0240 小码哥和假期堵车(循环即可)
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int t=sc.nextInt();
int ww[]=new int[n];//被支配的时
for (int i = 0; i <n ; i++) {
ww[i]=sc.nextInt();
}
int i=0;
for (i=0; i <n ; i++) {
int num=1440-ww[i];
if (num>=60){
t-=num;
}
if (t<=0){
break;
}
}
System.out.println(i+1);
}
}
MC0241防火墙 (运用到了字符串的最小表示法模版)
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str1=sc.next();
String str2=sc.next();
str1=panduan(str1);
str2=panduan(str2);
if (str1.equals(str2)){
System.out.println("Yes");
System.out.println(str1);
}else{
System.out.println("No");
}
}
private static String panduan(String str) {
int i=0,j=1,k=0,size=str.length();
while (i<size&&j<size&&k<size){
if (str.charAt((i+k)%size)==str.charAt((j+k)%size)){
k++;
}else {
if (str.charAt((i+k)%size)>str.charAt((j+k)%size)){
//求最小的情况
i=i+k+1;
}else{
j=j+k+1;
}
if (i==j){
i++;
}
//重置i j之后也要重置k
k=0;
}
}
int start=Math.min(i,j);
str=str.substring(start,size)+str.substring(0,start);
return str;
}
}
MC0242寻找聪明学者
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int ww[]=new int[n];
for (int i = 0; i <n ; i++) {
ww[i]=sc.nextInt();
}
int flag=0;
boolean cc=false;
for (int i = 0; i <n-1; i++) {
if (flag==2){
cc=true;
break;
}
if (ww[i]<ww[i+1]){
flag++;
}else{
flag=0;
}
}
if (cc){
System.out.println("True");
}else{
System.out.println("False");
}
}
}
MC0243星辰大海 (DFS)
import java.util.Scanner;
public class Main{
static int p,q,k,sum;
static int cc[][];
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
cc=new int[82][82];
for (int i = 0; i <t ; i++) {
p=sc.nextInt();
q=sc.nextInt();
k=sc.nextInt();
sum=0;
dfs(0,0);
System.out.println(sum%337077);
}
}
private static void dfs(int num, int res) {
if (res==k){
sum++;
return;
}
for (int i = num; i <p*q ; i++) {
int x=i/q+1;
int y=i%q+1;
if (x==0||x>=p+1||y==0||y>=q+1){
continue;
}
if (cc[x-1][y]==0&&cc[x+1][y]==0&&cc[x][y-1]==0&&cc[x][y+1]==0){
cc[x][y]=1;
res++;
dfs(i+1,res);
res--;
cc[x][y]=0;
}
}
}
}
MC0245小码哥的浇花选择
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int x=sc.nextInt();
int y=sc.nextInt();
int l=sc.nextInt();
int n=0;
int m=0;
while(true){
int num1=Math.abs(l-x);
l-=num1;
//先判断在加数值
if (l<0){
break;
}
n+=num1;
int num2=Math.abs(l-y);
l-=num2;
//先判断在加数值
if (l<0){
break;
}
m+=num2;
}
System.out.println(n+" "+m);
}
}
MC0248密码判断器
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.next();
boolean a=true,b=true,c=false,d=true;
if (str.length()<=6){
a=false;
}
if (str.toUpperCase()==str||str.toLowerCase()==str){
b=false;
}
for (int i = 0; i <str.length(); i++) {
if (str.charAt(i)>='0'&&str.charAt(i)<='9')
c=true;
}
for (int i = 0; i <str.length()-1 ; i++) {
if (str.charAt(i)>='0'&&str.charAt(i)<='9'&&str.charAt(i+1)>='0'&&str.charAt(i+1)<='9'){
d=false;
}
}
if (a&&b&&c&&d){
System.out.println("True");
}else {
System.out.println("False");
}
}
}
MC0249疗养院的福利 (多拿一个数组记录)
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Integer cc[]=new Integer[n];
Integer flag[]=new Integer[n];
for (int i = 0; i <n; i++) {
cc[i]=sc.nextInt();
flag[i]=cc[i];
}
Arrays.sort(flag,(a,b)->{
return b-a;
});
int a=sc.nextInt();
int max[]=new int[a];
for (int i = 0; i <a ; i++) {
max[i]=flag[i];
}
for (int i = 0; i <a; i++) {
for (int j = 0; j <n ; j++) {
if (max[i]==cc[j]){
max[i]=j+1;
cc[j]=-1;
break;
}
}
}
for (int i = 0; i <a; i++) {
System.out.print(max[i]+" ");
}
}
}
MC0251小码哥锻炼 普通)
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n= sc.nextInt();
int sum=0;
while(n>0){
if (n>=13){
sum+=n/13;
n%=13;
}
if (n>=7){
sum+=n/7;
n%=7;
}
if (n>=3){
sum+=n/3;
n%=3;
}
if (n>=1){
sum+=n;
n=0;
}
}
System.out.println(sum);
}
}
MC0252小码哥的数字游戏 (题意说一定包含所有的小于等于t的数据 所以简单遍历即可)
import java.util.Scanner;
public class Main{
static int t;
static int cc[][];
static int p,q;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n= sc.nextInt();
int m= sc.nextInt();
t= sc.nextInt();
cc=new int[n+1][m+1];
for (int i = 1; i <n+1 ; i++) {
for (int j = 1; j <m+1 ; j++) {
cc[i][j]=sc.nextInt();
}
}
int min_x=99,min_y=99,max_x=-1,max_y=-1;
for (int i = 1; i <n+1 ; i++) {
for (int j = 1; j <m+1 ; j++) {
if (cc[i][j]>t){
continue;
}else {
min_x=Math.min(min_x,i);
min_y=Math.min(min_y,j);
max_x=Math.max(max_x,i);
max_y=Math.max(max_y,j);
}
}
}
p=max_x-min_x;
q=max_y-min_y;
System.out.println(p+1);
System.out.println(q+1);
}
}