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. Less的学习和使用

    官网 http://less.bootcss.com/usage/ 在线编译器 http://tool.oschina.net/less

  2. java 并发容器一之BoundedConcurrentHashMap(基于JDK1.8)

    最近开始学习java并发容器,以补充自己在并发方面的知识,从源码上进行.如有不正确之处,还请各位大神批评指正. 前言: 本人个人理解,看一个类的源码要先从构造器入手,然后再看方法.下面看Bounded ...

  3. 【转】Java并发编程:CountDownLatch、CyclicBarrier和Semaphore

    Java并发编程:CountDownLatch.CyclicBarrier和Semaphore   Java并发编程:CountDownLatch.CyclicBarrier和Semaphore 在j ...

  4. CF1110C Meaningless Operations

    思路: 令x为满足2x <= a的最大的x.如果a的二进制表示中包含0,则将b构造为(2x+1 - 1) ^ a即可:否则gcd(a ^ b, a & b) = gcd(2x+1 - 1 ...

  5. Android Studio 升级到3.0后出现编译错误\.gradle\caches\transforms-1\files-1.1\*****-release.aar

    Android Studio 升级到3.0后出现各种编译问题,其中有一个问题是关于资源找不到的问题,百度了半天,也没有相关的文章 C:\Users.gradle\caches\transforms-1 ...

  6. HTML iframe框架

    iframe 作用: 就是在一个网页插入一个小窗口   窗口里面也是一个网页 <a href="http://www.baidu.com" target="da1& ...

  7. 新萝卜家园GHOST WIN7系统3专业装机版

    系统来自系统妈:http://www.xitongma.com/ 系统概述 萝卜家园GHOST win7 64位装机旗舰版加快“网上邻居”共享速度:取消不需要的网络服务组件,系统支持Windows安装 ...

  8. codevs 1390 回文平方数 USACO

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题目描述 Description 回文数是指从左向右念和从右像做念都一样的数.如12321就是一个典型的回文数 ...

  9. jQuery中ready方法的实现

    https://blog.csdn.net/major_zhang/article/details/80146674 先普及一下jquery.ready()和window.onload,window. ...

  10. nodejs:遍历文件夹文件统计文件大小

    根据 http://blog.csdn.net/hero82748274/article/details/45700465这里的思路对读写文件做了一个 封装: webpack在打包的时候可以借助ass ...