程序设计工作室1月21日内部训练赛

时间

2026 年 1 月 21 日 13:00 - 18:00

题解

https://gczdy.blog.csdn.net/article/details/157176670?spm=1001.2014.3001.5502

A Github关注Dddddduo喵

初中数学

曼哈顿环求中心点,只要判断记录第一个*和最后一个*出现的位置即可

复制代码
// https://github.com/Dddddduo/acm-java-algorithm
// powed by Dduo from bhu-acm
import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;

// 多多世界第一可爱!
public class Main {

    static IoScanner sc = new IoScanner();
//    static final int mod = (int) (1e9 + 7);
//    static final int mod = (int) (998244353);

    private static int n;
    private static int arr[];
    private static boolean visited[];
    private static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
    private static Stack<Integer> stack = new Stack<>();
    private static Queue<Integer> queue = new LinkedList<>();
    private static Deque<Integer> deque = new LinkedList<>();

    private static void solve() throws IOException {

        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<ArrayList<Character>> temp = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            temp.add(new ArrayList<>());
            String str = sc.next();
            for (int j = 0; j < m; j++) {
                temp.get(i).add(str.charAt(j));
            }
        }

        int firstX = -1;
        int firstY = -1;
        int lastX = 0;

        for (int i = 0; i < temp.size(); i++) {
            for (int j = 0; j < temp.get(i).size(); j++) {
                if(firstX == -1&&firstY==-1&&temp.get(i).get(j)=='#'){
                    firstX = i;
                    firstY = j;
                }
                if(temp.get(i).get(j)=='#'){
                    lastX = i;
                }
            }
        }

        sc.println((firstX+lastX+1)/2+1+" "+(firstY+1));

    }

    public static void main(String[] args) throws Exception {
        int t = 1;
        t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
        sc.flush();
        sc.bw.close();
    }

}

class IoScanner {
    BufferedReader bf;
    StringTokenizer st;
    BufferedWriter bw;

    public IoScanner() {
        bf = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
    }

    public String nextLine() throws IOException {
        return bf.readLine();
    }

