牛客暑期多校第一场

这篇博客探讨了几何问题在编程竞赛中的应用,包括球体与梯形的碰撞判断,以及如何计算球体被卡住的高度。此外,还讨论了如何在字符矩阵中寻找特定长度的连续零字符串,以及在100-200之间的3友好数的规律。文章还涉及了博弈论,分析了Alice和Bob在取石子游戏中的最优策略,以及在数组元素交换中最大化绝对差值的方法。

牛客多校第一场(罚坐)

B-Ball Dropping

A standard sphere ball is falling in the air, and the center of the sphere is exactly on the centerline of an empty isosceles trapezoidal. The trapezoid is hanging horizontally under the sphere.
Please determine whether the ball will get stuck in the trapezoid or drop past the trapezoid.
输入

The input contains four integers r, a, b, h(1 \le r,a,b,h \le 1000, a

b)r,a,b,h(1≤r,a,b,h≤1000,a>b), indicating the radius of the ball, the top base, the bottom base, and the height of the isosceles
trapezoid.

It is guaranteed that 2r != b , 2r < a , 2r < h.

输出

Output ‘Drop’ if the sphere ball will drop past the empty trapezoid,
otherwise output ‘Stuck’. If the answer is ‘Stuck’, please also
calculate the stuck position(the height between the center of the
sphere and the midpoint of the bottom base). Your answer is considered
correct if its absolute or relative error does not exceed 0.000001

在这里插入图片描述
由图中可知
可以将所求边换成x+y, x=r * sinc,y=h*(2rcosc-b)/(a-b);
其中,sinc=h/sqrt(hh+(a+b)(a+b)/4);
cosc=((a+b)/2)/sqrt(hh+(a+b)(a+b)/4);
由此就可以计算出来x+y的值即为我们所求的值
最后按精度输出即可

    #include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main(){
    double r,a,b,h;
    cin>>r>>a>>b>>h;
    if(2*r<=b){
        cout<<"Drop"<<endl;
    }
    else {
        cout<<"Stuck"<<endl;
        double c=(a-b)/2;
    double si=c/sqrt(c*c+h*h);
    double cs=h/sqrt(c*c+h*h);
    double sum=r*si+h*(2*r*cs-b)/(a-b);
    cout<<fixed<<setprecision(10)<<sum<<endl;
    }
    
}

Determine the Photo Position

在这里插入图片描述

题目的意思是给一个n*n的字符矩阵,将长度为m的老师覆盖在为字符矩阵中为零的地方,并且要求老师不能覆盖同学
我们只需要找到有多少个长度为m的连续为零的字符串(只能横着放)逐个加起来输出最后的结果。

#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
    int n, l;
    cin >> n >> l;
    vector<string>s(n);
    for (int i = 0; i < n; i++)cin >> s[i];
    string str;
    cin >> str;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        int flag = 0;
        for (int j = 0; j < n; j++) {
            if (s[i][j] == '0') {
                flag++;
            }
            else {
                flag = 0;
            }
             if(flag>=l)sum++;
        }
    }
    cout << sum << endl;
}

Find 3-friendly Integers

在这里插入图片描述
做着道题的时候感觉自己和傻子一样,将100-200中的所有数都列了出来发现全部都是3友好数
具体思考是以为在逐渐递增的时候 满足条件的数会越来越涵盖整个区间,而且只会增不会减,
所以想这道题的时候就在思考多少以后是全部满足条件的,最后发现在100以后是全部满足的而且
前一百个数中只有76个是满足的那么对于大于100的数就非常好计算了至于要用x-24就可以求出
在一百以内的数可以通过离线算或者是直接暴力的方法得到,给我们一个区间求区间内部的所有值
实际上我们可以转换为1到又端点中满足的数的个数减去1到左端点 - 1满足的个数。
原题链接
https://ac.nowcoder.com/acm/contest/11166/F

#include<iostream>
#include<vector>
using namespace std;
long long ste(long long x){
    if(x>=100)return x-24;
    long long sum=0;
    for(int i=1; i<=x; i++) {
            if(i%3==0)  sum++;
            else if(i/10!=0&&((i%10)%3==0||(i/10)%3==0||((i%10)+(i/10))%3==0)) sum++;
        }
    return sum;
}
int main(){
    int t;
    cin>>t;
    
    while(t--){
        long long l,r;
        cin>>l>>r;
        cout<<ste(r)-ste(l-1)<<endl;
    }
}

Alice and Bob

