https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1351

先按low从大到小贪心再high从小到大贪心

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N=;
const int MOD = 1e9+;
#define LL long long
double const pi = acos(-);
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
struct node{
int x,y;
}p[]; bool cmp1(const node &a,const node &b){
return a.x>b.x;
} bool cmp2(const node &a,const node &b){
return a.y<b.y;
} int main(){
// fre();
int T;
scanf("%d",&T);
while(T--){
int n,c,x;
scanf("%d%d%d",&n,&c,&x);
for(int i=;i<n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
sort(p,p+n,cmp1);
int sum=,ans1=;
for(int i=;i<n;i++){
if(sum<x)
ans1++,sum+=p[i].x;
else
break;
}
int ans2=n;
sort(p,p+n,cmp2);
for(int i=;i<n;i++){
if(c-p[i].y>=x){
ans2--,c-=p[i].y;
}
else
break;
}
printf("%d\n",min(ans1,ans2));
}
return ;
}

1351 topcoder 吃点心的更多相关文章

  1. 51nod 1351 吃点心(贪心)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1351 题意: 思路: 要么先选low值大的,要么先选high值大的,分两 ...

  2. Cow and Snacks(吃点心--图论转换) Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/contest/1209/problem/D 有n个点心,有k个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会 ...

  3. #51nod上topcoder练习记

    好久没刷51nod了,又听说topcoder有很多好题.那么就来51nod上刷吧.(那个客户端搞得有点烦(看不懂)) [1366 贫富差距] 当图不连通的时候,答案为无穷大. 当图连通时,两个点之间的 ...

  4. 最短路【洛谷P3946】ことりのおやつ(小鸟的点心)

    P3946 ことりのおやつ(小鸟的点心) 滑完雪之后,ことり突然想吃点心啦!于是她去了甜品店. 日本的冬天经常下雪.不幸的是,今天也是这样,每秒钟雪的厚度会增加q毫米. 秋叶原共有n个地点,编号从1到 ...

  5. Luogu P3946 ことりのおやつ(小鸟的点心) 【最短路】By cellur925

    题目传送门 日本的冬天经常下雪.不幸的是,今天也是这样,每秒钟雪的厚度会增加q毫米. 秋叶原共有n个地点,编号从1到n.每个地点在开始的时候的积雪高度为hi. 有m条双向道路连接这些地点,它们的长度分 ...

  6. <老友记>学习笔记

    这是六个人的故事,从不服输而又有强烈控制欲的monica,未经世事的千金大小姐rachel,正直又专情的ross,幽默风趣的chandle,古怪迷人的phoebe,花心天真的joey——六个好友之间的 ...

  7. jQuery之父:每天都写点代码

    去年秋天,我的“兼职编程项目”遇到了一些问题:要不是从 Khan Academy 的项目里挪出时间来的话,我根本没办法将不理想的进度弥补上. 这些项目遇到了一些严重的问题.之前的工作我主要是在周末,有 ...

  8. some words that I always make mistake

    发音相似容易混淆的词汇 alteration  英 [ɔːltə'reɪʃ(ə)n; 'ɒl-]  美 [,ɔltə'reʃən]  n. 修改,改变:变更 alteration /ˌɔːltəˈre ...

  9. 谷歌 google

    google Google是搜索引擎名,也是一家美国上市公司名称.Google公司于1998年9月7日以私有股份公司的形式创立,以设计并管理一个互联网的搜索引擎.Google公司的总部称作“Googl ...

随机推荐

  1. 1202: [HNOI2005]狡猾的商人 - BZOJ

    Description 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1,2,3...n-1,n), .当 ...

  2. Apache URL rewrite 配置

    下面是Apache的配置过程,可以参考下:1.httpd.conf配置文件中加载了mod_rewrite.so模块,使用虚拟主机 #LoadModule rewrite_module modules/ ...

  3. 在smarty模板中嵌入php代码

    我个人并不太喜欢smarty的语法,写起来比较啰嗦易出现匹配出错,但是旧项目中有许多工程都是采用它作模板.最近需要在此上稍微加一些PHP的内容,但我不想在模板控制层去一个一个assign,而想在模板文 ...

  4. uva 108

    降维  枚举行累加   然后求单行上最大连续和 #include <iostream> #include <cstring> #include <cstdio> # ...

  5. 【网络】IP地址分配、端口号、分层

    3.网络分层 OSI的七层网络结构图和TCP/IP的五层结构图 OSI七层模型OSI中的层            功能                                          ...

  6. maven3常用命令\创建Project

    转自 http://blog.csdn.net/edward0830ly/article/details/8748986 ------------------------------maven3常用命 ...

  7. 多线程 (五)NSOperation

    NSOperation是对GCD的分装,OC语言,更简单方便 NSOperation和NSOperationQueue一起使用也能实现多线程编程 基本步骤: 将操作封装到一个NSOperation对象 ...

  8. ORA-12704 字符集不匹配

  9. POJ2965——The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: following the stripy el ...

  10. 利用循环removeChild删除节点只删除一半问题

    <!DOCTYPE html> <html>   <head>     <title>adduser.html</title>        ...