贪心 C - Polycarp's New Job
Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.
Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares).
A bill 

x×y fits into some wallet 

h×w if either 

x≤h and 

y≤w or 

y≤h and 

x≤w . Bills can overlap with each other in a wallet and an infinite amount of bills can fit into a wallet. That implies that all the bills Polycarp currently have fit into a wallet if every single one of them fits into it independently of the others.
Now you are asked to perform the queries of two types:




+ x y — Polycarp earns a bill of size 

x×y ;



? h w — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size 

h×w .
It is guaranteed that there is at least one query of type
1 before the first query of type
2 and that there is at least one query of type
2 in the input data.
For each query of type
2 print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.
Input
The first line contains a single integer
n (







2≤n≤5⋅105 ) — the number of queries.
Each of the next
n lines contains a query of one of these two types:




+ x y (







1≤x,y≤109 ) — Polycarp earns a bill of size 

x×y ;



? h w (







1≤h,w≤109 ) — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size 

h×w .
It is guaranteed that there is at least one query of type
1 before the first query of type
2 and that there is at least one query of type
2 in the input data.
Output
For each query of type
2 print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.
Example
9
+ 3 2
+ 2 3
? 1 20
? 3 3
? 2 3
+ 1 5
? 10 10
? 1 5
+ 1 1
NO
YES
YES
YES
NO
Note
The queries of type
2 of the example:
- Neither bill fits;
- Both bills fit (just checking that you got that bills can overlap);
- Both bills fit (both bills are actually the same);
- All bills fit (too much of free space in a wallet is not a problem);
- Only bill


1×5 fit (all the others don't, thus it's "NO").
题目大意:
+ 代表给你的money,再给你两个数字,代表长和宽,?代表钱包,问你在出现?前面所有的Money是不是可以装进钱包,可以输出YES,否则输出NO
思路:先对输入数字进行处理,a,b, 输入之后,进行处理,a<b.
出现?,进行查找,很容易可以发现,这里的a一定要比前面所有的a中最大的一个还要大,这里的b同理
否则就装不下所有的。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=2e5+10; int main()
{
int n,maxx=0,maxy=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int a,b;
char c[10];
scanf("%s",c);
scanf("%d%d",&a,&b);
if(a>b) swap(a,b);
if(c[0]=='+')
{
maxx=max(maxx,a);
maxy=max(maxy,b);
}
if(c[0]=='?')
{
if(a>=maxx&&b>=maxy) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
贪心 C - Polycarp's New Job的更多相关文章
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心
C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CF 1006B Polycarp's Practice【贪心】
Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a1,a ...
- CodeForces 1005D Polycarp and Div 3(思维、贪心、dp)
http://codeforces.com/problemset/problem/1005/D 题意: 给一个仅包含数字的字符串,将字符串分割成多个片段(无前导0),求这些片段里最多有多少是3的倍数 ...
- 【Codeforces 723C】Polycarp at the Radio 贪心
n个数,用最少的次数来改变数字,使得1到m出现的次数的最小值最大.输出最小值和改变次数以及改变后的数组. 最小值最大一定是n/m,然后把可以改变的位置上的数变为需要的数. http://codefor ...
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...
- cf723c Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...
- codeforces 723C : Polycarp at the Radio
Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...
- Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心
A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...
- CF Covered Path (贪心)
Covered Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
随机推荐
- WPF 绕圈进度条(一)
在设计界面时,有时会遇到进度条,本次讲解如何设计自定义的绕圈进度条,直接上代码: 1.控件界面 <UserControl x:Class="ProgressBarControl&quo ...
- Linux日志 系统日志及分析
Linux系统拥有非常灵活和强大的日志功能,可以保存几乎所有的操作记录,并可以从中检索出我们需要的信息. 大部分Linux发行版默认的日志守护进程为 syslog,位于 /etc/syslog 或 / ...
- 对于SQL的Join,在学习起来可能是比较乱的。我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚。Coding Horror上有一篇文章,通过文氏图 Venn diagrams 解释了SQL的Join。我觉得清楚易懂,转过来。
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codi ...
- WPF,强制捕获鼠标事件,鼠标移出控件外依然可以执行强制捕获的鼠标事件
在WPF中,只有鼠标位置在某个控件上的时候才会触发该控件的鼠标事件.例如,有两个控件都注册了MouseDown和MouseUp事件,在控件1上按下鼠标,不要放开,移动到控件2上再放开.在这个过程中,控 ...
- js 数据类型具体分析
复习 点运算符 xxx.sss xxx是对象 sss是属性和方法.任何数据类型都是拥有属性和方法的.字符串 String var st=“hello world”.字符串的定义 ...
- kafka消费者启动报错
报错信息: WARN Fetching topic metadata with correlation id 14 for topics [Set(test)] from broker [Broker ...
- css 性能优化小结
1.能用css不用js 1.鼠标悬浮展示 2.自定义radio.checkbox的样式 3.巧用css伪类 当input获取焦点时候,把右边的按钮改变样式 检测用户输入:如果 ...
- blfs(systemd版本)学习笔记-安装、配置和使用wpa_supplicant无线网络连接工具
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! wireless项目地址:http://www.linuxfromscratch.org/blfs/view/stable-sy ...
- SAP MM GR-based IV, 无GR不能IV?
SAP MM GR-based IV, 无GR不能IV? 如下的采购订单, 没有做过收货, ITEM的details里却勾选了’GR-Bsd IV’ 选项. 此时试图直接针对该PO#450260713 ...
- 广州.net俱乐部12月份ABP框架活动场地征集、志愿者征集、合作讲师\副讲师征集
大家好,我在<被低估的.net(上) - 微软MonkeyFest 2018广州分享会活动回顾>一文中提到,我将在12月份搞一场ABP框架活动,现向大家征集活动场地.志愿者.合作讲师\副讲 ...