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

第一题

public class running {

    public static void main(String[] args){

        int count=0;
        int hp=10000;
        boolean flag=true;

        while(true){
            if(hp<600 && flag){//体力值小于600时这一分钟跑不完
                break;
            }
            if(flag){//跑步
                hp-=600;
                flag=false;
            }else{//休息
                hp+=300;
                flag=true;
            }
            count++;
        }
        int time=count*60+hp/10;
        System.out.println(time);
    }
}

第二题

 

public class factorial {

    static int n=100;
    static int[] p=new int[101];
    static int[] f=new int[101];
    static long s=1;
    static int c=0;

    public static void main(String[] args){
        for(int i=2;i<100;i++){
            if(f[i]==0){
                p[c++]=i;
            }
            for(int j=0;j<c && p[j]*i<=100;j++){
                f[i*p[j]]=1;
                if(i%p[j]==0) break;
            }
        }
        for(int i=0;i<c;i++){
            long temp=0;
            long now=p[i];
            for(int j=n;j>0;j/=now) temp+=j/now;
            s*=(temp+1);
        }
        System.out.println(s);
    }
}

第三题

 

public class popStack {
    public static void main(String[] args) {//卡特兰数
        int num=1;
        for (int i=1;i<=16;i++) {
            num=num*(4*i-2)/(i+1);
        }
        System.out.println(num);
    }
}

第四题

 

 

public class goldbach {
    static int ans = 0;
    static int n = 0;
    static int[] arr = new int[10005];
    static boolean[] arr2 = new boolean[10005];

    public static void main(String[] args) {
        find();
        for (int i = 2; i <= 10000; i = i + 2) {
            for (int j = 0; j < n; j++) {
                boolean flag = false;
                for (int k = j + 1; k < n; k++) {
                    if (arr[j] + arr[k] == i) {
                        ans = Math.max(ans, arr[j]);
                        flag = true;
                    }
                }
                if (flag) break;
            }
        }
        System.out.println(ans);

    }

    private static void find() {
        for (int i = 2; i <= 10000; i++) {
            if (!arr2[i]) {
                int j = 2;
                while (i * j <= 10000) {
                    arr2[i * j] = true;
                    j++;
                }
            }
        }
        for (int i = 2; i <= 10000; i++)
            if (!arr2[i]) arr[n++] = i;
    }

    public static boolean isprime(int n) {
        if (n == 1 || n == 0) return false;
        for (int j = 2; j <= Math.sqrt(n); j++) {
            if (n % j == 0) {
                return false;
            }
        }
        return true;

    }
}

第五题

 

 

public class book {

    static int sum=0;
    static int[] array={1,2,3,4,5,6,7,8,9,10};

    static void check() {
        for (int i=0;i<array.length-1;i++) {
            if(array[i]==array[i+1]+1||array[i]==array[i+1]-1) {
                return;
            }
        }
        sum++;
    }

