T - Olympiad—贪心或者STL
来源:互联网 发布:淘宝怎样看退货率 编辑:程序博客网 时间:2024/09/21 06:34
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.
Help Vasya's teacher, find two numbers — the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.
Input
The first line contains two space-separated integers n, x (1 ≤ n ≤ 105; 0 ≤ x ≤ 2·105) — the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the participants' points in the first tour.
The third line contains n space-separated integers: b1, b2, ..., bn (0 ≤ bi ≤ 105) — the participants' points in the second tour.
The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad — there are two integersi, j(1 ≤ i, j ≤ n) such, that ai + bj ≥ x.
Output
Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.
Sample Input
5 21 1 1 1 11 1 1 1 1
1 5
6 74 3 5 6 4 48 6 0 4 3 4
1 5
Hint
In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that — {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.
In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.
In the worst case scenario Vasya can get the fifth place if the table looks like that — {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.
这道题的题意就是给你两组数字a【】,b【】,还有一个x,a,b分别表示成绩,x为小明可能的最小成绩,求小明的最好的排名和最坏的排名
思路::最好排名不用说,当然是第一。现在就要求最差排名,其实就是求是求a+b》=x的数最多有好多个,所以我们现在有两种方法,一种是用贪心来做,另一种就是用STL函数来做
STL:
#include<stdio.h>
#include<set>
#include<string.h>
#include<iostream>
using namespace std;
#define mx 100009
int a[mx],b[mx];
multiset<int>::iterator it;
multiset<int> k;
int main()
{
int i;
int x,n;
while(scanf("%d %d",&n,&x)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
k.clear();
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
k.insert(b[i]);
}
int cnt=0;
for(i=0;i<n;i++)
{
it=k.lower_bound(x-a[i]);
if(it!=k.end())
{
cnt++;
k.erase(it);
}
}
printf("1 %d\n",cnt);
}
}
一般贪心:
- T - Olympiad—贪心或者STL
- 二分贪心—T
- codeforces 222D Olympiad(贪心)
- Codeforces 222D Olympiad(贪心)
- Codeforces 662D International Olympiad【贪心】
- olympiad
- Codeforces Round #279 (Div. 2)---A. Team Olympiad (贪心)
- hdu1789 t贪心
- 二分贪心 T 装箱
- 二分贪心 T
- 二分贪心 T
- 二分贪心 T题
- 二分贪心-T
- poj3253【贪心+堆(STL)】
- poj3190 区间贪心 + STL
- HDU 4398 STL + 贪心
- ZOJ 3963 STL + 贪心
- HDU 4268 Alice and Bob——STl upper_bound + 贪心
- 暴力拆解《Numerical Optimization》之共轭方向法
- 《Linux高性能服务器编程》学习笔记——第七章 Linux服务器程序规范
- 一个让<img>居中居左居右的方法
- train_cascade 源码阅读之Haar特征
- Android控件之HorizontalScrollView 去掉滚动条
- T - Olympiad—贪心或者STL
- 高精度模板
- jquery checkbox全选、反选、选择基数、选择偶数
- 计算机专业毕业后大致的工作方向
- Jquery 帅选器系列
- 图论基础之有向图出入度的计算
- springmvc的结构和流程
- mysql常用的操作
- xcode6 用%d输出NSInteger 时报警告的问题