2018年湘潭大学程序设计竞赛 E 吃货

题目描述

作为一个标准的吃货,mostshy又打算去联建商业街觅食了。
混迹于商业街已久,mostshy已经知道了商业街的所有美食与其价格,而且他给每种美食都赋予了一个美味度,美味度越高表示他越喜爱这种美食。
mostshy想知道,假如带t元去商业街,只能吃一种食物,能够品味到的美食的美味度最高是多少?

输入描述:

第一行是一个整数T(1 ≤ T ≤ 10),表示样例的个数。以后每个样例第一行是两个整数n,m(1 ≤ n,m ≤ 30000),表示美食的种类数与查询的次数。接下来n行,每行两个整数分别表示第i种美食的价格与美味度di,ci (1 ≤ di,ci ≤ 109)。接下来m行,每行一个整数表示mostshy带t(1 ≤ t ≤ 109)元去商业街觅食。

输出描述:

每个查询输出一行,一个整数,表示带t元去商业街能够品味到美食的最高美味度是多少,如果不存在这样的美食,输出0。

示例1

输入

复制

1
3 3
1 100
10 1000
1000000000 1001
9
10
1000000000

输出

复制

100
1000
1001

说明

大量的输入输出,请使用C风格的输入输出。
 1 //排序是为了进行二分
 2 //3*10^4*3*10^4*10 直接暴力肯定会超时的
 3 #include <iostream>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <queue>
 7 #include <algorithm>
 8 using namespace std;
 9 const int N =5e5+9;
10 int  t,n,m;
11 struct Node
12 {
13     int d,c;
14
15 }e[N];
16 bool cmp(Node a,Node b) return a.d<b.d;
17 int a[N];
18 int  main()
19 {
20     scanf("%d",&t);
21     while(t--)
22     {
23         scanf("%d%d",&n,&m);
24         for(int i=0;i<n;i++)
25         {
26             scanf("%d%d",&e[i].d,&e[i].c);
27
28         }
29         sort(e,e+n,cmp);
30         for(int i=0;i<n;i++) {
31             a[i] = e[i].d;
32
33         }
34         for(int  i=1;i<n;i++)//可以买我,那么我前面的也都可以买
35         { //我的c就是从0到我的c里面的最大值。
36             if(e[i].c<e[i-1].c)
37                 e[i].c=e[i-1].c;
38         }//不排序会超时
39         while(m--)
40         {
41
42                 int  x;
43                 scanf("%d",&x);
44                 if(e[0].d>x)//别忘了
45                 {
46                     printf("0\n");
47                     continue;
48                 }
49                 /*
50         int l=0,r=n-1;
51
52         while(l<=r)//因为可能是n-1,所以要有==
53         {
54             int  mid=(l+r)>>1;
55             if(e[mid].d<=x)
56             {
57                 l=mid+1;
58             }
59             else
60             {
61                 r=mid-1;
62             }
63         }
64         */
65         int  l =lower_bound(a,a+n,x)-a;
66         if(l==n) l--;//坑点
67         else if(a[l]>x) l--;
68         //二分或者利用函数都可以,但要注意坑点。
69         printf("%d\n",e[l].c);
70         }
71     }
72     return 0;
73 }

原文地址:https://www.cnblogs.com/tingtin/p/10582054.html

时间: 2024-08-30 18:04:55

2018年湘潭大学程序设计竞赛 E 吃货的相关文章

2018年湘潭大学程序设计竞赛 G- 又见斐波那契

推一推矩阵直接快速幂. 1 #include<bits/stdc++.h> 2 #define LL long long 3 #define pii pair<int,int> 4 #define mk make_pair 5 #define fi first 6 #define se second 7 using namespace std; 8 9 const int N=1e5+7; 10 const int M=1e5+7; 11 const int inf=0x3f3f3

2018清华大学学生程序设计竞赛暨高校邀请赛

2018清华大学学生程序设计竞赛暨高校邀请赛 A. 绿绿与串串 solution 生成字符串的方式决定了:当字符串中的某个奇回文串的左端为开头,或右端为结尾时,这个奇回文串的中间的位置就是其中一个长度. 时间复杂度:\(O(n)\) B. 赛艇 solution 将路径也弄成一个矩阵,然后压位判断. 时间复杂度:\(O(\frac{1}{64}n^2m^2)\) F. 密码学第三次小作业 solution 一看它给了两个式子就知道不是暴力分解质因子. 中间有一个很特别的性质:\((e_1, e_

HDU6447 YJJ&#39;s Salesman 2018中国大学生程序设计竞赛 - 网络选拔赛1010 离散化+线段树+DP

YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 253    Accepted Submission(s): 62 Problem Description YJJ is a salesman who has traveled through western country. YJJ is always on

2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ&#39;s Salesman 【离散化+树状数组维护区间最大值】

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 919    Accepted Submission(s): 290 Problem Description YJJ is a salesman who h

2019年湘潭大学程序设计竞赛(重现赛)

2019年湘潭大学程序设计竞赛(重现赛) A:Who's better? #include<bits/stdc++.h> using namespace std; int main(){ int n1,p1,s1,n2,p2,s2; cin>>n1>>p1>>s1; cin>>n2>>p2>>s2; if(n1!=n2){ if(n1>n2)cout<<"1\n"; else cout

2018华南理工大学程序设计竞赛 H-对称与反对称

H-对称与反对称 题目描述 给出一个N*N的方阵A.构造方阵B,C: 使得A = B + C.其中 B为对称矩阵,C为反对称矩阵. 对于方阵S中的任意元素,若(S)ij = (S)ji,则称S为对称矩阵 对于方阵T中的任意元素,若(T)ij = -(T)ji,则称T为反对称矩阵 注意,所有运算在模M意义下 输入描述: 输入包含多组数据,处理到文件结束每组数据,第一行包含两个正整数N,M(1 <= N <= 1000, 1 <= M <= 1000,000,001)分别表示方阵大小与

2018中国大学生程序设计竞赛 - 网络选拔赛 hdu6438 Buy and Resell 买入卖出问题 贪心

Buy and Resell Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1126    Accepted Submission(s): 359 Problem Description The Power Cube is used as a stash of Exotic Power. There are n cities numbe

2018中国大学生程序设计竞赛 - 网络选拔赛 Dream hdu6440 Dream 给出一个(流氓)构造法

http://acm.hdu.edu.cn/showproblem.php?pid=6440 题意:让你重新定义任意一对数的乘法和加法结果(输出乘法口诀表和加法口诀表),使得m^p+n^p==(m+n)^p(p为质数),并且存在一个0<q<p使得 q^k(0<k<p)取遍1~p-1的所有值,并且该运算是封闭的(exists an integer q(0<q<p) to make the set {qk|0<k<p,k∈Z} equal to {k|0<

&quot;字节跳动杯&quot;2018中国大学生程序设计竞赛-女生专场 Solution

A - 口算训练 题意:询问 $[L, R]$区间内 的所有数的乘积是否是D的倍数 思路:考虑分解质因数 显然,一个数$x > \sqrt{x} 的质因子只有一个$ 那么我们考虑将小于$\sqrt {x}$ 的质因子用线段树维护 其他质因子用vector 维护存在性 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 100010 5 #define block 317 6 vector <int>