Codeforces Beta Round #10 A. Power Consumption Calculation (模拟)

题目链接:http://www.codeforces.com/contest/10/problem/A

题意:有一台电脑,在活跃状态下,每秒钟耗能p1,在没人碰之后的t1秒后,进入休息状态,每秒钟耗能p2,如果再有t3秒没人碰的话,就会进入睡眠状态,每秒钟耗能p3,给你这个人碰电脑的区间时间,问你这台电脑的耗能是多少

思路:因为区间很小,所以说直接标记,然后检查就好了

ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stack>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 1010000
#define LL long long
#define ll __int64
#define INF 0xfffffff
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-8
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
double dpow(double a,ll b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;}
//head
int v[2333];
int main()
{
    int n,p1,p2,p3,t1,t2,i,j;
    scanf("%d%d%d%d%d%d",&n,&p1,&p2,&p3,&t1,&t2);mem(v);
    int M=-1,mi=INF;
    for(i=0;i<n;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        for(j=a;j<=b;j++)
            v[j]=1;
        M=max(M,b);mi=min(mi,a);
    }
    int len=1;int ans=0;
    for(i=mi+1;i<=M;i++)
    {
        if(v[i])
        {
            if(len!=1) ans-=p1;
            ans+=p1;
            if(len==1)
            continue;
            if(len>t1)
            {
                len-=t1;
                ans+=t1*p1;
                if(len>t2)
                    ans+=(t2*p2+(len-t2)*p3);
                else
                    ans+=(len*p2);
            }
            else
                ans+=len*p1;
            len=1;
        }
        else
            len++;
    }
    printf("%d\n",ans);
    return 0;
}

你可能感兴趣的:(Codeforces Beta Round #10 A. Power Consumption Calculation (模拟))