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. Java常用函数式接口--Consumer接口使用案例

    第一种方式: 第二种方式:

  2. [问题记录]Ubuntu下chmsee安装失败的解决

    日期:2016年2月26日 一直在找Ubuntu下查看chm的工具但是普遍不理想,发现在deepin中的chmsee相对比较好,但是直接执行网上的sudo apt-get install chmsee ...

  3. js对象引用赋值后

    a={f:1} b={} b.a=a console.log(b.a) a.b=2 console.log(b.a) a={f:1} b={} b.a=a console.log(b.a) a={b: ...

  4. [Luogu1343]地震逃生 最大流

    题目链接:https://www.luogu.org/problem/show?pid=1343 dinic跑最大流. #include<cstdio> #include<cstri ...

  5. 初学者应该怎么学习前端?web前端的发展路线大剖析!

    写在最前: 优秀的Web前端开发工程师要在知识体系上既要有广度和深度!应该具备快速学习能力. 前端开发工程师不仅要掌握基本的Web前端开发技术,网站性能优化.SEO和服务器端的基础知识,而且要学会运用 ...

  6. git的基本使用命令操作

    Linux操作命令行:    mkdir - 创建文件夹,    cd - 切换文件路径    pwd - 显示文件路径    ls -ah - 可以查看隐藏的文件夹名(.git)    cat 文件 ...

  7. UVALive 3211 Now or Later (2-SAT)

    题目的要求一个最小值最大,二分即可,但是怎么判断呢? 飞机早或者晚两种状态,可以用一个布尔变量表示,假设当前猜测为m,那么根据题意, 如果x和y所对应的时间冲突那么就是¬(xΛy)化成或的形式(¬x) ...

  8. websocket 入门

    什么是websocket WebSocket是HTML5新增的协议,它的目的是在浏览器和服务器之间建立一个不受限的双向通信的通道,比如说,服务器可以在任意时刻发送消息给浏览器. 为什么会出现 webs ...

  9. Emmet:HTML/CSS代码快速编写神器--20150422

    Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度,比如下面的演示: ...

  10. 【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands

    看似区间数据结构的一道题 题目描述 Bessie and her friends are playing a unique version of poker involving a deck with ...