    static void f(int index){
        if(index==array.length-1) {
            check();
            return;
        }

        for (int i=index;i<array.length;i++) {
            {
                int temp=array[i];
                array[i]=array[index];
                array[index]=temp;
            }
            f(index+1);
            {
                int temp=array[i];
                array[i]=array[index];
                array[index]=temp;
            }
        }
    }

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

第六题

 

public class monkey {
    public static void main(String[] args){
        for(int x=5;x<=10000;x++){
            int i=x;
            if((i-1)%5!=0)
                continue;
            i=(i-1)/5*4;
            if(i<2 || (i-2)%5!=0)
                continue;
            i=(i-2)/5*4;
            if(i<3 || (i-3)%5!=0)
                continue;
            i=(i-3)/5*4;
            if(i<4 || (i-4)%5!=0)
                continue;
            i=(i-4)/5*4;
            if(i<5 || i%5!=0)
                continue;
            System.out.println(x);
            return;
        }
    }
}

第七题

 

public class smaller {
    static int m,n;
    static int max1=0;
    static int max2=1;
    static int a=7;
    static int b=13;
    public static void main(String[] args) {
        for(n=100;n>1;n--){
            for(m=n-1;m>=1;m--){
                if(m*b<a*n && gcd(m,n)==1) {
                    if(m*max2>n*max1){
                        max1=m;
                        max2=n;
                        break;
                    }
                }
            }
        }
        System.out.println(max1+"/"+max2);
    }
    private static int gcd(int i, int j){
        if(j==0){
            return i;
        }
        return gcd(j,i%j);
    }
}

第八题

 

import java.util.Scanner;

public class excel{
    public static void main(String[] args){
        Scanner n=new Scanner(System.in);
        int[] A=new int[5000];
        int n1=n.nextInt();
        int i=1;
        while (n1!=0){
            if(n1%26==0){
                // +64转大写字母,+96转小写字母
                A[i]=26+64;
                n1-=1;
            }else{
                A[i]=n1%26+64;
            }
            n1/=26;
            i++;
        }
        for(int j=i-1;j>0;j--){
            System.out.print((char) A[j]);
        }
    }
}

第九题

 

 

 

 

import java.util.Scanner;
import java.util.TreeSet;

public class date{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a[] = sc.next().split("/");
        int b[] = new int[3];
        for(int i = 0;i < a.length;i++)
            b[i] = Integer.valueOf(a[i]);
        TreeSet<yea> set = new TreeSet<yea>();
        if(b[0] <= 59){
            if(b[1] <= 12 && b[2] <= 31 && b[1] != 0 && b[2] !=0){
                yea ans = new yea();
                ans.y = b[0]+2000;
                ans.m = b[1];
                ans.d = b[2];
                set.add(ans);
            }
        }
        if(b[2] <= 59){
            if(b[0] <= 12 && b[1] <= 31 && b[1] != 0 && b[0] !=0){
                yea ans = new yea();
                ans.y = b[2]+2000;
                ans.m = b[0];
                ans.d = b[1];
                set.add(ans);
            }
            if(b[0] <= 31 && b[1] <= 12 && b[1] != 0 && b[0] !=0){
                yea ans = new yea();
                ans.y = b[2]+2000;
                ans.m = b[1];
                ans.d = b[0];
                set.add(ans);
            }
        }
        if(b[0] >= 60){
            if(b[1] <= 12 && b[2] <= 31 && b[1] != 0 && b[2] !=0){
                yea ans = new yea();
                ans.y = b[0]+1900;
                ans.m = b[1];
                ans.d = b[2];
                set.add(ans);
            }
        }
        if(b[2] >= 60){
            if(b[0] <= 12 && b[1] <= 31&& b[1] != 0 && b[0] !=0){
                yea ans = new yea();
                ans.y = b[2]+1900;
                ans.m = b[0];
                ans.d = b[1];
                set.add(ans);
            }
            if(b[1] <= 12 && b[0] <= 31&& b[1] != 0 && b[0] !=0){
                yea ans = new yea();
                ans.y = b[2]+1900;
                ans.m = b[1];
                ans.d = b[0];
                set.add(ans);
            }
        }
        for(yea t:set)
            System.out.printf("%d-%02d-%02d\n",t.y,t.m,t.d);
        sc.close();
    }
}
class yea implements Comparable{
    int y;
    int m;
    int d;
    public int compareTo(Object b){
        yea a = (yea)b;
        if(this.y>a.y)
            return 1;
        else if(this.y==a.y){
            if(this.m>a.m)
                return 1;
            else if(this.m==a.m){
                if(this.d>a.d)
                    return 1;
                else return -1;
            }
            else
                return -1;
        }
        else return -1;
    }
}

第十题

 

import java.util.Scanner;

public class integer{
    public static void main(String[] args) {
        int n;
        int sum;
        Scanner scanner = new Scanner(System.in);
        n=scanner.nextInt();
        sum=res(n,n);
        System.out.println(sum);
    }

    public static int res(int a,int max) {
        if(a==1||max==1)
            return 1;
        if(a==max)
            return res(a,max-1)+1;
        if(a>max)
            return res(a,max-1)+res(a-max,max);
        if(a<max)
            return res(a,a);
        else return 0;
    }
}

第十一题

 

 

import java.util.LinkedList;
import java.util.Queue;

public class step {
    public static class loc {
        int x;
        int step;
        loc(){
        }
    }
    static int forward[] = { 97 , -127};
    static int pos =50000;
    static boolean vis[]=new boolean[100000];
    public static void main(String[] args) {
        for(int i=0;i<100000;i++) {
            vis[i]=false;
        }
        Queue<loc> queue =new LinkedList<loc>();
        loc q=new loc();
        q.step=0;
        q.x=pos;
        queue.add(q);
        vis[pos]=true;
        while(!queue.isEmpty()) {
            loc s=queue.remove();
//			System.out.println(step);
            if(s.x == pos+1) {
                System.out.println(s.step);
                return ;
            }
            else {
                for(int i=0;i<2;i++) {
                    int tx=s.x+forward[i];
                    if(tx<0||tx>100000||vis[tx]) continue;
                    else {
                        vis[tx]=true;
                        loc t=new loc();
                        t.step=s.step+1;
                        t.x=tx;
                        queue.add(t);
                    }
                }
            }
        }

    }
}

