2023年十四届蓝桥杯国赛(JavaB组)

2024-06-29 1229阅读

2023年十四届蓝桥杯国赛(JavaB组)

  • 前言
  • A: 互质
  • B: 逆元
  • C: 玩具
  • D: 不完整的等式
  • E: 星球
  • F: 序列
  • G: 电动车
  • H: 游戏
  • I: 非对称二叉树
  • J: 数和游戏

    前言

    2023年十四届蓝桥杯国赛(JavaB组)

    2023.6.16: 出成绩了,国一第15前排靠后,算是完成任务

    先简单写写,数据范围可能有小错,等题面出来了再更新

    2024.6.1:已更新体面,更新 I 题题解


    A: 互质

    本题总分:5分


    【问题描述】

    求出在 [ 1 , 202 3 2023 ] [1,2023^{2023}] [1,20232023]范围内,有多少个整数与 2023 2023 2023 互质,答案对 1 0 9 + 7 10^9+7 109+7取模。

    【答案提交】

    这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。


    640720414


    md考试时脑抽把 1 1 1 给减掉了,白白丢了 5 5 5 分。。

    易得 2023 = 7 ∗ 17 ∗ 17 2023=7*17*17 2023=7∗17∗17,故可以先求出与2023不互质的数,然后总数减去即可。

    设 a a a 为因数有7的数, b b b 为因数有17的数, c c c 为因数有7*17=119的数,显然不互质的数的总量为: a + b − c a+b-c a+b−c.

    	static long fpow(long a,long b) {
        	long res = 1;
        	a%=mod;
        	while(b>0) {
        		if(b%2==1) res = res*a%mod;
        		a = a*a%mod;
        		b/=2;
        	}
        	return res;
        }
        
        static void solve() throws IOException{
        	long res=fpow(2023,2023);
        	long a = fpow(2023,2023)*fpow(7,mod-2)%mod;
        	long b = fpow(2023,2023)*fpow(17,mod-2)%mod;
        	long c = fpow(2023,2023)*fpow(7*17,mod-2)%mod;
        	res = (res-a-b +c+2*mod)%mod;
        	pw.println(res);
        	
    	}
    

    B: 逆元

    本题总分:5分


    【问题描述】

    给定质数 M = 2146516019 M=2146516019 M=2146516019, 求出在 [ 1 , 233333333 ] [1,233333333] [1,233333333]内所有自然数的逆元。则所有逆元的异或和为多少?

    【答案提交】

    这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一 个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。


    1307261675


    快速幂暴力求逆元,逐个异或,比赛时跑了大概10多分钟

    	static long fpow(long a,long b) {
    		long res = 1;
        	a%=mod;
        	while(b>0) {
        		if(b%2==1) res = res*a%mod;
        		a = a*a%mod;
        		b/=2;
        	}
        	return res;
    	}
    	
        
    	static void solve() throws IOException{
    		mod = 2146516019;
    		ans=0;
    		for(int i=1;i
    			long res = fpow(i,mod-2);
    			ans ^=res;
    		}
    		System.out.println(ans);
    	}
    1,−⌊ip​⌋(p mod i)−1,​i=1i=1​(mod p)
        	mod = 2146516019;
        	long inv[] = new long[233333335];
        	inv[1]=1;
        	ans=1;
        	for(int i=2;i
        		inv[i] = (long)(mod-mod/i)*inv[(int)(mod%i)]%mod;
        		ans ^=inv[i];
        	}
        	pw.println(ans);
    	}
    
    	static int n,m,mod=(int)998244353,maxn=200005,inf=(int)1e9;
    	static long ans=0,INF=(long)1e18;
    	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    	static StreamTokenizer st = new StreamTokenizer(bf);
    	public static void main(String[]args) throws IOException{
    		int T = 1;
    		while(T--0) solve();
    	}
    	
    	static int I() throws IOException{
    		st.nextToken();
    		return (int)st.nval;
    	}
    	static void solve() throws IOException{
    		n = I();
    		long a[] = new long[maxn];
    		for(int i=1;i
    			ans += a[i]*a[j];
    		}
    		System.out.println(ans);
    	}
    }
    +,−,∗,/} 四个中的一个。  
         
          
           
           
             a 
            
           
             , 
            
           
             b 
            
           
             , 
            
           
             c 
            
           
             , 
            
           
             o 
            
           
             p 
            
           
          
            a,b,c,op 
           
          
        a,b,c,op 四个中一个会被  
         
          
           
           
             ? 
            
           
          
            ? 
           
          
        ? 代替,输出被代替的那个数或符号,保证有唯一解。
    	static int n,m,mod=(int)998244353,maxn=200005,inf=(int)1e9;
    	static long ans=0,INF=(long)1e18;
    	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    	static StreamTokenizer st = new StreamTokenizer(bf);
    	static PrintWriter pw = new PrintWriter(System.out);
    	public static void main(String[]args) throws IOException{
    		int T = 1;
    		//T = Integer.parseInt(S());
    		while(T--0) solve();
    		pw.flush();
    	}
    	
    	static int I() throws IOException{
    		st.nextToken();
    		return (int)st.nval;
    	}
    	static long c1(long a,long b,char op) {
    		if(op=='+') return a+b;
    		if(op=='-') return a-b;
    		if(op=='*') return a*b;
    		return a/b;
    	}
    	
    	static long c2(long a,long b,char op) {
    		if(op=='+') return a-b;
    		if(op=='-') return a+b;
    		if(op=='*') return a/b;
    		return a*b;
    	}
        
    	static void solve() throws IOException{
    		String s[] = S().split("=");
    		if(s[1].equals("?")) {
    			long a=0,b=0;
    			char op = ' ';
    			int i=0;
    			for(;i
    				char c = s[0].charAt(i);
    				if(c
    				char c = s[0].charAt(i);
    				b = b*10+(int)(c-'0');
    			}
    			pw.println(c1(a,b,op));
    		}
    		else {
    			if(s[0].charAt(0)=='?') {
    				long a=Long.parseLong(s[1]),b=0;
    				char op = ' ';
    				int i=1;
    				op = s[0].charAt(i++);
    				for(;i
    					char c = s[0].charAt(i);
    					b = b*10+(int)(c-'0');
    				}
    				pw.println(c2(a,b,op));
    			}
    			else {
    				long a=0,b=0;
    				char op = ' ';
    				int i=0;
    				for(;i
    					char c = s[0].charAt(i);
    					if(c
    					for(;i
    						char c = s[0].charAt(i);
    						b = b*10+(int)(c-'0');
    					}
    					long c = Long.parseLong(s[1]);
    					if(a+b==c) pw.println("+");
    					if(a*b==c) pw.println("*");
    					if(a/b==c) pw.println("/");
    					if(a-b==c) pw.println("-");
    				}
    				else {
    					b=Long.parseLong(s[1]);
    					pw.println(c1(a,b,op));
    				}
    			}
    		}
    	}
    }
    p1​,p2​,...,pn​},小明进攻所需的能量为  
         
          
           
           
             E 
            
           
             = 
            
            
            
              ∑ 
             
             
             
               i 
              
             
               = 
              
             
               2 
              
             
            
              n 
             
            
           
             d 
            
           
             ( 
            
            
            
              p 
             
             
             
               i 
              
             
               − 
              
             
               1 
              
             
            
           
             , 
            
            
            
              p 
             
            
              i 
             
            
           
             ) 
            
           
             ∗ 
            
            
            
              w 
             
            
              i 
             
            
           
          
            E=\sum_{i=2}^n d(p_{i-1},p_i)*w_i 
           
          
        E=∑i=2n​d(pi−1​,pi​)∗wi​,其中  
         
          
           
           
             d 
            
           
             ( 
            
            
            
              p 
             
             
             
               i 
              
             
               − 
              
             
               1 
              
             
            
           
             , 
            
            
            
              p 
             
            
              i 
             
            
           
             ) 
            
           
          
            d(p_{i-1},p_i) 
           
          
        d(pi−1​,pi​) 表示  
         
          
           
            
            
              p 
             
             
             
               i 
              
             
               − 
              
             
               1 
              
             
            
           
             , 
            
            
            
              p 
             
            
              i 
             
            
           
          
            p_{i-1},p_i 
           
          
        pi−1​,pi​ 两颗星球之间的直线距离。小明想知道进攻所需的最少能量是多少。
        static int maxn = 200005,n,m,inf=(int)2e9;
        static long INF = (long)2e18,ans = 0,mod = (int)1e9+7;
        static Scanner sc = new Scanner (System.in);
        static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        static StreamTokenizer st  =new StreamTokenizer(bf);
        static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        public static void main(String[]args) throws IOException{
            int T = 1;
            while(T--0) solve();
            pw.flush();
        }
        static final int I() throws IOException {
            st.nextToken();
            return (int)st.nval;
        }
        
        static long[]w=new long[20];
        static int []x = new int [20],y=new int [20],z=new int[20];
        static double as=INF;
        static double dis(int i,int j) {
        	if(i==0) return 0;
        	return Math.sqrt(Math.pow(x[i]-x[j], 2)+Math.pow(y[i]-y[j], 2)+Math.pow(z[i]-z[j], 2))*w[j];
        }
        
        static void solve() throws IOException{
        	n = I();
        	for(int i=1;i
        		x[i]=I();y[i]=I();z[i]=I();
        	}
        	m = 1
        		for(int i=0;i
        			dp[i][j] = INF;
        			if((j(i-1))%2==1) continue; //集合有 i,跳过
        			for(int k=1;k
        				if((j(k-1))%2==0) continue;
        				if(dp[i][j]  dis(i,k) + dp[k][j^(1b1​=d,b2​=2d,...,bn​=nd}。1,2,3,4}, 
         
          
           
            
            
              S 
             
            
              1 
             
            
           
             = 
            
           
             3 
            
           
          
            S_1=3 
           
          
        S1​=3。2,4,6,8}, 
         
          
           
            
            
              S 
             
            
              2 
             
            
           
             = 
            
           
             4 
            
           
          
            S_2=4 
           
          
        S2​=4。3,6,9,12}, 
         
          
           
            
            
              S 
             
            
              3 
             
            
           
             = 
            
           
             3 
            
           
          
            S_3=3 
           
          
        S3​=3。4,8,12,16}, 
         
          
           
            
            
              S 
             
            
              4 
             
            
           
             = 
            
           
             4 
            
           
          
            S_4=4 
           
          
        S4​=4。
        static int maxn = 200005,n,m,inf=(int)2e9;
        static long INF = (long)2e18,ans = 0,mod = (int)1e9+7;
        static Scanner sc = new Scanner (System.in);
        static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        static StreamTokenizer st  =new StreamTokenizer(bf);
        static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        public static void main(String[]args) throws IOException{
            int T = 1;
            //T = I();
            while(T--0) solve();
            pw.flush();
        }
        static final int I() throws IOException {
            st.nextToken();
            return (int)st.nval;
        }
        
        static int gcd(int a,int b) {
        	if(b==0) return a;
        	return gcd(b,a%b);
        }
        
        static long lcm(int a,int b) {
        	return 1L*a*b/gcd(a,b);
        }
        
        static void solve() throws IOException{
        	n = I();
        	for(int i=1;i
        		int a=I();
        		long x = lcm(a,i);
        		ans += (1L*n*i)/x;
        	}
        	pw.println(ans);
    	}
    }
    
        static int maxn = 200005,n,m,inf=(int)2e9;
        static long INF = (long)2e18,ans = 0,mod = (int)1e9+7;
        static Scanner sc = new Scanner (System.in);
        static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        static StreamTokenizer st  =new StreamTokenizer(bf);
        static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        public static void main(String[]args) throws IOException{
            int T = 1;
            while(T--0) solve();
            pw.flush();
        }
        static final int I() throws IOException {
            st.nextToken();
            return (int)st.nval;
        }
        
        static class edge{
        	int u,v,w;
        	public edge(int a,int b,int c) {
        		u=a;v=b;w=c;
        	}
        }
        
        static int p[] = new int [maxn];
        static int find(int x) {
        	if(p[x] == x) return x;
        	return p[x] = find(p[x]);
        }
        
        static Vector
        	Collections.sort(g,(o1,o2)-o1.w-o2.w);
        	int cnt=0;
        	for(edge x:g) {
        		int a=x.u,b=x.v,w=x.w;
        		int aa = find(a),bb = find(b);
        		if(aa!=bb) {
        			p[aa]=bb;
        			ans=w;
        			cnt++;
        		}
        	}
        	if(cnt!=n-1) pw.println(-1); //不连通
        	else pw.println(ans);
        }
        
        static void solve() throws IOException{
        	n = I();m=I();
        	while(m--0) {
        		g.add(new edge(I(),I(),I()));
        	}
        	krus();
    	}
    }
    
        static int maxn = 2000005,n,m,inf=(int)2e9;
        static long INF = (long)2e18,ans = 0,mod = (int)1e9+7;
        static Scanner sc = new Scanner (System.in);
        static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        static StreamTokenizer st  =new StreamTokenizer(bf);
        static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        public static void main(String[]args) throws IOException{
            int T = 1;
            //T = I();
            while(T--0) solve();
            pw.flush();
        }
        static final int I() throws IOException {
            st.nextToken();
            return (int)st.nval;
        }
        
        static int a[] = new int [maxn];
        static int mi[] = new int [maxn
        	mi[i] = Math.min(mi[i
        	if(l==r) {
        		mx[i]=mi[i]=a[l];return;
        	}
        	int mid=(l+r)/2;
        	build(i
        	if(ll
        	if(ll
        	n = I();m=I();
        	for(int i=1;i
        		a[i]=I();
        	}
        	build(1,1,n);
        	long cnt=n-m+1;
        	double ans=0;
        	for(int i=1;i+m-1
        		int j = i+m-1;
        		ans += query_mx(1,1,n,i,j) - query_mi(1,1,n,i,j);
        	}
        	pw.printf("%.2f\n",ans/cnt);
    	}
    }
    hli​​,hri​​}⩾k∗min{hli​​,hri​​},则此二叉树为一颗非对称二叉树。其中  
         
          
           
            
            
              l 
             
            
              i 
             
            
           
             , 
            
            
            
              r 
             
            
              i 
             
            
           
          
            l_i,r_i 
           
          
        li​,ri​ 分别是  
         
          
           
           
             i 
            
           
          
            i 
           
          
        i 的左儿子和右儿子,  
         
          
           
            
            
              h 
             
            
              x 
             
            
           
          
            h_x 
           
          
        hx​ 表示以  
         
          
           
           
             x 
            
           
          
            x 
           
          
        x 为根的子树高度(如果结点  
         
          
           
           
             x 
            
           
          
            x 
           
          
        x 不存在视为高度等于  
         
          
           
           
             0 
            
           
          
            0 
           
          
        0)。hli​​,hri​​}+1]=∑max{hli​​,hri​​}⩾k∗min{hli​​,hri​​}​dp[lcnt​][hli​​]∗dp[rcnt​][hri​​]
    	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in),65535);
    	static StreamTokenizer st = new StreamTokenizer(bf);
    	static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
    	static int n,m,maxn=200005,inf = 0x3f3f3f3f;
    	static long ans=0,mod=(int)1e9+7,INF=(long)2e18;
    	public static void main(String[]args) throws IOException{
    		new Task().main();
    		pw.flush();
    	}
    	static int I() throws IOException {
    		st.nextToken();
    		return (int)st.nval;
    	}
    	static class Task{
    		void main()throws IOException{
    			int t=1;
    			//t=I();
    			while(t--0) solve();
    		}
    		
    		long [][]dp = new long[44][44];
    		
    		private void solve() throws IOException {
    			n=I();m=I();
    			dp[1][1]=1;
    			dp[0][0]=1;
    			for(int i=2;i
    				for(int j=0;j
    					int k=i-j-1;
    					for(int h1=0;h1
    						for(int h2=0;h2
    							int mx = Math.max(h1, h2),mi = Math.min(h1, h2);
    							if(mx 
VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]