请添加图片描述
题意:
Alice和Bob进行一个游戏,在两堆石头分别为n,m中,在一堆中选取k个石子,在另一堆中选取sk个石子,不能进行这个操作的人输;
因为他们足够聪明,所以他们会尽量找到自己的必胜态,即目标点能不能一步到达。于是我们遍历所有的点,能一步到达0,0或者不能一步到达!(k,k
s)就是Alice胜,否则是Bob胜;
原题链接
https://ac.nowcoder.com/acm/contest/11166/A

#include<vector>
#include<iostream>
using namespace std;
bool a[5010][5010];
 
void check(){
    for(int i=0; i<=5000; i++){
        for(int j=0; j<=5000; j++){
            if(a[i][j]==0){
                for(int k=1; k+i<=5000; k++){
                    for(int s=0; s*k+j<=5000; s++){
                        a[k+i][s*k+j] = true;
                    }
                }
                for(int k=1; k+j<=5000; k++){
                    for(int s=0; s*k+i<=5000; s++){
                        a[s*k+i][k+j] = true;
                    }
                }
            }
        }
    }
}
int main() {
    int t;
	check();
    cin >> t;
    while (t--) {
        int m, n;
        cin >> m >> n;
        if (a[m][n])cout << "Alice" << endl;
        else cout << "Bob" << endl;
    }
}

Game of Swapping Numbers

请添加图片描述

题意
本题实际上将是将两个数组对应的位置,其中较大的数赋为正号,较小的数赋为负号,交换A数组中的元素<=k次,得到绝对值相差最大的那一组交换,我们可以先计算出目前的绝对值之和,通过交换使其增加,其实本质上,是我们“减多了“,现在我们将赋正的元素放进一组,将赋负的元素放入一组,我们多减的,实际上就”小数组中最大的元素比大数组中最小的数字”的差,我们要获得最大的差的话,就是要加上这部分减多了的元素。
原题链接
https://ac.nowcoder.com/acm/contest/11166/G

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	vector<int>b(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++)cin >> b[i];
	if (n == 2) {
		if (k % 2)swap(a[1], a[0]);
		cout << abs(a[0] - b[0]) + abs(a[1] - b[1]);
		return 0;
	}
	vector<int>ma(n);
	vector<int>mi(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += abs(a[i] - b[i]);
		ma[i] = max(a[i], b[i]);
		mi[i] = min(a[i], b[i]);
	}
	sort(ma.begin(), ma.end());
	sort(mi.begin(), mi.end());
	for (int i = 0; i < min(n, k); i++) {
		if(mi[n-i-1]>ma[i])sum += 2*(mi[n-1-i]-ma[i]);
	}
	cout << sum << endl;
}
源码地址: https://pan.quark.cn/s/a4b39357ea24 欧姆龙触摸屏编程软件MPTST 5.02是专门为欧姆龙品牌的工业触摸屏而研发的编程解决方案,它赋予用户在直观界面上构建、修改以及排错触摸屏应用程序的能力。 该软件在工业自动化领域具有不可替代的地位,特别是在生产线监视、设备操控以及人机互动系统中发挥着核心作用。 欧姆龙MPTST(Machine Process Terminal Software Touch)5.02版本配备了样化的功能,旨在应对不同种类的触摸屏项目要求。 以下列举了若干核心特性:1. **图形化编程**:MPTST 5.02采用图形化的编程模式,允许用户借助拖拽动作来设计屏幕布局,设定按钮、滑块、指示灯等组件,显著简化了编程流程,并提升了工作效率。 2. **兼容性**:该软件能够适配欧姆龙的个触摸屏产品线,包括CX-One、NS系列、NJ/NX系列等,使用户可以在同一个平台上完成对不同硬件的编程任务。 3. **数据通信**:MPTST 5.02具备与PLC(可编程逻辑控制器)进行数据交互的能力,通过将触摸屏作为操作界面,实现生产数据的显示与输入,以及设备状态的监控。 4. **报警与事件管理**:软件中集成了报警和事件管理机制,可以设定种报警标准,一旦达到预设条件,触摸屏便会展示对应的报警提示,助力操作人员迅速做出响应。 5. **模拟测试**:在设备实际连接之前,MPTST 5.02支持用户进行脱机模拟测试,以此验证程序的正确性与稳定性。 6. **项目备份与恢复**:为了防止数据遗失,MPTST 5.02提供了项目文件的备份及还原功能,对于版本控制与团队协作具有显著价值。 7. **语言支持**:针对全球化的应...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值