【思特奇杯·云上蓝桥-算法集训营】第1周

  1. 第一题

在这里插入图片描述答案为:3880。
代码如下:

public class one_1 {
    public static void main(String[] args) {
        int t=0;
        int tz=0,ts=0;
        int hp=10000;
        tz=(hp/600)*600/300*120;
        //(hp/600)*600能完整的跑+休息消耗的时间
        ts=(hp-(hp/600)*600)/10;
        t=tz+ts;
        System.out.println(t);
    }
}
  1. 第二题

在这里插入图片描述答案为:39001250856960000。
代码如下:

public class one_2 {
    public static void main(String[] args) {
        int[] array=new int[101];
        int i;
        int j;
        int k;
        long s=1;
        for(i=100;i>1;i--){
            array[i]++;
            for(j=2;j<i;j++){
                if(i%j==0){
                    array[j]=array[j]+array[i];
                    array[i/j]=array[i/j]+array[i];
                    array[i]=0;
                    break;
                }
            }
        }
        for (k=2;k<101;k++){
            if(array[k]!=0){
                s=s*(array[k]+1);
            }
        }
        System.out.println(s);
    }
}
  1. 第三题

在这里插入图片描述答案:35357670
代码如下:

public class one_3 {
    public static void main(String[] args) {
        System.out.println(hhhhh(16,0));
    }
    public static int hhhhh(int a,int b){
        if(a==0){
            return 1;
        }if(b==0){
            return hhhhh(a-1,1);
        }
        return hhhhh(a-1,b+1)+hhhhh(a,b-1);
    }
}

  1. 第四题

在这里插入图片描述答案:173.

public class one_4 {
    public static void main(String[] args) {
        int[] array=new int[10001];
        int i,j;
        int k;
        int r;
        int[] t=new int[5001];
        for(i=10000;i>1;i--){//寻找所有素数
            array[i]=1;
            for(j=2;j<i;j++){
                if(i%j==0){
                    array[i]=0;
                }
            }
        }
        
        for(k=2;k<5000;k++){//找到包含最小的素数并标记
            for(r=0;r<k;r++){
                if(array[r]==1&&array[2 * k - r]==1){
                    t[r]=1;
                    //System.out.println(r+"+"+(2*k-r)+"="+(2*k));
                    break;
                }
            }
        }
        for (i=5000;i>1;i--){//输出
            if(t[i]==1){
                System.out.println(i);
                break;
            }
        }
    }
}

  1. 第五题
    在这里插入图片描述
    答案:479306
    代码如下:
public class one_5 {
    public static int res=0;
    public static int[] a={0,1,2,3,4,5,6,7,8,9};
    public static boolean[] b={false,false,false,false,false,false,false,false,false,false};
    public static boolean check(){
        int i;
        for(i=0;i<9;i++){
            if(Math.abs(a[i]-a[i+1])==1){
                return false;
            }
        }
        return true;
    }
    public static void dfs(int k){
        if(k==10){
            if(check()){
                res++;
                return;
            }
        }for(int i=0;i<10;i++){
            if(!b[i] ){
                b[i]=true;
                a[k]=i;
                dfs(k+1);
                b[i]=false;
            }
        }

    }
    public static void main(String[] args) {
        dfs(0);
        System.out.println(res);

    }
}

  1. 第六题

在这里插入图片描述

答案为:3141.
代码如下:

public class one_6 {
    public static void main(String[] args) {
        int i=0;
        int s=0;
        while(s==0){
            i=i+1;
            if(i%5==1){
                int i1=i-1-i/5;
                if((i1)%5==2){
                    int i2=i1-2-i1/5;
                    if(i2%5==3){
                        int i3=i2-3-i2/5;
                        if(i3%5==4){
                            int i4=i3-4-i3/5;
                            if(i4%5==0&&i4!=0){
                                s=i;
                            }
                        }
                    }
                }
            }

        }
        System.out.println(s);
    }
}

  1. 第七题
    在这里插入图片描述
import java.util.Scanner;

public class one_7 {
    static int m,n;
    static int z = 0,f = 1;
    static int a,b;
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String str = input.nextLine();
        String[] s =str.split("/");
        a=Integer.parseInt(s[0]);
        b=Integer.parseInt(s[1]);
        for(n=100; n>1; n--){
            for(m=n*a/b; m>=1; m--){
                if( (m*b)<(a*n)&&hhhhh(m,n)==1)
                {
                    if( m*f>n*z ){
                        z = m;
                        f = n;
                        break;
                    }
                }
            }
        }

        System.out.println(z+"/"+f);
    }
    private static int hhhhh(int i, int j) {
        if(j==0){
            return i;
        }
        return hhhhh(j,i%j);
    }
}

  1. 第八题

在这里插入图片描述代码如下:

import java.util.Scanner;

