- BC20260025's blog
水题合集
- 2023-12-5 15:36:52 @
P2240
# include<iostream>
# include<cstdio>
# include<algorithm>
using namespace std;
struct ts{
double m,v,p;
void in(){
cin>>m>>v;
p=v/m;
}
}a[105];
int n,t;
double s=0;
bool cmp(ts x,ts y){
return x.p>y.p;
}
int main(){
cin>>n>>t;
for(int i=0;i<n;++i) a[i].in();
sort(a,a+n,cmp);
for(int i=0;i<n;++i){
if(t<=a[i].m){
s+=t*a[i].p;
break;
}
else{
s+=a[i].v;
t-=a[i].m;
}
}
printf("%.2lf",s);
return 0;
}
P1803
# include<iostream>
# include<cstdio>
# include<algorithm>
using namespace std;
const int M=1e6+5;
struct ts{
int s,f;
void in(){
cin>>s>>f;
}
}a[M];
int n,ans=0,m;
bool cmp(ts x,ts y){
return x.f<y.f;
}
int main(){
cin>>n;
for(int i=0;i<n;++i) a[i].in();
sort(a,a+n,cmp);
for(int i=0;i<n;++i){
if(a[i].s>=m){
++ans;
m=a[i].f;
}
}
cout<<ans;
return 0;
}
P1181
# include<iostream>
# include<cstdio>
# include<algorithm>
# include<queue>
using namespace std;
const int M=1e5+5;
int n,m,a[M],ans=1,s=0;
int main(){
cin>>n>>m;
for(int i=0;i<n;++i) cin>>a[i];
for(int i=0;i<n;++i){
s+=a[i];
if(s>m){
s=a[i];
++ans;
}
}
cout<<ans;
return 0;
}