hdoj1897 SnowWolf's Wine Shop (multiset)
来源:互联网 发布:8月份信贷数据 编辑:程序博客网 时间:2024/06/05 06:40
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1897
SnowWolf's Wine Shop
Problem Description
After retired from hustacm, Sempr(Liangjing Wang) find a part-time-job in Snowwolf(Wei Xu)'s wine shop. There are different qualities of wine in the shop, and all of which has a rating describing the qualities. All the ratings are larger than 0 and smaller than 1,000,000. Everyday nearly Q people will go to his shop and buy a bottle of wine because of his kindness. Once a customer want an X qualified rating but there are no such one, Sempr will sell him a better one with the smallest rating. But the boss of the shop is Snowwolf, you know, so if no wine has no more than Y qualified ratings better than the customer's request, Sempr will say sorry to them. Every morning, Xiangsanzi will send N bottles of different or same qualified wine.
Input
In the first line there is an Integer T(0<T<10), which means the number of test cases in the test file, then followed by T test cases.
For each test case;
In the first line, there are 3 Integers, N,Q and Y.
In the second line, there are N integers, which means the quality rating of each bottle of wines.
In the third line, there are Q integers, which means the requests of customers from dawn to dark.
Here, all the Integers are between 0 and 1,000,000
For each test case;
In the first line, there are 3 Integers, N,Q and Y.
In the second line, there are N integers, which means the quality rating of each bottle of wines.
In the third line, there are Q integers, which means the requests of customers from dawn to dark.
Here, all the Integers are between 0 and 1,000,000
Output
For each test case, output "Case I:", where I is the case number, then followed by Q different lines of integers, means the quality of wine Sempr will sell that time. If he could not sell any wine, just output -1.
Sample Input
22 3 32 31 2 32 3 02 33 1 2
Sample Output
Case 1:23-1Case 2:3-12
商店有n瓶酒,每瓶酒有一个度数xi(0<xi<1000000),有Q个人来买酒,要度数为v的酒,若店里没有度数为v的酒,店主就会拿出度数高一点的酒(度数为t且t>v)卖给客人,但有一个要求,t需要满足t-v<=Y;每输入一个客人要的酒的度数,就输出店主卖出酒的度数,若店主没能卖出酒,就输出-1;
思路:
用multiset模拟,我刚开始把题目看错了,理解成了若t==v则输出t,或v<t<=Y也输出t。把Y理解成了界限,实际上Y应该是范围。
#include<stdio.h>#include<string.h>#include<map>#include<set>#include<vector>#include<iostream>using namespace std;int main(){ int t,a,b,c,x,cas=1; scanf("%d",&t); while(t--) { multiset<int > wine; wine.clear(); scanf("%d%d%d",&a,&b,&c); printf("Case %d:\n",cas++); while(a--) { scanf("%d",&x); wine.insert(x); } while(b--) { scanf("%d",&x); multiset<int >::iterator t=wine.lower_bound(x); if(t==wine.end()||*t-x>c)printf("-1\n"); else { printf("%d\n",*t); wine.erase(t); } } } return 0;}
- hdoj1897 SnowWolf's Wine Shop (multiset)
- hdu 1897 SnowWolf's Wine Shop multiset 运用 STL
- hdu4884TIANKENG’s rice shop(模拟)
- POJ4002Alice's mooncake shop
- Vasiliy's Multiset
- HDU 4122--Alice's mooncake shop(单调队列)
- HDU 4884 —— TIANKENG’s rice shop(模拟)
- [ACM] HDU 4884 TIANKENG’s rice shop (模拟)
- hdu 4884 TIANKENG’s rice shop(模拟)
- HDU 4884 TIANKENG’s rice shop (模拟)
- hdu 5349 MZL's simple problem(multiset)
- MZL's simple problem(STL multiset的应用)
- Codeforces 706D-Vasiliy's Multiset(Trie树)
- Vasiliy's Multiset (异或字典树)
- hdu1402 Alice's mooncake shop
- HDU4122-Alice's mooncake shop
- HDU4884 TIANKENG’s rice shop
- 706D. Vasiliy's Multiset
- 为什么需要使用2级指针(转载)
- Understanding ANTLR Grammar Files
- 自定义WM_NOTIFY消息
- Linux 2.6.32的内核栈和用户空间栈关系
- linux下查找字符串命令
- hdoj1897 SnowWolf's Wine Shop (multiset)
- Java获取N天前,N天后的日期(如3天)
- Linux内核中常见内存分配函数
- 过滤器、监听器、拦截器的区别
- PHP脚本木马防范经验
- 内存分配-LINUX设备驱动程序第三版
- cstring头文件
- android4.0.3 修改启动动画和开机声音
- JDK工具(零)--简要介绍JDK1.6自带的42个工具