“玲珑杯”ACM比赛 Round #19
Time Limit:2s Memory Limit:128MByte
Submissions:1599Solved:270
You have a sequence anan, which satisfies:

Now you should find the value of ⌊10an⌋⌊10an⌋.
#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 ;}
Time Limit:2s Memory Limit:128MByte
Submissions:699Solved:186
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.
#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的更多相关文章
- “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】
A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...
- “玲珑杯”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 ...
- lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP
E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...
- 玲珑杯”ACM比赛 Round #19 B 维护单调栈
1149 - Buildings Time Limit:2s Memory Limit:128MByte Submissions:588Solved:151 DESCRIPTION There are ...
- “玲珑杯”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 ...
- “玲珑杯”ACM比赛 Round #12题解&源码
我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧! A ...
- “玲珑杯”ACM比赛 Round #18
“玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...
- “玲珑杯”ACM比赛 Round #1 题解
A:DESCRIPTION Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a co ...
- 玲珑杯”ACM比赛 Round #4 1054 - String cut 暴力。学到了扫描的另一种思想
http://www.ifrog.cc/acm/problem/1054 问删除一个字符后的最小循环节是多少. 比赛的时候想不出,不知道怎么暴力. 赛后看了别人代码才晓得.唉,还以为自己字符串还不错, ...
随机推荐
- Java语言中自动生成随机数
参考原文:http://zhidao.baidu.com/link?url=nB3BT69wmUAiSPfKGgK5Q7HOFFP9AIE04AthreRd9yYcwKhUQsQRWlMdMhW1Qm ...
- Sunday算法模板
Sunday是一个线性字符串模式匹配算法.算法的概念如下: Sunday算法是Daniel M.Sunday于1990年提出的一种字符串模式匹配算法.其核心思想是:在匹配过程中,模式串并不被要求一定要 ...
- JS小游戏
捕鱼达人 飞机大战游戏 详解javaScript的深拷贝 http://www.cnblogs.com/penghuwan/p/7359026.html
- https域名强弱校验的区别
HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){ public boolean verify(String ...
- Hibernate:Disjunction&Conjunction构造复杂的查询条件.
Hibernate:Disjunction&Conjunction构造复杂的查询条件 Disjunction和Conjunction是逻辑或和逻辑与,如下: 用来组合一组逻辑或[or]条件的方 ...
- IOS之UI异步刷新
NSOperationQueue *operationQueue; // for rendering pages on second thread [operationQueue waitUn ...
- Android学习总结(四)—— Activity和 Service进行通信
一.Activity 和 Service进行通信的基本概念 前面我们学习我生命周期里面包含了启动和停止服务的方法,虽然服务器在活动里启动,但在启动了服务之后,活动与服务基本就没有什么关系了.我们在活动 ...
- 最近在准备面试,总结了几个java中面向对象的几个问题,问题本事还不够全面,要想知道还是要自己去找,但是在面试上应该是没多大问题了
Overload(重载)与Override(重写)的区别 重载:发生在一个类中,方法名称相同,参数列表不同,方法体不同(看对象类型) 重写:发生在父类中,方法名称相同,参数列表相同,方法体不同(看引用 ...
- 根据HTML语义化编码
语义化标签——http://www.html5jscss.com/html5-semantics-section.html 写HTML代码时应注意什么? 尽可能少的使用无语义的标签div和span: ...
- 47.Number of Islands(岛的数量)
Level: Medium 题目描述: Given a 2d grid map of '1's (land) and '0's (water), count the number of islan ...