“玲珑杯”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(1≤n≤109)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\n",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](l≤r)(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(1≤n≤2×105),k(0≤k≤109)n(1≤n≤2×105),k(0≤k≤109). The second line contains nn integers hi(1≤hi≤109)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\n", ans);
}

int main() {
    input();
    work();
    return 0;
}
时间: 2024-10-21 06:00:31

“玲珑杯”ACM比赛 Round #19的相关文章

“玲珑杯”ACM比赛 Round #19题解&amp;源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】

A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT 5 20 1314 SAMPLE OUTPUT 5 21 1317 SOLUTION “玲珑杯”ACM比赛 Round #19 题目链接:http://www.ifrog.cc/acm/problem/1145 分析: 这个题解是官方写法,官方代码如下: 1 #include <iostream>

“玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)

“玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-07-29 16:42:55 Private B -- Buildings Time Limit:2s Memory Limit:128MByte Submissions:590Solved:151 DESCRIPTION There are nn buildings lined up, and th

玲珑杯”ACM比赛 Round #19 B 维护单调栈

1149 - Buildings Time Limit:2s Memory Limit:128MByte Submissions:588Solved:151 DESCRIPTION There are nn buildings lined up, and the height of the ii-th house is hihi. An inteval [l,r][l,r](l≤r)(l≤r) is harmonious if and only if max(hl,…,hr)−min(hl,…,

“玲珑杯”ACM比赛 Round #19 B -- Buildings

#include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<cmath> #include<set> #include<stack> #def

“玲珑杯”ACM比赛 Round #1

Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public A -- Absolute Defeat Time Limit:2s Memory Limit:64MByte Submissions:394Solved:119 DESCRIPTION Eric has an array of integers a1,a2,...,ana1,a2,...,an.

“玲珑杯”ACM比赛 Round #18 A 暴力水 C dp

“玲珑杯”ACM比赛 Round #18 计算几何你瞎暴力 题意:如果从一个坐标为 (x1,y1,z1)的教室走到(x2,y2,z2)的距离为 |x1−x2|+|y1−y2|+|z1−z2|.那么有多少对教室之间的距离是不超过R的呢? tags:坐标范围很小,瞎暴力 #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring>

“玲珑杯”ACM比赛 Round #18

"玲珑杯"ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time Limit:5s Memory Limit:256MByte Submissions:1764Solved:348 DESCRIPTION 今天HHHH考完了期末考试,他在教学楼里闲逛,他看着教学楼里一间间的教室,于是开始思考: 如果从一个坐标为 (x1,y1,z1)(x1,y1,z1)的

“玲珑杯”ACM比赛 Round #18 图论你先敲完模板(dp)

题目链接:http://www.ifrog.cc/acm/problem/1146 题意:中文题 题解:状态转移方程:dp[ i ] = min ( dp[ i ] ,dp[ j ] + 2xi-xj+a ). dp[1]=0,第一个点需要消耗的能量为0,从第二个点(假设这个点为A)开始,往前遍历一遍点(假设这个点为B)假定B点为休息点,然后直接到A点需要的能量, 依次然后找出最小能量,因为从第二个点依次往后,每次前面的都已经最优了,所以最后n位置得到的就是答案了. 然后有几个注意点INF尽量弄

“玲珑杯”ACM比赛 Round #18 A 计算几何你瞎暴力(瞎暴力)

题目链接:http://www.ifrog.cc/acm/problem/1143 题意:如果从一个坐标为 (x1,y1,z1)(x1,y1,z1)的教室走到(x2,y2,z2)(x2,y2,z2)的距离为 |x1−x2|+|y1−y2|+|z1−z2| 那么有多少对教室之间的距离是不超过R的呢? 题解:暴力暴力,把点记录在三维数组里面,然后暴力搜寻符合条件的点,值得注意的是在同个位置可能有不同的教室(明显不符合现实,蜜汁尴尬(逃.....) 不同位置直接暴力,会重复计算一次,比如点(1,2,3