zoukankan      html  css  js  c++  java
  • “玲珑杯”ACM比赛 Round #19

    A -- A simple math problem

    Time Limit:2s Memory Limit:128MByte

    Submissions:1599Solved:270

    DESCRIPTION

    You have a sequence anan, which satisfies:

    Now you should find the value of 10an⌊10an⌋.

    INPUT
    The input includes multiple test cases. The number of test case is less than 1000. Each test case contains only one integer n(1n109)n(1≤n≤109)。
    OUTPUT
    For each test case, print a line of one number which means the answer.
    SAMPLE INPUT
    5
    20
    1314
    SAMPLE OUTPUT
    5
    21
    1317
    这个题就是找规律啊,一个很明显的规律是每一项都有一个贡献,但是这个范需要自己找,10的话按照log是要加1结果不需要,入手点就是这里,看看哪些少加了1,每个数量级多一个,这个pow损精度,wa了好几次,主要是n==1时输出值也是1,这个才是我被坑的最严重的
    以下是题解
    #include <stdio.h>
    #include <math.h>
    int pow10(int i){
    int ans=1;
    for(int j=0;j<i;j++)
        ans*=10;
    return ans;
    }
    int main(){
    int n;
    while(~scanf("%d",&n)){
    int ans=n+(int)log10(n*1.0);
    if(n==10)ans-=1;
    for(int i=2;i<=9;i++){
        int x=pow10(i);
        if(x+1-i<n&&n<x)
            ans++;
    }
    printf("%d
    ",ans);
    }
    return 0;}
    B - Buildings

    Time Limit:2s Memory Limit:128MByte

    Submissions:699Solved:186

    DESCRIPTION

    There are nn buildings lined up, and the height of the ii-th house is hihi.

    An inteval [l,r][l,r](lr)(l≤r) is harmonious if and only if max(hl,,hr)min(hl,,hr)kmax(hl,…,hr)−min(hl,…,hr)≤k.

    Now you need to calculate the number of harmonious intevals.

    INPUT
    The first line contains two integers n(1n2×105),k(0k109)n(1≤n≤2×105),k(0≤k≤109). The second line contains nn integers hi(1hi109)hi(1≤hi≤109).
    OUTPUT
    Print a line of one number which means the answer.
    SAMPLE INPUT
    3 1 1 2 3
    SAMPLE OUTPUT
    5
    HINT
    Harmonious intervals are: [1,1],[2,2],[3,3],[1,2],[2,3][1,1],[2,2],[3,3],[1,2],[2,3].
    模板题???区间最大值最小值的差小于等于k的值有多少组,单调栈,RMQ都不会被卡的
    #include <bits/stdc++.h>
    #define LL long long
    using namespace std;
    const int maxN = 2e5+10;
    int n, k, a[maxN];
    LL ans;
    void input() {
        scanf("%d%d", &n, &k);
        for (int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
    }
    void work() {
        ans = 0;
        deque<int> mi, ma;
        int p = 0;
        for (int i = 0; i < n; ++i) {
            while (!(mi.empty() && ma.empty()) &&
                    !(abs(a[i]-a[mi.front()]) <= k && abs(a[i]-a[ma.front()]) <= k)) {
                p++;
                while (!mi.empty() && mi.front() < p)
                    mi.pop_front();
                while (!ma.empty() && ma.front() < p)
                    ma.pop_front();
            }
            ans += i-p+1;
            while (!mi.empty() && a[mi.back()] > a[i])
                mi.pop_back();
            mi.push_back(i);
            while (!ma.empty() && a[ma.back()] < a[i])
                ma.pop_back();
            ma.push_back(i);
        }
        printf("%lld
    ", ans);
    }
    
    int main() {
        input();
        work();
        return 0;
    }

     ST表

    void rmqinit()  
    {  
        for(int i = 1; i <= n; i++) mi[i][0] = mx[i][0] = w[i];  
        int m = (int)(log(n * 1.0) / log(2.0));  
        for(int i = 1; i <= m; i++)  
            for(int j = 1; j <= n; j++)  
            {  
                mx[j][i] = mx[j][i - 1];  
                if(j + (1 << (i - 1)) <= n) mx[j][i] = max(mx[j][i], mx[j + (1 << (i - 1))][i - 1]);  
                mi[j][i] = mi[j][i - 1];  
                if(j + (1 << (i - 1)) <= n) mi[j][i] = min(mi[j][i], mi[j + (1 << (i - 1))][i - 1]);  
            }  
    }  
    int rmqmin(int l,int r)  
    {  
        int m = (int)(log((r - l + 1) * 1.0) / log(2.0));  
        return min(mi[l][m] , mi[r - (1 << m) + 1][m]);  
    }  
    int rmqmax(int l,int r)  
    {  
        int m = (int)(log((r - l + 1) * 1.0) / log(2.0));  
        return max(mx[l][m] , mx[r - (1 << m) + 1][m]);  
    }  
    大佬您太强了,还请多多指教哎
  • 相关阅读:
    oracle数据导出以及导入
    远程修改VMware ESXi服务器的密码(SSH)
    正确的姿势解决IE弹出证书错误页面
    win32.gui.api.con(前置,鼠标点击,发送数据的Dome)
    【转】python win32api win32gui win32con 简单操作教程(窗口句柄 发送消息 常用方法 键盘输入)
    autoit获取ie浏览器简单操作网页(GUI小工具)
    cmd命令行安装,删除Windows证书(certgmr的简单使用)
    windows安装tensorflow简单直接的方法(win10+pycharm+tensorflow-gpu1.7+cuda9.1+cudnn7.1)
    selenium获取新页面标签页(只弹出一个新页面的切换)
    selenium在页面中多个fream的定位
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7258287.html
Copyright © 2011-2022 走看看