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? ...
随机推荐
- Spring Boot打包运行
一:pom.xml配置修改 <!--如果想打成jar包,修改为jar--> <packaging>war</packaging> <dependency> ...
- git学习笔记 --分支管理策略
通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...
- .NET 使用 JustAssembly 比较两个不同版本程序集的 API 变化
原文:.NET 使用 JustAssembly 比较两个不同版本程序集的 API 变化 最近我大幅度重构了我一个库的项目结构,使之使用最新的项目文件格式(基于 Microsoft.NET.Sdk)并使 ...
- 如何删除mysql注释
Linux命令删除注释 先把库表导出成一个.sql文件,然后使用sed命令删除注释.此种适用于mysql端口不开外网的情况. $ cat create_table.sql create table t ...
- 使用jmeter对dubbo接口进行性能测试教程及常见问题处理
一. 测试脚本编写 脚本可参考git项目: https://github.com/aland-1415/dubbo-interface-test.git 1. pom依赖 (注意添加的jmeter ...
- 【面试突击】- Java面试总则
Java基础 1.Map.Set.List集合差别及联系详解 2.HashSet类是如何实现添加元素保证不重复的 3.HashMap 是线程安全的吗,为什么不是线程安全的(最好画图说明多线程环境下不安 ...
- float与position间的区别
float与position间的区别: 个人理解为:脱离文档流不一定脱离文本流:但脱离文本流,则也脱离文档流.[如有更好的理解还望评论区一起探讨,共同学习进步]一.float 浮动(脱离文档流, ...
- 交换ESCHAUNGE英语ESCHAUNGE交易所
exchange From Middle English eschaunge, borrowed from Anglo-Norman eschaunge exchange 1.An act of ex ...
- MES选型很困惑?避开这三个禁忌!
MES系统的选型除了要充分剖析自己企业,掌握自己企业的需要.信息化的目标.自身的特点外,还要完全了解MES系统供应商,对其实力.软件性能.服务.用户.软件实施速度.价格进行了解与分析,这也是MES系统 ...
- react native 集成react navigation报错
集成后出现:“Invalid escape sequence at line 1 column 29 path $[0].name”的错误. 解决办法: