头像

xiaozuo




离线:2小时前


活动打卡代码 AcWing 754. 平方矩阵 II

xiaozuo
1天前
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = 0;
        while(sc.hasNext()){
            n = sc.nextInt();
            for(int i = 0;i<n;i++){
                for(int j= 0;j<n;j++){
                    System.out.print((Math.abs(i-j)+1)+" ");
                }
                System.out.println();
            }

            if(n!=0){
                System.out.println();
            }
        }
    }
}


活动打卡代码 AcWing 1341. 十三号星期五

xiaozuo
2天前
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int year_len = sc.nextInt();
        int[] count = new int[7];
        for (int current_year = 1900; current_year < 1900 + year_len; current_year++)
            for (int current_month = 1; current_month <= 12; current_month++)
                count[week_day(current_year, current_month, 13)]++;
        System.out.println(count[6]+ " "+count[0]+ " "+count[1]+ " "+count[2]+ " "+count[3]+ " "+count[4]+" "+count[5]);
    }
    public static int week_day(int year, int month, int day)
    {
        if (month == 1 || month == 2){
            month += 12;
            year--;
        } 
        return (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400 + 1) % 7;
    }
}




活动打卡代码 AcWing 1532. 找硬币

xiaozuo
3天前
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),target = sc.nextInt();
        int[] arr = new int[n];
        int count = 0;
        for(int i =0;i<n;i++){
            arr[i] = sc.nextInt();

        }
        Arrays.sort(arr);
        solution(arr,target);
    }
    public static void solution(int[] arr,int target){
        int left = 0,right = arr.length-1;
        while(left < right){
            if(left!=right && arr[left]+arr[right] == target){
                System.out.println(arr[left]+" "+arr[right]);
                return ;
            }else if(arr[left]+arr[right] > target){
                right--;
            }else{
                left++;
            }
        }
        System.out.println("No Solution");
        return ;
    }
}


活动打卡代码 AcWing 1208. 翻硬币

xiaozuo
4天前
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();

        int res = 0;
        for(int i= 0;i<a.length-1;i++){
            if(a[i] != b[i]){
                if(a[i]=='*'){
                    a[i] = 'o';
                }else{
                    a[i]= '*';
                }   
                if(a[i+1] == '*'){
                    a[i+1] = 'o';
                }else{
                    a[i+1] = '*';
                }
                res++;
            }
        }
        System.out.println(res);
    }

}




活动打卡代码 AcWing 429. 奖学金

xiaozuo
5天前
import java.util.*;


class C{
    int id;
    int y;
    int total;
    public C(int id,int y,int total){
        this.id = id;
        this.y = y;
        this.total = total;
    }
}

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        C[] list = new C[n];
        for(int i= 0;i<n;i++){
            int y = sc.nextInt();
            int s = sc.nextInt();
            int yy = sc.nextInt();
            int sum = y+s+yy;
            C t = new C(i+1,y,sum);
            list[i] = t;
            // list.add(t);
        }

        // System.out.println(Arrays.toString(list));
        Arrays.sort(list,new Comparator<>(){

           @Override
           public int compare(C c1,C c2){
               // 先是总分 然后语文  最后id
                if(c1.total != c2.total) return c2.total - c1.total;
                if(c1.y != c2.y) return c2.y- c1.y;
                return c1.id - c2.id;
           }
        });
        for(int i = 0;i<list.length&& i<5;i++){
            System.out.println(list[i].id+" "+list[i].total);
        }
    }
}


新鲜事 原文

xiaozuo
5天前
争取今年之前把基础课看完两遍。。。。之后报个提高课看看


活动打卡代码 AcWing 1227. 分巧克力

xiaozuo
6天前
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[][] c = new int[n][2];
        int max = 0;
        for(int i = 0;i<n;i++){
            c[i][0] = sc.nextInt();
            c[i][1] = sc.nextInt();
            max = Math.max(max,Math.max(c[i][0],c[i][1]));
        }
        int l = 0,r = max;
        while(l < r){
            int mid = (l+r+1)/2;
            int cnt = 0;
            for(int i = 0;i<n;i++){
                cnt+=(c[i][0]/mid) * (c[i][1]/mid);
            }
            if(cnt >= k) l = mid;
            else r = mid-1;
        }
        System.out.println(l);
    }
}


活动打卡代码 AcWing 422. 校门外的树

xiaozuo
6天前
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int n = sc.nextInt();

        int[][] q = new int[n][2];
        for(int i =0;i<n;i++){
            q[i][0] = sc.nextInt();
            q[i][1] = sc.nextInt();
        }
        int res = L+1;
        Arrays.sort(q,(o1,o2)->(o1[0]-o2[0]));
        int l = q[0][0],r = q[0][1];
        for(int i=1;i<n;i++){
            if(r>=q[i][0]){
                r = Math.max(r,q[i][1]);
            }else{
                res -= r-l+1;
                l = q[i][0];
                r = q[i][1];
            }
        }
        res-= r-l+1;
        System.out.println(res);
    }
}


新鲜事 原文

xiaozuo
8天前
记 计算机一秒钟大概能算10^7~10^8量的数


活动打卡代码 AcWing 680. 剪绳子

xiaozuo
8天前
import java.util.*;

public class Main{
    static int N = 100010;
    static int[] a = new int[N];
    static int n,m;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < n; i++) a[i]=sc.nextInt();
        double l = 0, r = 1e9;
        while (r - l > 1e-3)//二分法
        {
            double mid = l + (r - l) / 2;
            if (check(mid)) l = mid;//若能剪出 mid 长度的
            else r = mid;
        }
        System.out.printf("%.2f", l);
    }
    static boolean check(double len)//剪长度为 len 的绳字是否能到 m 根
    {
        int res = 0;
        for (int i = 0; i < n; i++)
        {
            res += a[i] / len;//一根绳子能剪出多少长度为 m 的绳子
            if (res >= m) return true;
        }
        return false;
    }
}