博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
“玲珑杯”ACM比赛 Round #19
阅读量:5908 次
发布时间:2019-06-19

本文共 3251 字,大约阅读时间需要 10 分钟。

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(1n109)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 
#include
int pow10(int i){int ans=1;for(int j=0;j
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](lr)(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(1n2×105),k(0k109)n(1≤n≤2×105),k(0≤k≤109). The second line contains nn integers hi(1hi109)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 
#define LL long longusing 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
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;}

 ST表

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

 

转载于:https://www.cnblogs.com/BobHuang/p/7258287.html

你可能感兴趣的文章
配置 Project Server 2010 与 Microsoft Exchange Server 2010 结合使用
查看>>
服务器架构之性能扩展-第七章(8)
查看>>
J2EE部署项目至Tomcat报错:Unable to read TLD "META-INF/c.tld"
查看>>
《跟阿铭学Linux》第6章 Linux磁盘管理——课后习题与答案
查看>>
biji001
查看>>
给年轻工程师的十大忠告
查看>>
在SQL2005 轻松配置SSIS包
查看>>
MDT2008部署之一概览
查看>>
正确删除归档日志
查看>>
Spring 3支持RESTful API/APP配置示例
查看>>
Dell R710服务器磁盘恢复数据库一例(记录)
查看>>
一个专业网管的工作笔记(超级珍藏)
查看>>
rails中实现上传功能
查看>>
SQL Server column not allow Null,insert failed
查看>>
运维老鸟分享-学好Linux技术大绝招
查看>>
一次嵌套循环的优化
查看>>
Zabbix 3.2.6 通过Orabbix监控Oracle数据库
查看>>
mongo shell启动配置文件.mongorc.js(二)
查看>>
服务器与内存
查看>>
SCVMM2008实战之虚拟机安装
查看>>