public class one_8 {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int e=input.nextInt();
        char[] array={'Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N',
                'O','P','Q','R','S','T','U','V','W','X','Y'};
        String s="";
        int c=0;
        while(e!=0){
            s=array[e%26]+s;
            if(e%26==0){//使商减一。如52,AZ,2余0无法成立
                e=e-1;
            }
            System.out.println(e%26);
            if(e/26==1){
                e=0;
            }else {
                e=e/26;
            }
        }
        System.out.println(s);
    }
}

  1. 第九题
    在这里插入图片描述代码如下:
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class one_9 {
    public static List<String> List=new LinkedList<>();
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String str = input.nextLine();
        String[] s =str.split("/");


        int x=Integer.parseInt(s[0]);
        int y=Integer.parseInt(s[1]);
        int z=Integer.parseInt(s[2]);
        hhhhh(x,y,z);
        hhhhh(z,x,y);
        hhhhh(z,y,x);
        for(int i=0;i<List.size();i++){
            System.out.println(List.get(i));
        }


    }
    public static void hhhhh(int y, int m, int d){
        if(y<=59){
            y=2000+y;
        }else {
            y=1900+y;
        }
        if((y%4==0&&y%100!=0)||y%400==0){//闰年
            if(m==2&&d<10){
                List.add(y+"-0"+m+"-0"+d);
            }
            if(m==2&&d<=29&&d>=10){
                List.add(y+"-0"+m+"-"+d);
            }

        }else{
            if(m==2&&d<10){
                List.add(y+"-0"+m+"-0"+d);
            }
            if(m==2&&d<=28&&d>=10){
                List.add(y+"-0"+m+"-"+d);
            }
        }
        if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){
            if(m<10){
                if(d<10){
                    List.add(y+"-0"+m+"-0"+d);
                }
                if(d>10&&d<=31){
                    List.add(y+"-0"+m+"-"+d);
                }
            }else{
                if(d<10){
                    List.add(y+"-"+m+"-0"+d);
                }
                if(d>=10&&d<=31){
                    List.add(y+"-"+m+"-"+d);
                }
            }

        }if(m==4||m==6||m==9||m==11){
            if(m<10){
                if(d<10){
                    List.add(y+"-0"+m+"-0"+d);
                }
                if(d>=10&&d<=30){
                    List.add(y+"-0"+m+"-"+d);
                }
            }else{
                if(d<10){
                    List.add(y+"-"+m+"-0"+d);
                }
                if(d>10&&d<=30){
                    List.add(y+"-"+m+"-"+d);
                }
            }
        }

    }
}

  1. 第十题
    在这里插入图片描述

代码如下:

import java.util.Scanner;
public class one_10 {
    public static int divide(int n,int m){
        if(n==1||m==1){
            return 1;
        }if(n==m){
            return divide(n,m-1)+1;
        }if(n>m){
            return divide(n,m-1)+divide(n-m,m);
        }if(n<m){
            return divide(n,n);
        }
        return 0;
    }
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int x=scanner.nextInt();
        System.out.println(divide(x,x));

    }
}

  1. 第十一题

在这里插入图片描述
答案为:97。
代码如下:

public class one_11 {
    public static void main(String[] args) {
        int s=Integer.MAX_VALUE;
        int i,j;
        int x=0,y=0;
        for(i=0;i<100;i++){
            for(j=0;j<100;j++){
                if((97*i-127*j)==1&&s>(i+j)){
                    s=i+j;
                    x=i;y=j;
                }
            }
        }
        System.out.println(s);
    }
}

  1. 第十二题
    在这里插入图片描述

代码如下:

import java.util.Scanner;

public class one_12 {
    public static int m,n,res,row;
    public static int[] cnt;
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        m=scanner.nextInt();
        n=scanner.nextInt();
        res=0;
        row= (int) Math.sqrt(2*(m+n));
        cnt=new int[row+1];
        explore(1);
        System.out.println(res);

    }
    public static boolean check(){
        int a=0,b=0;
        int tem=row;
        while (tem>0){
            for (int i=1;i<tem+1;i++){
                if(cnt[i]==1){
                    a=a+1;
                }else {
                    b=b+1;
                }
            }
            for (int j=2;j<tem+1;j++){
                if(cnt[j-1]==cnt[j]){
                    cnt[j-1]=1;
                }else {
                    cnt[j-1]=2;
                }
            }
            tem--;
        }
        if(a==m&&b==n){
            return true;
        }else {
            return false;
        }
    }
    public static void explore(int k){
        if(k>row){
            if(check()){
                res++;
            }
            return;
        }
        cnt[k]=1;
        explore(k+1);
        cnt[k]=2;
        explore(k+1);
    }
}

  1. 第十三题(图反了)
    在这里插入图片描述答案:10 3 9 8
    代码如下(十分暴力了):
public class one_13 {
    public  static int a,b,c,d,m,x;
    public static int[] s=new int[15];
    public static boolean judge(){
        s[6]=1;
        s[11]=1;
        s[14]=1;
        s[a]++;
        s[b]++;
        s[c]++;
        s[d]++;
        s[m]++;
        s[x]++;
        s[10-b]++;
        s[13-c]++;
        if(20-a+b-m>14||20-a+b-m<1){
            return false;
        }
        s[20-a+b-m]++;
        if(2+x+d-c-m>14||2+x+d-c-m<1){
            return false;
        }
        s[2+x+d-c-m]++;
        if(17+c-x-d>14||17+c-x-d<1){
            return false;
        }
        s[17+c-x-d]++;
        for(int i=1;i<15;i++){
            if(s[i]!=1){
                for (int j=0;j<15;j++){
                    s[j]=0;
                }
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        for(a=1;a<14;a++){
            for(b=1;b<10;b++){
                for(c=1;c<13;c++){
                    for(d=1;d<14;d++){
                        for(m=1;m<14;m++){
                            for(x=1;x<14;x++){
                                if(a+b+c+d==30){
                                    if(14+x+20-a-m+b+2+x+d-c-m==30&&judge()){

                                        System.out.println(a+" "+b+" "+c+" "+d);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值