2018-08-30 拼多多笔试

2018-08-30  本文已影响0人  菜鸡学算法

T1:

public class TT1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int HP = sc.nextInt();
        int normalAttack = sc.nextInt();
        int buffedAttack = sc.nextInt();
        if(normalAttack * 2 >= buffedAttack) {
            int res = HP/normalAttack;
            if(HP%normalAttack!=0)
                res += 1;
            System.out.println(res);
        }else {
            int res = HP/buffedAttack*2;
            if(HP%buffedAttack!=0) {
                if(HP%buffedAttack<normalAttack)
                    res += 1;
                else res += 2;
            }
            System.out.println(res);
        }
    }
    }

T2:

public class TT2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[][] str = new char[n][m];
        sc.nextLine();
        for (int i = 0;i < n;i ++){
            String input=sc.nextLine();
            str[i] = input.toCharArray();
        }
        for(int i=0;i<m;i++){
            for(int j=n-1;j>=0;j--){
                if(str[j][i]!='o')continue;
                int k = j;
                while(k<n){
                    str[k][i]='.';
                    k++;
                    if(k<n&&str[k][i]!='.'){
                        str[k-1][i]='o';
                        break;
                    }
                }
            }          
        }
        for (int i = 0;i < n;i ++){
            System.out.println(new String(str[i]));
        }
    }
}

T3:

public class TT3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        Map<Integer,Integer> map = new HashMap<>();
        a %= b;
        if(a==0){
            System.out.println(0+" "+0);
        }else{
            int x = 1;
            while(!map.containsKey(a) && a != 0){
                map.put(a, x++);
                a = a*10;
                a %= b;
            }
            if(a==0){
                System.out.println(x-2+" "+0);
            } else{
                System.out.println(map.get(a)-1+" "+(x-map.get(a)));
            }
        }       
    }
}

T4:

public class TT5 {
    static int flag = 0;
    static Map<String,Integer> map = new HashMap<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        sc.nextLine();
        char[] ans = new char[l];
        int[][] vis = new int[l][26];
        for(int i=0;i<n;i++){
            String s = sc.nextLine();
            for(int j=0;j<l;j++){
                vis[j][s.charAt(j)-'A']=1;
            }
            map.put(s,1);
        }
        dfs(0,vis,ans);
        if(flag==0) System.out.println("-");         
    }

    public static void dfs(int len,int[][] vis,char[] ans) {
        if(flag==1)return;
        if(len==vis.length){
            String s = new String(ans);
            if(!map.containsKey(s)){
                System.out.println(s);
                flag = 1;
            }
            return;
        }
        for(int j=0;j<26;j++){
            if(vis[len][j]==1){
                ans[len] = (char)('A'+j);
                dfs(len+1,vis,ans);
            }
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读