“蔚来杯“2022牛客暑期多校训练营1

A-Villages: Landlines

题意:

一维平面上有电力塔,电站等建筑物,两者都有一个接收信号半径,只要在半径范围之内都可接收到电,求需要最短的电线长度使所有建筑物相联通。

题解:

该题可以看成一个区间合并问题,将建筑物的坐标加减半径,即为一个区间,求每个连续区间之间的距离之和,判断不连续的方法为一区间的右端点大于前面连续区间的最大左段点。

#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define endl '\n'
#define N  200005
#define fi first
#define se second
#define pb push_back
using namespace std;
const int inf=0x3f3f3f3f;
const double ex=acos(-1);
const int mod=1e11+3;
int gcd(int a,int b){return b? gcd(b,a%b) : a ;}
typedef pair<int,int>PII;
priority_queue<int,vector<int>,greater<int> > q;
int a[N];
signed main()
{ios
    int t = 1, x , r;
    vector<PII>v;
    cin >> t;
    while (t--)
    {
        cin >>x>>r;
        v.pb({x-r,x+r});
    }
    sort(v.begin(),v.end());
    int res=v[0].se,ans=0;
    for(int i=1;i<v.size();i++)
    {
        if(v[i].fi>res)
        {
            ans+=v[i].fi-res;res=v[i].se;
        }else{
            res=max(res,v[i].se);
        }
    }
    cout <<ans;
    return 0;
}

D-Mocha and Railgun

题意:

1、给定一个圆心为原点的圆,以及一个在圆内的点Q

2、并且指定圆的半径r以及一个整数d

3、可以首先指定一个角度,然后形成一个角度为α,中点为Q,长度为2d的线段AB,然后把这个线段投影到圆边上形成一个弧。

4、可以任意选择角度,问这个弧最长可以是多少

题解:

当过AB的直线与圆心相交时,所对应的弧长最长。

故可旋转坐标系得:蓝色的线段为AB。我们只需求得a-b角对应的弧长即可:故求a和b的大小,可通过反三角函数求得,最后代入弧长公式求解。

G-Lexicographical Maximum

题意:

输入一个整数n,求1-n的最大值(按字典序排序),即把整数n看做一个字符串。

题解:

由题1-9的最大值为他们本身,1-89的最大值为9,max(1-90)=90,max(1-91)=91...max(1-100)= 99,max(1-989)=99,max(1-990)=990。可以发现:当整数有n位时,当至少前n-1位全为九时,最大值为该整数本身(只有一位则输出本身),否则输出n-1个9;

#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define endl '\n'
#define N  200005
#define fi first
#define se second
#define pb push_back
using namespace std;
const int inf=0x3f3f3f3f;
const double ex=acos(-1);
const int mod=1e11+3;
int gcd(int a,int b){return b? gcd(b,a%b) : a ;}
typedef pair<int,int>PII;
priority_queue<int,vector<int>,greater<int> > q;
int a[N];
void solve()
{
    string s;
    cin >>s;
    int k=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='9') k++;
        else break;
    }
    if(k>=s.size()-1)
    {
        cout <<s<<endl;
    }
    else
    {
        int n=s.size()-1;
        while(n--) cout <<"9";
        cout <<endl;
    }
}
signed main()
{ios
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

I-Chiitoitsu

题意:

题解:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值