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? ...
随机推荐
- 材质(Material)和几何体(Geometry)
1. 材质 一个材质结合一个几何体可以组成一个mesh对象.材质就像物体的皮肤,决定了几何体的外表.例如:皮肤定义了一个几何体看起来是否像金属.透明与否,或者显示为线框. 基本的材质如下: 1. ...
- Google Colab——零成本玩转深度学习
前言 最近在学深度学习HyperLPR项目时,由于一直没有比较合适的设备训练深度学习的模型,所以在网上想找到提供模型训练,经过一段时间的搜索,最终发现了一个谷歌的产品--Google Colabora ...
- day52——jquery引入与下载、标签查找、操作标签
day52 jquery引入 下载链接:jQuery官网 https://jquery.com/ 中文文档:jQuery AP中文文档 http://jquery.cuishifeng.cn/ < ...
- 【leetcode】590. N-ary Tree Postorder Traversal
Recurisve: /* // Definition for a Node. class Node { public: int val; vector<Node*> children; ...
- Python与MogoDB交互
睡了大半天,终于有时间整理下拖欠的MongoDB的封装啦. 首先我们先进行下数据库的连接: conn = MongoClient('localhost',27017) # 建立连接 result = ...
- yii框架中的各种小问题
1.默认路径的修改 2.分页的做法
- VMware学习笔记之在虚拟机中使用Ghost系统盘安装xp黑屏卡在光标闪无法进入系统
使用ghost安装后,无法进入系统,卡在光标闪动,请参考如下: https://www.cnblogs.com/mq0036/p/3588058.html https://wenku.baidu.co ...
- sleep方法动态打印 C语言
#include<Windows.h> #include<stdio.h> #include<stdlib.h> #include<string.h> ...
- 使用poi调整字体格式、添加单元格注释、自动调整列宽
1 创建新的工作铺 import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org ...
- Commander基本使用
随着NodeJs的不断发展,对于前端来说要做的东西也就更多,Vue脚手架React脚手架等等等一系列的东西都脱颖而出,进入到人们的视野当中,对于这些脚手架工具来讲也只是停留在应用阶段,从来没有想过脚手 ...