当前位置:网站首页>20年秦皇岛D - Exam Results(二分+思维,附易错数据)
20年秦皇岛D - Exam Results(二分+思维,附易错数据)
2022-06-29 04:36:00 【int 我】
亚历克斯教授正在为他的学生准备考试。
将会nn参加本次考试的学生。如果学生ii拥有良好的心态,他/她会表现出色并获得a_iai分。否则,他/她会得到北京国际机场bi分。所以不可能预测考试结果。假设这些学生的最高分是xx分。分数不低于的学生x \cdot p\%x⋅p%会通过考试的。
Alex需要知道在所有情况下能够通过考试的学生人数上限是多少。你能回答他的问题吗?
投入
输入的第一行给出了测试用例的数量,T\ (1次10^3)T (1≤T≤5×103). TT测试案例如下。
对于每个测试用例,第一行包含两个整数n \(1 \ le n \ le 2 \次10^5)n (1≤n≤2×105)和p\ (1 \le p \le 100)p (1≤p≤100),在哪里nn是学生的数量p\%p%就是比例。
以下每一项nnlines包含两个整数10^9阿乐大学ai,bi (1≤bi≤ai≤109),代表学生的分数ii.
的总和nn在所有测试案例中,不超过5次10^55×105.
输出
对于每个测试用例,输出一行包含“案例#x: y“,哪里\texttt{x}x是测试用例编号(从11),以及\texttt{y}y是学生的最大数量。
样本1
| 投入复制 | 输出复制 |
|---|---|
2 2 50 2 1 5 1 5 60 8 5 9 3 14 2 10 8 7 6 | Case #1: 2 Case #2: 4 |
题意:n个学生是较高分,或者是较低分。使不低于最高分*(m/100)的人数最多
思路:看别人都是尺取,差分什么,但是不能理解,还好自己的代码终于过了
个人觉得这个思路还是比较好理解的。
先结构体排序,按照高分高的(一样的话按低分高的)进行排序,第二个样例就成了下面这样
struct Node
{
int x,y;
bool operator<(const Node temp)const{
if(x!=temp.x) return x>temp.x;
return y>temp.y;
}
}x[M];14 2 10 8 9 3 8 5 7 6
如果最后的最大值是14,那么其他一定都是最大的,二分查找上升数组中有多少不低于14*(60/100.0)就很简单
如果最后的最大值是10,那么下面的一定是最大的,第一个不是14,一定会是2,因为14存在的话10不会是最大的。那么答案就是下面较大的答案+上面较小的答案。因为上面较小的答案是没有顺序的,而优先队列不能进行二分查找,可以使用vector进行添加+二分查找,具体下面代码最上面两个函数就是。
然后对于数据:
2 50 100 80 7 6
7和6永远不会是最大值,实现这个停止只需要记录前面最大的y为maxxy,if(x[i].x<maxxy) break;即可
注意最后那个最大的maxxy也是有可能是最大,最后需要再算一遍结果,比如100 80,7 6这个数据,maxxy=80。
#include<bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
#define ll long long
const ll mod=998244353;
#define EXP 1e-6
#define M 1000005
int T,n,m,maxxy;
int a[M];
struct Node
{
int x,y;
bool operator<(const Node temp)const{
if(x!=temp.x) return x>temp.x;
return y>temp.y;
}
}x[M];
vector<int>s;
void update(int q){ //差不多以优先队列时间加入
maxxy=max(maxxy,q);
vector<int>::iterator last=lower_bound(s.begin(),s.end(),q);
s.insert(last,q);
}
int solve(double a){ //二分查找
if(s.size()==0) return 0;
return lower_bound(s.begin(),s.end(),a)-s.begin();
}
signed main()
{
scanf("%d",&T);
for(int k=1;k<=T;k++){
int maxx=0;
maxxy=0;
s.clear();
scanf("%d%d",&n,&m);
fo(1,n) scanf("%d%d",&x[i].x,&x[i].y);
sort(x+1,x+n+1);
fo(1,n) a[i]=x[n-i+1].x;
for(int i=1;i<=n;i++){
if(x[i].x<maxxy) break; //如果较高分无法成为最大值
double r=x[i].x*(m/100.0);
int sum=(n-i)-(lower_bound(a+1,a+n+1-i,r)-a)+2; //下面的
sum+=i-solve(r)-1; //上面的
maxx=max(maxx,sum);
update(x[i].y);
}
double r=maxxy*(m/100.0);
int sum=0;
for(int i=1;i<=n;i++){ //maxxy为最大值时的答案
sum+=(x[i].x>maxxy?(x[i].y>=r):(x[i].x>=r));
}
maxx=max(maxx,sum);
printf("Case #%d: %d\n",k,maxx);
}
return 0;
}
/*
一些易错的数据:
1
3 50
100 6
5 4
6 4
:3
1
2 50
5 5
2 2
:2
1
3 50
100 6
5 4
5 4
:3
*/
边栏推荐
- Proxy mode (proxy)
- Talking about Canary deployment
- My creation anniversary
- String differences between different creation methods
- Practical part: solving the function conflict between swagger and user-defined parameter parser
- [hackthebox] dancing (SMB)
- 使用AssetStudio/UnityStudio UABE等
- Research Report on the overall scale, major manufacturers, major regions, product and application segmentation of GSM and GPRS modules in the global market in 2022
- [performance test] introduction and installation of JMeter
- SEAttention 通道注意力机制
猜你喜欢

Ask a simple question about SQL

BERT和ViT简介

【牛客网刷题系列 之 Verilog快速入门】~ 异步复位的串联T触发器

What is the method of connection query in MySQL

Decorator Pattern

ROS URDF model is parsed into KDL tree

Idea modifying JVM memory

What are the circular statements of MySQL

How to test electronic components with a multimeter

泰克TDS3054B示波器技术指标
随机推荐
044. (2.13) add value to yourself
How to display all MySQL databases
What is the method of connection query in MySQL
Mediator pattern
Pytorch read / write file
Redis cache penetration, cache breakdown, cache avalanche
SEAttention 通道注意力機制
Cucumber test practice
[结构力学] 结点承载下影响线与直接承载下影响线不同的原因
Real time waveform calculation function of Waveform Recorder mr6000
Apifox : 不仅是Api调试工具,更是开发团队的协作神器
How to create a subtype like relationship between two generic classes when the classes are generic related
How to create robots Txt file?
Actual combat! Another opening method of magic modified swagger and knife4j
安捷伦数字万用表软件NS-Multimeter,实时数据采集数据自动保存
[wc2021] Fibonacci - number theory, Fibonacci sequence
The last week! Summary of pre competition preparation for digital model American Games
IDEA修改jvm内存
Hi, my technology forum is online!
MySQL subquery