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=;
for(int j=;j<i;j++)
ans*=;
return ans;
}
int main(){
int n;
while(~scanf("%d",&n)){
int ans=n+(int)log10(n*1.0);
if(n==)ans-=;
for(int i=;i<=;i++){
int x=pow10(i);
if(x+-i<n&&n<x)
ans++;
}
printf("%d\n",ans);
}
return ;}
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+;
int n, k, a[maxN];
LL ans;
void input() {
scanf("%d%d", &n, &k);
for (int i = ; i < n; ++i)
scanf("%d", &a[i]);
}
void work() {
ans = ;
deque<int> mi, ma;
int p = ;
for (int i = ; 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+;
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 ;
}

ST表

void rmqinit()
{
for(int i = ; i <= n; i++) mi[i][] = mx[i][] = w[i];
int m = (int)(log(n * 1.0) / log(2.0));
for(int i = ; i <= m; i++)
for(int j = ; j <= n; j++)
{
mx[j][i] = mx[j][i - ];
if(j + ( << (i - )) <= n) mx[j][i] = max(mx[j][i], mx[j + ( << (i - ))][i - ]);
mi[j][i] = mi[j][i - ];
if(j + ( << (i - )) <= n) mi[j][i] = min(mi[j][i], mi[j + ( << (i - ))][i - ]);
}
}
int rmqmin(int l,int r)
{
int m = (int)(log((r - l + ) * 1.0) / log(2.0));
return min(mi[l][m] , mi[r - ( << m) + ][m]);
}
int rmqmax(int l,int r)
{
int m = (int)(log((r - l + ) * 1.0) / log(2.0));
return max(mx[l][m] , mx[r - ( << m) + ][m]);
}

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

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

    A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...

  2. “玲珑杯”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-0 ...

  3. lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP

    E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...

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

    1149 - Buildings Time Limit:2s Memory Limit:128MByte Submissions:588Solved:151 DESCRIPTION There are ...

  5. “玲珑杯”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 ...

  6. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  7. “玲珑杯”ACM比赛 Round #18

    “玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...

  8. “玲珑杯”ACM比赛 Round #1 题解

    A:DESCRIPTION Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a co ...

  9. 玲珑杯”ACM比赛 Round #4 1054 - String cut 暴力。学到了扫描的另一种思想

    http://www.ifrog.cc/acm/problem/1054 问删除一个字符后的最小循环节是多少. 比赛的时候想不出,不知道怎么暴力. 赛后看了别人代码才晓得.唉,还以为自己字符串还不错, ...

随机推荐

  1. Flask 学习系列(二)---Jinjia2模板

    下面是一个jinjia2的简单模板的例子: <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  2. AJPFX关于子类父类中的构造

    1.子父类中的构造函数不存在重写,因为子父类的构造函数名字不一样(重写要求子父类的方法名字一模一样,包括参数列表)2.子类创建对象时会先运行父类的构造函数再运行子类的构造函数.因为每个子类的构造函数的 ...

  3. [BZOJ2982]combination Lucas定理

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2982 $C(N,M)\% P = C(N\% P,M\% P) * C(N/P,M/P)\ ...

  4. arcgis jsapi接口入门系列(10):图形高亮

    jsapi也有提供高亮的实现接口,但这里没用,而用的是一种改变图形(graphic)样式的思路 本文实现效果是:地图有多个面图形,当鼠标移动到面的上方,面高亮显示,鼠标移出后高亮解除 初始化 //高亮 ...

  5. 详解ASP.NET缓存机制

    文中对ASP.NET的缓存机制进行了简述,ASP.NET中的缓存极大的简化了开发人员的使用,如果使用得当,程序性能会有客观的提升.缓存是在内存存储数据的一项技术,也是ASP.NET中提供的重要特性之一 ...

  6. OpenCV中CvMat的初始化[转]

    一)cvCreateMat创建和分配数据CvCreateMat会创建CvMat,并为CvMat分配数据.cvCreateMat可以配合cvInitMatHeader来初始化CvMat对象.因为CvCr ...

  7. 【Web应用】JAVA网络上传大文件报500错误

    问题描述 当通过 JAVA 网站上传大文件,会报 500 错误. 问题分析 因为 Azure 的 Java 网站都是基于 IIS 转发的,所以我们需要关注 IIS 的文件上传限制以及 requestT ...

  8. 查看进程lsof

    查看8000端口 lsof -i :8000 杀死进程 pkill -ns <pid>

  9. 产生式模型(生成式模型)与判别式模型<转载>

    转自http://dongzipnf.blog.sohu.com/189983746.html 产生式模型与判别式模型 产生式模型(Generative Model)与判别式模型(Discrimiti ...

  10. A. Pride (emmmm练习特判的好题)

    题目连接 : http://codeforces.com/problemset/problem/891/A You have an array a with length n, you can per ...