ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

9.11 拉练

2021-09-11 22:34:47  阅读:155  来源: 互联网

标签:10 index int cin long 9.11 拉练 include


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;
}

 

标签:10,index,int,cin,long,9.11,拉练,include
来源: https://www.cnblogs.com/la-la-wanf/p/15256947.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有