    public String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    public char nextChar() throws IOException {
        return next().charAt(0);
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public float nextFloat() throws IOException {
        return Float.parseFloat(next());
    }

    public BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

    public BigDecimal nextDecimal() throws IOException {
        return new BigDecimal(next());
    }

    public void println(int a) throws IOException {
        print(a);
        println();
    }

    public void print(int a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void println(String a) throws IOException {
        print(a);
        println();
    }

    public void print(String a) throws IOException {
        bw.write(a);
    }

    public void println(long a) throws IOException {
        print(a);
        println();
    }

    public void print(long a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void println(double a) throws IOException {
        print(a);
        println();
    }

    public void print(double a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void print(BigInteger a) throws IOException {
        bw.write(a.toString());
    }

    public void println(BigInteger a) throws IOException {
        bw.write(a.toString());
        println();
    }

    public void print(char a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void println(char a) throws IOException {
        print(a);
        println();
    }

    public void println() throws IOException {
        bw.newLine();
    }

    //其他调试命令:
    public void flush() throws IOException {
        //交互题分组调试,或者提前退出的情况下可以先运行此语句再推出
        bw.flush();
        return;
    }

    public boolean hasNext() throws IOException {
        //本地普通IDE难以使用这个方法调试,需要按照数据组flush,刷新语句:
        //sc.flush()
        //调试完可删去
        return bf.ready();
    }

}

B 乌拉呀哈,呀哈乌拉

暴力求解的话最大时间复杂度为 n*n

可发现不会满足最大时间复杂度

外循环一步步左移

匹配的

内循环一直右移到头即可

复制代码
// https://github.com/Dddddduo/acm-java-algorithm

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.*;

// 多多世界第一可爱!
public class Main {

    private static IoScanner sc = new IoScanner();
//    static final int mod = (int) (1e9 + 7);
//    static final int mod = (int) (998244353);

    private static int n;
    private static int arr[];
    private static boolean visited[];
    private static ArrayList<ArrayList<Integer>> adj = new ArrayList<>();
    private static Stack<Integer> stack = new Stack<>();
    private static Queue<Integer> queue = new LinkedList<>();
    private static Deque<Integer> deque = new LinkedList<>();

    private static void solve() throws IOException {

        String str = sc.next();
        char[] arr = str.toCharArray();

        for (int i = 1; i < arr.length; i++) {
            int j = i;
            while(j>0){
                int current = arr[j] - '0';
                if(current==0){
                    j--;
                    continue;
                }
                int prev = arr[j-1] - '0';
                if(current-1>prev){
                    char temp = arr[j];
                    arr[j]=arr[j-1];
                    arr[j-1]=(char) (temp-'0'-1+'0');
                    j--;
                }else {
                    break;
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        for (char c : arr) {
            sb.append(c);
        }
        sc.println(sb.toString());

    }

    public static void main(String[] args) throws Exception {
        int t = 1;
        t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
        sc.flush();
        sc.bw.close();
    }

}

class IoScanner {
    BufferedReader bf;
    StringTokenizer st;
    BufferedWriter bw;

    public IoScanner() {
        bf = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
    }

    public String nextLine() throws IOException {
        return bf.readLine();
    }

    public String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    public char nextChar() throws IOException {
        return next().charAt(0);
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public float nextFloat() throws IOException {
        return Float.parseFloat(next());
    }

    public BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

    public BigDecimal nextDecimal() throws IOException {
        return new BigDecimal(next());
    }

    public void println(int a) throws IOException {
        print(a);
        println();
    }

    public void print(int a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void println(String a) throws IOException {
        print(a);
        println();
    }

    public void print(String a) throws IOException {
        bw.write(a);
    }

    public void println(long a) throws IOException {
        print(a);
        println();
    }

    public void print(long a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void println(double a) throws IOException {
        print(a);
        println();
    }

    public void print(double a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void print(BigInteger a) throws IOException {
        bw.write(a.toString());
    }

    public void println(BigInteger a) throws IOException {
        bw.write(a.toString());
        println();
    }

    public void print(char a) throws IOException {
        bw.write(String.valueOf(a));
    }

    public void println(char a) throws IOException {
        print(a);
        println();
    }

    public void println() throws IOException {
        bw.newLine();
    }

    //其他调试命令:
    public void flush() throws IOException {
        //交互题分组调试,或者提前退出的情况下可以先运行此语句再推出
        bw.flush();
        return;
    }

    public boolean hasNext() throws IOException {
        //本地普通IDE难以使用这个方法调试,需要按照数据组flush,刷新语句:
        //sc.flush()
        //调试完可删去
        return bf.ready();
    }

}

C 三个人?

贪心

最优解为先选行 再选列

可以证明无更优解

因为是先后顺序所以决定了贪心

复制代码
#include <iostream>
#include <vector>
using namespace std;
int main() 
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>>a(n, vector<int>(m));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    int num = 0;
    for (int i = 0; i < n; ++i)
    {
        int a_min = a[i][0];
        for (int j = 1; j < m; ++j)
        {
            if (a[i][j] < a_min) 
            {
                a_min = a[i][j];
            }
        }
        if (a_min > num)
        {
            num = a_min;
        }
    }
    cout << num << endl;
    return 0;
}

D 蛙蛙大王的考验

初中数学

核心的平方根、基础指数运算属于初中数学

复制代码
#include<bits/stdc++.h>
using namespace std;

int main(){
   	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	long double sum=a[0];
	for(int i=1;i<=n-1;i++){
		sum=sqrt(sum*a[i]);
	}
	cout<<sum<<endl;
	return 0;
}

E 猪猪医院的多多医生

可以暴力求解

根据题目意思模拟即可

复制代码
#include<bits/stdc++.h>
using namespace std;

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int sum=0;
		for(int i=0;i<n;i++){
			string m=s;
			if(m[i]=='0'){
				m[i]='1';
			}
			else{
				m[i]='0';
			}
			for(int j=0;j<n;j++){
				if(m[j]=='1'){
					sum++;
				}
			}	
		}
		cout<<sum<<endl;
	}
	
	return 0;
}

F 可我知道你还是爱着我

结论题,每次即选全部的数

选自牛客周赛

简单数论

SUM−MAX 的贡献随数的个数增加而增大

GCD 的贡献不会因增加数而变大,但整体收益仍更高

增加数可能导致 GCD 变小(比如原集合 {2,4} 的 GCD=2,加入 6 后仍为 2;加入 3 后变为 1)。

但 GCD 的贡献损失远小于 SUM−MAX 的增益

极端情况验证(k=1)

题目要求 "至少选 k 个",当 k=1 时:

选 1 个数:SUM−MAX = 数的和 - 最大值 = x - x = 0 → 目标值 = 0。

选所有数:目标值必然 ≥0(且几乎所有情况 > 0)。

因此选所有数仍最优。

复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int T;
    cin>>T;
    while(T--){
        long long L, R, k;
        cin>>L>>R>>k;
        cout << (L + R - 1) * (R - L) / 2 << "\n";
    }
    return 0;
}
相关推荐
Coder个人博客2 小时前
Linux6.19-ARM64 crypto NH-Poly1305 NEON子模块深入分析
linux·网络·算法·车载系统·系统架构·系统安全·鸿蒙系统
Engineer邓祥浩2 小时前
设计模式学习(15) 23-13 模版方法模式
java·学习·设计模式
茶本无香2 小时前
设计模式之四:建造者模式(Builder Pattern)详解
java·设计模式·建造者模式
毕设源码-赖学姐2 小时前
【开题答辩全过程】以 高校素拓分管理系统的设计与开发为例,包含答辩的问题和答案
java·eclipse
AI殉道师2 小时前
从0开发大模型之实现Agent(Bash到SKILL)
开发语言·bash
计算机学姐2 小时前
基于SpringBoot的社区互助系统
java·spring boot·后端·mysql·spring·信息可视化·推荐算法
skywalk81632 小时前
介绍一下 Backtrader量化框架(C# 回测快)
开发语言·c#·量化
源代码•宸2 小时前
Leetcode—3314. 构造最小位运算数组 I【简单】
开发语言·后端·算法·leetcode·面试·golang·位运算
lbb 小魔仙2 小时前
【Java】深入解析 Java 集合底层原理:HashMap 扩容与 TreeMap 红黑树实现
java·开发语言