头像

2098274677




离线:3天前


最近来访(0)


2098274677
7个月前
import java.util.Scanner;

public class Main{

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

        for(int i=0;i<n;i++){
            int res=0;
            a[i]=in.nextInt();
            while(a[i]>0){
                a[i]-=lowbit(a[i]);
                res++;
            }
            System.out.print(res+" ");
        }
    }
    public static int  lowbit(int x){
        return x&-x;
    }
}


活动打卡代码 AcWing 2816. 判断子序列

2098274677
7个月前
import java.util.Scanner;

publlic class Main{

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

        int []a=new int[n];
        int []b=new int[m];

        int i=0;
        int j=0;

        while(i<n && j<m){
            if(a[i]!=b[j]){
                j++;
            }else{
                i++;
                j++;
            }
        }
        if(i==n){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }



    }
}



2098274677
7个月前
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner in=new Scanner (System.in);
        int n=in.nextInt();
        int m=in.nextInt();
        int x=in.nextInt();

        int []a =new int [n];
        int []b =new int [m];

        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
        }
        for(int i=0;i<m;i++){
            b[i]=in.nextInt();
        }
        for(int i=0,j=m-1;i<n;i++){
            while(j>0 && a[i]+b[j]>x){
                j--;
            }if(a[i]+b[j]==x){
                System.out.println(i+" "+j);
                break;
            }
        }
    }
}



2098274677
7个月前
import java.util.Scanner;
public class Main{
    static int N=10010;
    public static void main(String[] args){
        Scanner in=new Scanner (System.in);
        int n=in.nextInt();
        int []a=new int[n];
        int []s=new int[N];
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
        }
        System.out.println(put(a,s,n));
    }
    public static int put(int []a,int []s,int n){
        int res=0;
        for(int i=0,j=0;i<n;i++){
            s[a[i]]++;
            while(j<i &&s[a[i]]>1){
                s[a[j]]--;
                j++;
            }
            res=Math.max(res,i-j+1);
        }
        return res;
    }
}



活动打卡代码 AcWing 798. 差分矩阵

2098274677
7个月前
import java.io.*;

public class Main{
    static int N=1010;

    public static void main(String[] args)throws IOException{
        BufferedReader reader=new BufferedReader (new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] str1 = reader.readLine().split(" ");
        int n=Integer.parseInt(str1[0]);
        int m=Integer.parseInt(str1[1]);
        int p=Integer.parseInt(str1[2]);
        int [][]a=new int [N][N];
        int [][]b=new int [N][N];
        for(int i=1;i<=n;i++){
            String[] str2 = reader.readLine().split(" ");
            for(int j=1;j<=m;j++){
                int c = Integer.parseInt(str2[j - 1]);
                cha(b,i,j,i,j,c);
            }
        }

        while(p-->0){
            String[] str3 = reader.readLine().split(" ");
            int x1 = Integer.parseInt(str3[0]);
            int y1 = Integer.parseInt(str3[1]);
            int x2 = Integer.parseInt(str3[2]);
            int y2 = Integer.parseInt(str3[3]);
            int c = Integer.parseInt(str3[4]);
            cha(b,x1,y1,x2,y2,c);
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                b[i][j]+=b[i][j-1]+b[i-1][j]-b[i-1][j-1];
            }

        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                writer.write(b[i][j] + " ");
            }
             writer.write("\n");
        }
         writer.flush();
    }
    public static void cha(int [][]b,int x1,int y1,int x2,int y2,int c){
        b[x1][y1]+=c;
        b[x1][y2+1]-=c;
        b[x2+1][y1]-=c;
        b[x2+1][y2+1]+=c;
    }
}


活动打卡代码 AcWing 797. 差分

2098274677
7个月前
import java.util.Scanner ;
import java.io.BufferedInputStream;

public class Main{
    static int N=10010;
    public static void main(String[] args){
        Scanner in=new Scanner (new BufferedInputStream(System.in));
        int n=in.nextInt();
        int m=in.nextInt();
        int []a=new int[N];
        int []b=new int[N];
        for(int i=1;i<=n;i++){
            a[i]=in.nextInt();
        }
        for(int i=1;i<=n;i++){
            cha(b,i,i,a[i]);
        }
        while(m-->0){
            int l=in.nextInt();
            int r=in.nextInt();
            int c=in.nextInt();
            cha(b,l,r,c);
        }
        for(int i=1;i<=n;i++){
            b[i]+=b[i-1];
        }
        for(int i=1;i<=n;i++){
            System.out.print(b[i]+" ");
        }
        System.out.println();
    }

    public static void cha(int []b,int l,int r,int c){
        b[l]+=c;
        b[r+1]-=c;
    }
}


活动打卡代码 AcWing 796. 子矩阵的和

2098274677
7个月前
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int m=in.nextInt();
        int p=in.nextInt();
        int [][]a=new int [n+1][m+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                a[i][j]=in.nextInt();
            }
        }
        int [][]s=new int[n+1][m+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
            }
        }
        while(p-->0){
            int x1=in.nextInt();
            int y1=in.nextInt();
            int x2=in.nextInt();
            int y2=in.nextInt();
            System.out.println(s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1]);
        }
    }
}


活动打卡代码 AcWing 795. 前缀和

2098274677
7个月前
import java.util.*;
import java.io.BufferedInputStream;
public class Main{
    static int N=10010;


    public static void main(String[] args){
        Scanner in=new Scanner(new BufferedInputStream(System.in));
        int []a=new int [N];
        int n=in.nextInt();
        int m=in.nextInt();
        for(int i=1;i<=n;i++){
            a[i]=in.nextInt();
        }
        int []s=new int [N];
        s[0]=0;
        for(int i=1;i<=n;i++){
            s[i]=s[i-1]+a[i];
        }
        while(m-->0){
            int l=in.nextInt();
            int r=in.nextInt();
            System.out.println(s[r]-s[l-1]);
        }
    }
}


活动打卡代码 AcWing 794. 高精度除法

2098274677
7个月前
import java.math.BigInteger;
import java.io.*;
public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        BigInteger a=new BigInteger(in.readLine());
        BigInteger b=new BigInteger(in.readLine());

        BigInteger []arr=a.divideAndRemainder(b);
        System.out.println(arr[0]);
        System.out.println(arr[1]);

        in.close();
    }
}


活动打卡代码 AcWing 793. 高精度乘法

2098274677
7个月前
import java.math.BigInteger;
import java.io.*;
public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

        BigInteger a=new BigInteger(in.readLine());
        BigInteger b=new BigInteger(in.readLine());

        System.out.println(a.multiply(b));

        in.close();
    }
}