Problem I. Wiki with Special Poker Cards
Input file: standard input Time limit: 1 second
Output file: standard output Memory limit: 256 megabytes
"耶,我赢了! "教室里传来一阵阵快乐的笑声。这是在干什么呢?原来他们在举行"扑克牌游戏"呢。而
作为本次游戏的组织者, Wiki也同时制定了游戏的规则,规则如下:
游戏现场一共有n张扑克牌,但是有别于传统的扑克牌,本次游戏所采用的扑克牌,其牌面大小都在整数
区间[1; 106]之内。把这n张扑克牌按照从左往右的顺序平放在桌子上,牌面大小依次为a1; a2; :::; an。
现在请游戏参与者从这n张扑克牌中挑出连续的m张扑克,满足这m张扑克中牌面最大的那张ai与最小的
那张aj(1 <= i; j <= n)的差值小于等于r,且这m张扑克的牌面加起来的和大于等于s。
游戏期间,同学们依次上场,每人游戏结束以后, Wiki会记录每位同学拿到的牌数m,且每位游戏参与
者拿到的这m张牌必须符合上述游戏规则,不符合规则则记录为0!
为了保证游戏的公平性,每人游戏结束以后, Wiki会把这n张牌重新摆放到初始位置,保证每位参与游
戏的同学都能在相同的条件下进行游戏。最后,谁拿到的牌数最多(也就是m),谁就赢得游戏胜利。
Input
第一行输入三个正整数n; r; s(1 <= n <= 105; 0 <= r; s <= 106)
接下来输入n个正整数ai(1 <= i <= n),两数之间用空格隔开,表示n张牌牌面的大小(0 <= ai <= 106)
Output
在满足游戏规则的前提下,输出m的最大值
Samples

standard input standard output
5 0 5
1 1 1 1 1
5
5 3 10
1 2 3 4 5
4

思路:

利用两个单调队列,一个维护以i为终止节点的单调不减队列记录区间最小值,另一个维护以i为终止节点的单调不增队列记录区间最大值

用一个指针记录满足最大值最小值的最小下标,如果该区间满足前缀和要求,则用该区间去更新答案,否则不更新

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <deque> using namespace std ; const int N = ;
deque<int> miv,mav ; int a[N],sum[N] ;
int n,r,s ; int main(){
cin >> n >> r >> s ; for(int i=;i<=n;i++){
cin >> a[i] ;
sum[i] = sum[i-] + a[i] ;
} int last = , ans = ;
for(int i=;i<=n;i++){
while(!mav.empty() && a[mav.back()] < a[i]) mav.pop_back() ;
while(!miv.empty() && a[miv.back()] > a[i]) miv.pop_back() ;
mav.push_back(i) ;
miv.push_back(i) ;
while(!miv.empty() && !mav.empty() && a[mav.front()] - a[miv.front()] > r){
if(mav.front()<miv.front()){
last = mav.front() ;
mav.pop_front() ;
}else if(mav.front()>miv.front()){
last = miv.front() ;
miv.pop_front() ;
}else{
last = mav.front() ;
mav.pop_back() ;
miv.pop_back() ;
}
}
if(!mav.empty() && !miv.empty() && sum[i]-sum[last]>=s){
ans = max(ans,i-last) ;
}
}
cout << ans << endl ; return ;
}

...

Problem I. Wiki with Special Poker Cards的更多相关文章

  1. Problem F. Wiki with String

    Problem F. Wiki with StringInput file: standard input Time limit: 1 secondOutput file: standard outp ...

  2. uva131 The Psychic Poker Player

    The Psychic Poker Player Time Limit: 3000MS     64bit IO Format: %lld & %llu Description In 5-ca ...

  3. UVa12298 Super Poker II(母函数 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/23590 Description I have a set of super poker cards, ...

  4. Subset sum problem

    https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...

  5. bzoj2487: Super Poker II

    Description I have a set of super poker cards, consisting of an infinite number of cards. For each p ...

  6. Super Poker II UVA - 12298 FFT_生成函数

    Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long #define double long do ...

  7. Codeforces Gym 100418K Cards 暴力打表

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  8. Problem C

    Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. ...

  9. Codeforces Gym 100418K Cards 组合数学

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

随机推荐

  1. ArcGIS Engine中C#开发不能引用ESRI.ArcGIS.AxControls问题

    问题:ArcGIS Engine中C#开发不能引用ESRI.ArcGIS.AxControls问题 解决方法:将这里的特定版本改成“False”即可.

  2. 阿里巴巴 Java 开发手册(一):命名风格

    命名风格 1. [强制] 代码中的命名均不能以下划线或美元符号开始,也不能以下划线或美元符号结束. 反例: _name / __name / $Object / name_ / name$ / Obj ...

  3. python基础知识(二)

    python基础知识(二) 字符串格式化 ​ 格式: % 类型 ---- > ' %类型 ' %(数据) %s 字符串 ​ print(' %s is boy'%('tom')) ----> ...

  4. Nginx配置SSL实现HTTPS访问

    nginx配置文件如下: server { listen 443 ssl; server_name www.domain.com; root /www/web; index index.html in ...

  5. np.random模块的使用介绍

    np.random模块常用的一些方法介绍 名称 作用 numpy.random.rand(d0, d1, …, dn) 生成一个[d0, d1, …, dn]维的numpy数组,数组的元素取自[0, ...

  6. testNG 注释实例

    1. 单个测试用例文件 新建TestDBConnection.java文件 import org.testng.annotations.*; public class TestDBConnection ...

  7. WinRAR捆绑木马

    准备好木马文件 server.exe 准备一个小游戏 趣味数学计算 压缩 创建自解压格式压缩文件 自解压选项设置 解压路径设置 设置程序 模式设置 压缩完成 使用 开始玩游戏

  8. SAP Hybris Discount group,折扣组,折扣记录,用户组几组概念的关联

    在backoffice的Price Settings->Discount->Customer Discount Groups菜单下面,创建一个新的Customer Discount Gro ...

  9. zookeeper介绍(4)zookeeper的完整分布式

    参考: zookeeper的单机和伪分布式教程请参考:zookeeper介绍(1)zookeeper介绍与安装 Zookeeper的完整分布式集群搭建: 准备好三台centos主机:(在这我使用的是z ...

  10. 【hadoop】hadoop3.2.0应用环境搭建与使用指南

    下面列出我搭建hadoop应用环境的文章整理在一起,不定期更新,供大家参考,互相学习!!! 杂谈篇: [英语学习]Re-pick up English for learning big data (n ...