当前位置:网站首页>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
*/
边栏推荐
- CTO and programmer were both sentenced because the crawler was out of control!
- Canoe- how to parse messages and display information in the trace window (use of program node and structure type system variables)
- Five thousand years of China
- Error accessing database
- How to write MySQL scheduled backup script in Linux
- Remediation for Unsafe Cryptographic Encryption
- 泰克DPO4104数字荧光示波器技术参数
- How to quickly change the database name in MySQL
- The subnet of the pool cannot be overlapped with that of other pools.
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of GPS antenna modules in the global market in 2022
猜你喜欢

It is said on the Internet that a student from Guangdong has been admitted to Peking University for three times and earned a total of 2million yuan in three years

波形记录仪MR6000的实时波形运算功能

C language -- branch structure

LabVIEW displays Unicode characters

Technical specifications of Tektronix tds3054b oscilloscope
![[hackthebox] dancing (SMB)](/img/bb/7bf81004b9cee80ae49bb0c0c2b810.png)
[hackthebox] dancing (SMB)

Idea modifying JVM memory

JDBC learning

EEG signal processing - wavelet transform series

Remediation for Unsafe Cryptographic Encryption
随机推荐
ROS TF coordinate transformation Library & rewrite to create high frequency coordinate transformation broadcaster
Practical part: solving the function conflict between swagger and user-defined parameter parser
如何用万用表测试电子部件
What are the ways to simulate and burn programs? (including common tools and usage)
Installation and configuration of interrealsense d435i camera driver
ECS 四 Sync Point、Write Group、Version Number
Hot renewal process
GBASE 8s must be a DBSA、路径更改导致无法启动的解决方法
Open source demo| you draw and I guess -- make your life more interesting
Webapck system foundation
Remediation for Unsafe Cryptographic Encryption
人民银行印发《关于支持外贸新业态跨境人民币结算的通知》
C language -- branch structure
JDBC man Han building code
The subnet of the pool cannot be overlapped with that of other pools.
Libuv library overview and comparison of libevent, libev and libuv (Reprint)
Sword finger offer II 040 Largest rectangle in matrix
Seattention channel attention mechanism
Redis cache penetration, cache breakdown, cache avalanche
Live broadcast appointment AWS data everywhere series activities