zoukankan      html  css  js  c++  java
  • 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<<"
    ";
    //	cout<<sum1<<" "<<sum2<<"
    ";
    	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<<"
    ";
    	}
    	fclose(stdin);
    	fclose(stdout);
    	return 0;
    }
    /*
    6 3 1 6
    5 4 4 3 5 6
    3 3 2 3 
    9000 9000 9000
    */
    
  • 相关阅读:
    react-native window下创建Hello(解决创建一路的坑)
    vue2.0 监听滚动 锚点定位
    vue-awesome-swiper 轮播图使用
    vue和react区别
    vuex 管理状态
    vue 解决axios 跨域问题
    判断一个对象是否为空? js
    微信小程序中的自定义组件(components)
    深入理解ES6箭头函数中的this
    vue中组件的data为什么是一个函数
  • 原文地址:https://www.cnblogs.com/Aswert/p/13871863.html
Copyright © 2011-2022 走看看