首页 > 其他分享 >牛客多校训练营2022年(一)

牛客多校训练营2022年(一)

时间:2022-12-16 13:33:06浏览次数:52  
标签:const int double list 多校 牛客 program 2022 Eibwen

Lexicographical Maximum

Eibwen is a newbie in Python.

You might know that when you input a number in the command line, your Python program will receive a string containing that number instead of a number that can be used to calculate. This is an interesting feature that a newbie might not know.

Eibwen wants to find the maximum of some given numbers, so he writes a program to sort the list of the numbers and print the last element in the sorted list. However, as a newbie, Eibwen doesn't know the feature. He actually sorts the list of number strings in lexicographical order and prints the last string in the list.

Now Eibwen runs his program, inputs all the integers from 1 to n, and finds his program really slow. Could you help

him find out the expected output of his program?

Input

The only line contains an integer n — the size of Eibwen's input.

Output
Print the expected output of Eibwen's program in a single line, which actually is the lexicographically maximum from 1 to n.

input output
616 99

 

做法:贪心,如果n这个数的前n-1位都是9,则直接输出这个数,否则就输出n-1个数字9。
#include <iostream>
#define int long long 
const int N=1000010;


using namespace std;
signed main()
{
    string s;
    cin>>s;
    int cnt = 0;
    int l = s.size();
    for(int i = 0;i < l - 1;i ++ )
    {
        if(s[i] == '9')
        {
            cnt ++ ;
            
        }
        
    }
    if(cnt == l - 1)
    {
        for(int i = 0;i < l ;i ++ )
        {
            cout<<s[i];
        }
    }
    else
    {
        for(int i = 0;i < l - 1;i ++ )
        {
            cout<<"9";
        }
    }
    return 0;
    
}

 Villages: Landlines

 

 

 

 

做法:我们将所有坐标及半径看成n个坐标轴上的区间,假设发电站的范围内有无数个变电塔,我们就只需要计算从左到右的区间中不连通区域的长度,这个长度就是所要求的导线长度。在输入时,我们将坐标x与半径r转化为区间的左右端点[x-r.x+r],然后对所有区间进行排序,再扫一遍找到区间中不连通区域的长度即可。

#include <bits/stdc++.h>
using namespace std;
const int N=1000010;


struct node 
{
    int l, r;
}a[N];
bool cmp(node a,node b)
{
    if(a.l == b.l)
    {
        return a.r < b.r;
    }
    return a.l < b.l;
}
signed main()
{
    int n;
    cin>>n;
    for(int i = 1 ; i <= n ; i ++ )
    {
        int x, r;
        cin>>x>>r;
        a[i].l = x - r;
        a[i].r = x + r;
    }
    sort(a + 1, a + 1 + n, cmp);
    int ans = 0;
    int right = a[1].r;
    for(int i = 2; i <= n; i ++)
    {
        if(a[i].l <= right)
        {
            right = max(a[i].r, right);
        }
        else
        {
            ans += a[i].l - right;
            right = a[i].r;
        }
    }
    cout << ans;
    return 0;
    
}

Mocha and Railgun

 

 

 

 

 

#include <bits/stdc++.h>
#define int long long 
const int N=10000010;


const double pi = acos(-1);
using namespace std;
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        double r;
        
        double x, y, d;        
        cin>>r>>x>>y>>d;
        
        double dis = sqrt(x * x + y * y);
        double a1 = acos((d - dis) / r);
        double a2 = acos((d + dis) / r);
        double a3 = pi - a1 - a2;
        

        printf("%.12lf\n",a3 * r);
    }
    return 0;
    
}

 

标签:const,int,double,list,多校,牛客,program,2022,Eibwen
From: https://www.cnblogs.com/codeforceshobby/p/16986862.html

相关文章