这道题叫“功耗计算”,大概意思呢是告诉你这么件事——
当你afk时,电脑的耗电大概是这么回事:
然而期间只要你动了一下电脑,立马从零开始计时。问你这个Tom在这么几个阶段里耗了多少电。
嘛~ 大概意思就是个水题啦~^_^ 函数分定义域计算的问题似乎是初中……还是小学来着的……那个什么出租车开车算路费的问题吧~
Python:
# input
list = raw_input().split()
n,p1,p2,t1,t2,t3 = map(int , list)
# solve
ans = 0
pre = -1
while n > 0:
n -= 1
list = raw_input().split()
start,end = map(int , list)
ans += (end-start)*p1
if pre != -1:
x = start-pre
if x > t1:
ans += t1*p1
x -= t1
if x > t2:
ans += t2*p2
x -= t2
ans += x*p3
else:
ans += x*p2
else:
ans += x*p1
pre = end
print ans
C++:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,p1,p2,p3,t1,t2 ;
int l,r,l2,r2;
scanf("%d%d%d%d%d%d",&n,&p1,&p2,&p3,&t1,&t2);
scanf("%d%d", &l, &r);
int sum = (r - l) * p1;
while(--n)
{
scanf("%d%d",&l2,&r2);
int mid = l2 - r ;
int p1pow = t1 * p1, p2pow = t2 * p2;
if (mid <= t1)
sum += mid * p1;
else
{
sum += p1pow;
mid -= t1;
if (mid <= t2)
sum += mid * p2;
else
sum += p2pow + (mid - t2) * p3;
}
sum += (r2 - l2) * p1;
l = l2;
r = r2;
}
printf("%d",sum);
return 0;
}