第十四届蓝桥杯javac浅浅打卡一下

填空就不说了(反正错了)本文就不写解释了,等结果出来了再补一手吧

C:三国游戏

贪心

 


import java.io.*;
import java.util.Arrays;

/**
 * @ClassName 三国游戏
 * @Description TODO
 * @Author 小怂很怂
 * @Date 2023/4/8 13:40
 * @Version 1.0
 **/
public class 三国游戏 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
    static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws Exception {
        int n=nextInt();
        int []a=new int[n];
        int []b=new int[n];
        int []c=new int[n];
        for (int i=0;i<n;i++) a[i]=nextInt();
        for (int i=0;i<n;i++) b[i]=nextInt();
        for (int i=0;i<n;i++) c[i]=nextInt();
        for (int i=0;i<n;i++){
            int x=a[i],y=b[i],z=c[i];
            a[i]=x-y-z;
            b[i]=y-z-x;
            c[i]=z-x-y;
        }
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        int s=0;
        long sum=0,ans=0,count=0;
        for (int i=n-1;i>=0;i--){
            sum+=a[i];
            ans+=b[i];
            count+=c[i];
            if (sum>0||ans>0||count>0) s=n-i;
        }
        pw.println(s);
        pw.flush();
    }

    public static int nextInt() throws Exception {//int型
        st.nextToken();
        return (int) st.nval;
    }

    public static long nextLong() throws Exception {//long型
        st.nextToken();
        return (long) st.nval;
    }
}

D:平均

贪心

 


import java.io.*;
import java.util.Arrays;

/**
 * @ClassName 平均
 * @Description TODO
 * @Author 小怂很怂
 * @Date 2023/4/8 13:46
 * @Version 1.0
 **/
public class 平均 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
    static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws Exception {
        int n=nextInt();
        int [][]f=new int[n][2];
        int []d=new int[10];
        for (int i=0;i<n;i++){
            f[i][0]=nextInt();//值
            f[i][1]=nextInt();//价
        }
        Arrays.sort(f,((a,b)->{
            if (a[0]!=b[0]) return a[0]-b[0];
            return a[1]-b[1];
        }));
        long sum=0;
        for (int i=n-1;i>=0;i--){
            d[f[i][0]]++;
            if (d[f[i][0]]>n/10) sum+=f[i][1];
        }
        pw.println(sum);
        pw.flush();
    }

    public static int nextInt() throws Exception {//int型
        st.nextToken();
        return (int) st.nval;
    }

    public static long nextLong() throws Exception {//long型
        st.nextToken();
        return (long) st.nval;
    }
}

E:填充

贪心


import java.io.*;
import java.util.Scanner;

/**
 * @ClassName 填充
 * @Description TODO
 * @Author 小怂很怂
 * @Date 2023/4/8 13:54
 * @Version 1.0
 **/
public class 填充 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
    static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        String ss=sc.nextLine();
        boolean []f=new boolean[ss.length()+1];
        int count=0;
        for (int i=1;i<ss.length();i++){
            if (ss.charAt(i)=='?'){
                if (!f[i - 1]) {
                    count++;
                    f[i]=true;
                }else if (i!=ss.length()-1){
                    count++;
                    f[i+1]=true;
                    i++;
                }
            }else if (ss.charAt(i)==ss.charAt(i-1)&& !f[i - 1]||ss.charAt(i-1)=='?'&&!f[i-1]){
                count++;
                f[i]=true;
            }
        }
        pw.println(count);
        pw.flush();
    }

    public static int nextInt() throws Exception {//int型
        st.nextToken();
        return (int) st.nval;
    }

    public static long nextLong() throws Exception {//long型
        st.nextToken();
        return (long) st.nval;
    }
}

 

F:棋盘

差分前缀和

数据范围:对于所有评测用例,1 ≤ n, m ≤ 2000 ,1 ≤ x1 ≤ x2 ≤ n ,1 ≤ y1 ≤ y2 ≤ m 。


import java.io.*;

/**
 * @ClassName 棋盘
 * @Description TODO
 * @Author 小怂很怂
 * @Date 2023/4/8 13:59
 * @Version 1.0
 **/
public class 棋盘 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
    static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws Exception {
        int n=nextInt();
        int m=nextInt();
        int [][]f=new int[n+2][n+2];
        for (int i=0;i<m;i++){
            int x1=nextInt(),y1=nextInt(),x2=nextInt(),y2=nextInt();
            for (int j=x1;j<=x2;j++){
                f[j][y1]++;
                f[j][y2+1]--;
            }
        }
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++){
                f[i][j]+=f[i][j-1];
                if (f[i][j]%2==0) pw.print(0+" ");
                else pw.print(1+" ");
            }
            pw.println();
        }
        pw.flush();
    }

    public static int nextInt() throws Exception {//int型
        st.nextToken();
        return (int) st.nval;
    }

    public static long nextLong() throws Exception {//long型
        st.nextToken();
        return (long) st.nval;
    }
}

 

G:子矩阵

赛时代码忘记,暴力写的(1e9复杂度,5s不确定能不能过)

数据范围:对于所有评测用例,1 ≤ a ≤ n ≤ 1000 1 ≤ b ≤ m ≤ 1000 1 ≤ Ai, j ≤ 10^9 。

H:公因数匹配

一点点数学知识+贪心


import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName 公因数匹配
 * @Description TODO
 * @Author 小怂很怂
 * @Date 2023/4/8 14:24
 * @Version 1.0
 **/
public class 公因数匹配 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
    static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws Exception {
        int n=nextInt();
        Map<Integer,Integer> map=new HashMap<>();
        int min=99999999,max=0;
        int r=min,l=0;
        for (int i=0;i<n;i++){
            int a=nextInt();
            int k= (int) (Math.sqrt(a)+2);

            for (int j=2;j<=k;j++){
                if (a%j==0&&a!=j){
                    if (map.get(j)==null) map.put(j,i+1);
                    else{
                        r=Math.min(r,map.get(j));
                        l=i+1;
                    }
                    if (map.get(a/j)==null) map.put(a/j,i+1);
                    else {
                        r=Math.min(r,map.get(a/j));
                        l=i+1;
                    }
                }
            }
            if (map.get(a)==null) map.put(a,i+1);
            else if (a!=1){
                r=Math.min(r,map.get(a));
                l=i+1;
            }
            if (r!=min){
                min=r;
                max=l;
            }
        }
        pw.println(min+" "+max);
        pw.flush();
    }

    public static int nextInt() throws Exception {//int型
        st.nextToken();
        return (int) st.nval;
    }

    public static long nextLong() throws Exception {//long型
        st.nextToken();
        return (long) st.nval;
    }
}

I:异或和之差

暴力做的,代码忘了,应该是过40%数据

J:太阳

按照三角去判断的,按照高度排序然后一条一条往下判断,代码忘了,不确定对不对

祝各位看官姥爷都能省一进入决赛圈 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值