9.11 拉练

2021/9/11 23:08:38

本文主要是介绍9.11 拉练,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

A签到 练习赛 - Virtual Judge (ppsucxtt.cn)

原链接 Div2 A, 难度800 Problem - 1554A - Codeforces

题意

t组数据中给出一个n(1~1e9),然后是长度为n的数列,求选定一段区间内最大值和最小值之积 最大。 区间范围:1≤l<r≤n

题解

不需要每个区间都遍历,只取相邻两个数的最大值即可。毕竟最大值附近越往外扩张最小值小的几率更大。

#include <string>
#include <iostream>
#include <cmath>

using namespace std;
typedef long long LL;

int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        LL n, l, r, res = 0;
        cin >> n >> l;
        for(LL i = 1; i < n; i ++)
        {
            cin >> r;    
            res = max(res, l*r);
            l = r;
        }
            
        cout << res <<endl;
            
        
    }
    
    return 0;
}

 

B最难的一个,思维题 练习赛 - Virtual Judge (ppsucxtt.cn)

原链接 Div2 C难度1600 Problem - 1567C - Codeforces

题意

给出你一个n让你求出有多少对a,b,(a,b颠倒位置也算一种)相加构成,运算规则:如果有进位将其进到前面两位的地方

题解

它的奇数会进到奇数位前一位,偶数也是,所以可以将题n为奇数位(记为x)和偶数位(记为y)组成的数字,如2021化为01和22,n为0~x 和0~y相加得到

结果输出:(x+1)*(y+1)-2     2是因为两个数不能有任意一数=0

#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;
typedef long long LL;
int a[30];

int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        int n, odd = 0, even = 0;
        cin >> n;
        
        int n1 = n, len = 0, index = 1;//不进位
        while(n1)
        {
            if(n1>9)
                index *= 10;
                
            len ++;
            n1/=10;
        }
        for(int i = len; i>0; i --)
        {
            if(i%2==1)//odd
                odd = odd*10+n/index;
            else
                even = even*10+n/index;
            n%=index; 
            index/=10;
        }
        
        // cout << odd << "  "<<even<<endl;
        cout << (odd+1)*(even+1)-2 <<endl;
    }
    
    return 0;
}

 

 

 C也算一个签到题,但是有小坑  练习赛 - Virtual Judge (ppsucxtt.cn)

原链接 Div2 A 900  Problem - 1555A - Codeforces

题意+题解

n个人切n块,不能切也可以>n块

可以把饼切成6 8 10块, 分别需15 20 25分钟,其实都是一块需5/2分钟,但是最少切六下

8 10存在的意义就是n>10时,奇数+1就可以正好切,偶数也可以正好切

#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;
typedef long long LL;

int main()
{
    int t;
    cin >> t;
    while(t --)
    {
        LL n;
        cin >> n;
        if(n<=6)
        cout << 15<<endl;
        else if(n<=8)
        cout << 20 << endl;
        else if(n<=10)
        cout << 25<<endl;
        else
        {
            n = (n+1)>>1;
            cout << n*(LL)5<<endl;
        }        
    }
    return 0;
}

 



这篇关于9.11 拉练的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程