Problem I. Wiki with Special Poker Cards
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的更多相关文章
- Problem F. Wiki with String
Problem F. Wiki with StringInput file: standard input Time limit: 1 secondOutput file: standard outp ...
- uva131 The Psychic Poker Player
The Psychic Poker Player Time Limit: 3000MS 64bit IO Format: %lld & %llu Description In 5-ca ...
- UVa12298 Super Poker II(母函数 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/23590 Description I have a set of super poker cards, ...
- Subset sum problem
https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...
- bzoj2487: Super Poker II
Description I have a set of super poker cards, consisting of an infinite number of cards. For each p ...
- Super Poker II UVA - 12298 FFT_生成函数
Code: #include<bits/stdc++.h> #define maxn 1000000 #define ll long long #define double long do ...
- Codeforces Gym 100418K Cards 暴力打表
CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- Problem C
Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. ...
- Codeforces Gym 100418K Cards 组合数学
CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...
随机推荐
- cannot access org.springframework.core.io.InputStreamSouce
cannot access org.springframework.core.io.InputStreamSouce错误,把mian路径下main.iml文件备份一下,然后删除该文件,报错就会消失,但 ...
- 【Python爬虫案例学习】python爬取淘宝里的手机报价并以价格排序
第一步: 先分析这个url,"?"后面的都是它的关键字,requests中get函数的关键字的参数是params,post函数的关键字参数是data, 关键字用字典的形式传进去,这 ...
- flink checkpoint状态储存三种方式选择
Flink 提供了三种可用的状态后端:MemoryStateBackend,FsStateBackend,和RocksDBStateBackend. MemoryStateBackend Memory ...
- python_进程与线程的补充
进程与线程的标识 知识点一:进程id 与 线程ident import time import multiprocessing import threading time.sleep(10) prin ...
- python_封装redis_hash方法
xshell 进入 虚拟环境 安装 redis workon py3env # 进入虚拟环境 pip install redis # 安装redis deactivate # 退出虚拟环境 简单的封装 ...
- 怎样遍历NodeList对象
因为NodeList对象是一个类似数组的对象, 且它自带了一个 forEach() 方法, 因此可以使用 forEach() 遍历, 它的用法和 Array 里面的 forEach() 是完全一样的. ...
- kali之nmap
nmap简介 Nmap,也就是Network Mapper,最早是Linux下的网络扫描和嗅探工具包.可以扫描主机.端口.并且识别端口所对应的协议,以及猜测操作系统 Ping扫描(-sP参数) TCP ...
- 区块链会2020再次爆发,先学点DAPP压压惊,跟我一起学《区块链DApp入门实战》
区块链DApp正在经历市场洗礼,常言道,对抗动荡最稳妥的是稳扎稳打的技术学习,不能临时抱佛脚. 马化腾说:互联网会像水和电一样融入我们的生活.而区块链呢?它是价值互联网的基石,是未来必然的趋势,也会像 ...
- 【MFC】在CHtmlView中在同一窗口显示新打开页面
使用MFC的单文档,用IE核心做的简单浏览器.当打开一个新的链接时,IE核心会使用IE来打开一个新窗口显示打开的新页面.为了让新页面在本程序中显示,我试了如下方法,其中的问题一并列出: 方法1.重载C ...
- 介绍一个免费的云开发工具:Cloud Shell
上周和一德国同事吹牛的时候,他说最近业余时间在玩一个东东,叫做Cloud Shell,Google出品.Jerry之前听说过国内的阿里云也提供过类似的解决方案,即在云端提供一个受限制的Linux环境并 ...