BestCoder Round #3 A,B
A.预处理出来,0(1)输出。
Task schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 387 Accepted Submission(s): 193
有m个询问,每一个询问有一个数字q。表示假设在q时间有一个工作表之外的任务请求,请计算何时这个任务才干被运行。
机器总是依照工作表运行。当机器空暇时马上运行工作表之外的任务请求。
对于每组測试数据:
第一行是两个数字n, m,表示工作表里面有n个任务, 有m个询问;
第二行是n个不同的数字t1, t2, t3....tn,表示机器在ti时间运行第i个任务。
接下来m行,每一行有一个数字q,表示在q时间有一个工作表之外的任务请求。
特别提醒:m个询问之间是无关的。
[Technical Specification]
1. T <= 50
2. 1 <= n, m <= 10^5
3. 1 <= ti <= 2*10^5, 1 <= i <= n
4. 1 <= q <= 2*10^5
1
5 5
1 2 3 5 6
1
2
3
4
5
4
4
4
4
7
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define LL __int64
#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 201000; using namespace std; int vis[maxn];
int num[maxn]; int main()
{
int T;
cin >>T;
while(T--)
{
int n, m;
cin >>n>>m;
memset(vis, 0, sizeof(vis));
int x;
for(int i = 1; i <= n; i++)
{
scanf("%d",&x);
vis[x] = 1;
}
int now;
for(int i = maxn-1; i >= 1; i--)
{
if(!vis[i])
{
now = i;
num[i] = now;
continue;
}
num[i] = now;
}
while(m--)
{
scanf("%d",&x);
printf("%d\n",num[x]);
}
}
return 0;
}
B.统计左右比m大的个数,然后求和。
BestCoder Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 258 Accepted Submission(s): 108
Mr Potato is the BestCoder.
One night, an amazing sequence appeared in his dream. Length of this sequence is odd, the median number is M, and he named this sequence as Bestcoder Sequence.
As the best coder, Mr potato has strong curiosity, he wonder the number of consecutive sub-sequences which are bestcoder sequences in a given permutation of 1 ~ N.
For each test case, there is a pair of integers N and M in the first line, and an permutation of 1 ~ N in the second line.
[Technical Specification]
1. 1 <= N <= 40000
2. 1 <= M <= N
1 1
1
5 3
4 5 3 2 1
1
3HintFor the second case, {3},{5,3,2},{4,5,3,2,1} are Bestcoder Sequence.
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 101000; using namespace std; int num[maxn];
LL sum1[maxn];
LL sum2[maxn];
int main()
{
int n, m;
while(cin >>n>>m)
{
memset(sum1, 0, sizeof(sum1));
memset(sum2, 0, sizeof(sum2));
int s;
for(int i = 1; i <= n; i++)
{
scanf("%d",&num[i]);
if(num[i] == m) s = i;
}
int cnt = 0;
int pp = 40000;
sum1[pp] = 1;
for(int i = s-1; i >= 1; i--)
{
if(num[i] > m) cnt++;
else if(num[i] < m) cnt--;
sum1[cnt+pp]++;
}
cnt = 0;
LL ans = 0;
ans += sum1[pp];
for(int i = s+1; i <= n; i++)
{
if(num[i] > m) cnt++;
else if(num[i] < m)cnt--;
sum2[cnt+pp]++;
ans += sum1[pp-cnt];
}
cout<<ans<<endl;
}
return 0;
}
BestCoder Round #3 A,B的更多相关文章
- BestCoder Round #89 02单调队列优化dp
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01 HDU 5944 水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
- bestcoder Round #7 前三题题解
BestCoder Round #7 Start Time : 2014-08-31 19:00:00 End Time : 2014-08-31 21:00:00Contest Type : ...
- Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
- BestCoder Round #88
传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) tree(hdu 5606)
tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
随机推荐
- 程序猿必备的10款web前端开发插件一
1.CSS3实现的火柴燃烧Loading加载动画 这次我们要给大家分享一款非常特别的CSS3 Loading加载动画,整个Loading加载动画就好像是火柴在燃烧一样,不足的是火苗并没有那么真实,比较 ...
- hdu 1595 find the longest of the shortest(dijkstra)
Problem Description Marica is very angry with Mirko because he found a new girlfriend and she seeks ...
- Mac 下纯lua(一)
Lua 介绍 什么是lua - lua是一种跨平台开发脚本语言. Lua 历史 学校 University of Rio de Janeiro 国家 巴西 作者 Roberto Ierusalimsc ...
- 谱聚类--SpectralClustering
谱聚类通常会先对两两样本间求相似度. 然后依据相似度矩阵求出拉普拉斯矩阵,然后将每一个样本映射到拉普拉斯矩阵特诊向量中,最后使用k-means聚类. scikit-learn开源包中已经有现成的接口能 ...
- Android Studio代码自己主动提示无效(not available in Power Save mode)
针对一位博友提的问题,我这边写出来,预计还是非常多人会碰到这个问题,可是不知道怎样解决的. 就是在设置了代码自己主动提示功能后,发现不生效的,怎样设置代码自己主动提示请戳这:Android Studi ...
- Ubuntu下嵌入式Qt开发环境配置全攻略
http://qpcwth.blog.163.com/blog/static/20993024620139151424822/ 在安装的过称中,出现一些问题,注意试想: 1.本次开发环境的配置,是基于 ...
- js执行环境深入研究
js 声明函数是创建函数对象的过程,当创建函数对象时,函数对象的[[scope]] =连当前执行环境对象的作用域(栈顶执行环境--当执行函数时,js会将该函数的执行环境对象入栈) 当为全局函数时,如: ...
- js操作iframe框架时应该屡清楚的一些概念
1.获取iframe的window对象 存在跨域访问限制. iframeElement.contentWindow 兼容 2.获取iframe的document对象 存在跨域访问限制. chrome: ...
- RTP InitializeComponent() 报错
注意xaml中x:Class 是不是相应改了,下面2处标红的部分是否一致. namespace RTP.ToolKits{ /// <summary> /// Interaction lo ...
- 反片语(map)
输入一些单词,找出所有满足如下条件的单词: 该单词不能通过字母重排,得到输入文本中的另外一个单词. 在判断是否满足条件时,不区分大小写,但输出保留输入中的大小写,按字典序进行排列(所有大写字母在小写字 ...