zoukankan      html  css  js  c++  java
  • 11.2森林冰火人

    先把所有的雪人当成都是第一天做的,然后存在优先队列里面,然后从第一天开始算总共化了多少,如果超过当前最小的雪人,那么就把雪人化到0,弹出就好

    #include<bits/stdc++.h>
    #define sf scanf
    #define scf(x) scanf("%lld",&x)
    #define scff(x,y) scanf("%d%d",&x,&y)
    #define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define vi vector<int>
    #define mp make_pair
    #define pf printf
    #define prf(x) printf("%lld
    ",x)
    #define mm(x,b) memset((x),(b),sizeof(x))
    #define rep(i,a,n) for (ll i=a;i<n;i++)
    #define per(i,a,n) for (ll i=a;i>=n;i--)
    typedef long long ll;
    using namespace std;
    const ll mod=1e9+7;
    const double eps=1e-6;
    const double pi=acos(-1.0);
    const int inf=0xfffffff;
    const int N=1e5+7;
    ll sum[N],a[N],tot[N];
    
    struct node
    {
    	ll id;ll sum;
    	node(ll a=0,ll b=0){id=a;sum=b;}
    	friend bool operator <(node a,node b)
    	{
    		return a.sum >b.sum ;
    	} 
    };
    
    priority_queue<node> v;
    int main()
    {
    	node t;
    	mm(sum,0); 
    	ll n;scf(n);
    	rep(i,1,n+1) scf(tot[i]);
    	rep(i,1,n+1) scf(a[i]);
    	ll qq=a[1];
    	rep(i,2,n+1)
    	{
    		tot[i]+=qq;
    		qq+=a[i];
    	}
    	rep(i,1,n+1)  v.push(node(i,tot[i]));
    	ll sum1,num=0;
    	ll now=0;
    	rep(i,1,n+1)
    	{
    		now+=a[i];
    		num++;
    		sum1=num*a[i];
    		while(!v.empty())
    		{
    			t=v.top();
    			if(t.sum <now)
    			{
    				v.pop();
    				num--;
    				//sum1-=a[i];
    				sum1+=t.sum -now;
    			}else
    			break;
    		}
    		if(n!=i)
    			pf("%d ",sum1);
    		else 
    			prf(sum1);
    	}
    //	rep(i,1,n+1)	prf(tot[i]);
    	return 0;
    }
    
  • 相关阅读:
    Beta 冲刺(1/7)
    福大软工 · 第十次作业
    福大软工 · BETA 版冲刺前准备(团队)
    福大软工 · 第十一次作业
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    vue 写一个瀑布流插件
    微信小程序页面滚动到指定位置
    写一个vue的滚动条插件
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/10087400.html
Copyright © 2011-2022 走看看