10.25考试
作者:互联网
T1
交换相邻两项贪心,然后推式子即可;
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+7;
struct node{
int a,t;
}b[N];
int n;
double v,sum1,sum2;
int cmp(node x,node y){
return x.a>y.a;
}
int main(){
freopen("physics.in","r",stdin);
freopen("physics.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&b[i].a,&b[i].t);
sum1+=1.0*v*b[i].t+1.0*1/2*b[i].a*b[i].t*b[i].t;
v+=b[i].a*b[i].t;
}
sort(b+1,b+n+1,cmp);
v=0;
for(int i=1;i<=n;i++){
sum2+=1.0*v*b[i].t+1.0*1/2*b[i].a*b[i].t*b[i].t;
v+=b[i].a*b[i].t;
}
// cout<<v<<"\n";
// cout<<sum1<<" "<<sum2<<"\n";
printf("%.1lf",sum2-sum1);
fclose(stdin);
fclose(stdout);
return 0;
}
/*
2
2 1
30 2
*/
T2
每次找包括自己的前h个数中,最小的那个数就是答案;
用单调队列维护;
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1e5+7;
int n,h,b,e,l,r;
int c[N],ans[N],q[N];
void init(){
for(int i=1;i<=n;i++){
ans[i]=0;
}
}
int main(){
freopen("coffee.in","r",stdin);
freopen("coffee.out","w",stdout);
while(scanf("%d%d%d%d",&n,&h,&b,&e)!=EOF){
init();
for(int i=1;i<=n;i++){
scanf("%d",&c[i]);
}
l=1,r=0;
for(int i=1;i<=n;i++){
while(l<=r&&i-q[l]>=h) l++;
while(l<=r&&c[q[r]]>=c[i]) r--;
q[++r]=i;
ans[q[l]]++;
}
for(int i=b;i<=e;i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
}
fclose(stdin);
fclose(stdout);
return 0;
}
/*
6 3 1 6
5 4 4 3 5 6
3 3 2 3
9000 9000 9000
*/
标签:node,10.25,int,++,1e5,ans,include,考试 来源: https://www.cnblogs.com/Aswert/p/13871863.html