CodeForces - 10A Power Consumption Calculation【水题】

编程入门 行业动态 更新时间:2024-10-25 04:25:18

【题目描述】
Tom is interested in Power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the “sleep” mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom’s work with the laptop can be divided into n time periods [l1, r1], [l2, r2], …, [ln, rn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1, rn].

【输入】
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom’s work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start and the end of the i-th period of work.

【输出】
Output the answer to the problem.

【样例输入1】
1 3 2 1 5 10
0 10

【样例输出1】
30

【样例输入2】
2 8 4 2 5 10
20 30
50 100

【样例输出2】
570

题目链接:https://codeforces/contest/10/problem/A

某人的电脑在使用时功耗为P1,不使用经过T1时间后功耗变为P2,在经过T2时间后功耗变为P3,求从L1(唯一坑点,不是0开始)到Rn的时间内电脑的功耗。

代码如下:

#include <iostream>
using namespace std;
static const int MAXN=1e2+10;
int l[MAXN],r[MAXN];
int n,P1,P2,P3,T1,T2;
int res=0;
int main()
{
    cin>>n>>P1>>P2>>P3>>T1>>T2;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i]>>r[i];
        res+=P1*(r[i]-l[i]);
        if(i==1) continue;
        int t=l[i]-r[i-1];
        res+=P1*min(T1,t)+P2*min(T2,max(t-T1,0))+P3*max(t-T1-T2,0);
    }
    cout<<res<<endl;
    return 0;
}

更多推荐

CodeForces - 10A Power Consumption Calculation【水题】

本文发布于:2023-06-14 09:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Power   CodeForces   水题   Calculation   Consumption

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!