第十二题

 

 

 

import java.util.Scanner;

public class tower {
    static int re = 0;
    static int cs(int m,int n){
        int num = m+n,c = 0;
        for(int i=1;i<num;i++){
            c += i;
            if(c == num)
                return i;
        }
        return 0;
    }
    static void dfs(char a[][],int cm,int cn,int M,int N,int d){
        if(M <0 || N<0)
            return;
        if(M == 0 && N==0 )
        {
            re++;
            return;
        }

        if(cn ==0){
            if(a[cm][cn] == 'A'){
                a[cm+1][cn] = a[cm+1][cn+1] = 'A';
                dfs(a,cm+(cn+1)/d,(cn+1)%d,M-2,N,d+(cn+1)/d);
                a[cm+1][cn] = a[cm+1][cn+1] = 'B';
                dfs(a,cm+(cn+1)/d,(cn+1)%d,M,N-2,d+(cn+1)/d);
            }else{
                a[cm+1][cn] = 'B';a[cm+1][cn+1] = 'A';
                dfs(a,cm+(cn+1)/d,(cn+1)%d,M-1,N-1,d+(cn+1)/d);
                a[cm+1][cn] = 'A';a[cm+1][cn+1] = 'B';
                dfs(a,cm+(cn+1)/d,(cn+1)%d,M-1,N-1,d+(cn+1)/d);
            }
        }
        else{
            if(a[cm][cn] == 'A'){
                if(a[cm+1][cn] == 'A'){
                    a[cm+1][cn+1] = 'A';
                    dfs(a,cm+(cn+1)/d,(cn+1)%d,M-1,N,d+(cn+1)/d);
                }
                else{
                    a[cm+1][cn+1] = 'B';
                    dfs(a,cm+(cn+1)/d,(cn+1)%d,M,N-1,d+(cn+1)/d);
                }
            }
            else{
                if(a[cm+1][cn] == 'A'){
                    a[cm+1][cn+1] = 'B';
                    dfs(a,cm+(cn+1)/d,(cn+1)%d,M,N-1,d+(cn+1)/d);
                }
                else{
                    a[cm+1][cn+1] = 'A';
                    dfs(a,cm+(cn+1)/d,(cn+1)%d,M-1,N,d+(cn+1)/d);
                }
            }
        }


    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner s = new Scanner(System.in);
        int M = s.nextInt(),N = s.nextInt();
        int c = cs(M,N);
        char a[][] = new char [c][];
        for(int i=0;i<c;i++){
            a[i] = new char[i+1];
        }
        a[0][0] = 'A';
        dfs(a,0,0,M-1,N,1);
        a[0][0] = 'B';
        dfs(a,0,0,M,N-1,1);
        System.out.println(re);
    }
}

第十三题

 

 

public class star{
    public static void main(String[] args) {
        dfs(0);

    }

    static int[] a = new int[] {1,2,3,4,5,7,8,9,10,12,13};
    static int n=11;

    static void dfs(int m) {
        if(m>=n) {

            if(check(a)) {
                System.out.println(a[1]+" "+a[2]+" "+a[3]+" "+a[4]);
                System.exit(0);
            }
            return;
        }
        for(int i=m;i<n;i++) {
            swap(i,m);
            dfs(m+1);
            swap(i,m);//回溯
        }
    }

    static void swap(int i,int j) {
        int t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static boolean check(int []A)
    {
        if(
                (A[1]+A[2]+A[3]+A[4])==(A[3]+A[6]+17)
                        &&(A[1]+A[2]+A[3]+A[4])==(A[2]+A[5]+20)
                        &&(A[1]+A[2]+A[3]+A[4])==(A[1]+A[5]+A[7]+A[0])
                        &&(A[1]+A[2]+A[3]+A[4])==(14+A[7]+A[8]+A[10])
                        &&(A[1]+A[2]+A[3]+A[4])==(A[0]+A[8]+A[9]+11)
                        &&(A[1]+A[2]+A[3]+A[4])==(A[6]+A[4]+A[9]+A[10])
        )
            return true;
        return false;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值