第十七届中国计量大学程序设计竞赛 C -Cook Steak

第十七届中国计量大学程序设计竞赛 C -Cook Steak(签到题)
题目
The party began, the greasy uncle was playing cards, the fat otaku was eating, and the little beauty was drawing.

After playing cards for a while, ZJH felt very hungry. He decided to let the automatic kitchen grill steak for him. It can make the kitchen quite busy, because ZJH tastes food very strictly, especially steak!

To grilling a steak, ZJH believes that it required N grilling processes in order, each function within a temperature range [l_i,r_i] for one minute, only in this case the grilled steak is the best.

Fortunately, the device in the kitchen has already been equipped with artificial intelligence, which can quickly complete the whole process in the shortest time. The temperature of this device can be increased or decreased by one degree per minute. When the temperature is within the required temperature range, the steak will be grilled for one minute. However, the trouble now is that ZJH forgot to write a program to calculate the completion time of the steak when remodelling the automatic kitchen system, so you are asked to add this program to the system.

Given an integer N, indicating the number of processes, and N pairs of numbers [l_i,r_i], representing the temperature range required by each function. The initial temperature of the device is 0. Your program should tell ZJH how long it takes for each steak to be grilled.
输入描述:
There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases(number of steaks ZJH wants to eat!). For each test case:

The first line contains an integer N (1 ≤ N ≤ 10^5 ), indicating the number of processes.

Then followed N lines, each line contains two integers l_i, r_il
(0 ≤ l_il ≤ r_ir i ≤ 10^9), indicating the temperature range of the i-th process.
输出描述:
For each test case, each line contains an integer, indicating the shortest time the kitchen take to grill steak each case.
示例1
输入

2
3
1 5
4 6
2 3
3
0 6
0 8
0 4

输出

8
3

题意
本题意思为给一一些牛排和一些温度区间 牛排必须在这区间才能熟,牛排需烤一分钟(在烤的时候,不升温)。温度从0开始,每升降一度都为1分钟。问多长时间把这些牛排烤熟(按顺序)。
代码

#include<iostream>
using namespace std;
typedef long long ll;
const int N=100010
int main()
{
    ll t;
    cin>>t;
    ll l[N];
    ll r[N];
    while(t--)
    {
         
        ll n;
        cin>>n;
        ll sum=0;
        ll ans=n;
        for(int i=0;i<n;i++)
        {
           cin>>l[i]>>r[i];
           if(sum<l[i])
           {
               ans+=l[i]-sum;
               sum=l[i];
           }
            if(sum>r[i])
            {
                ans+=sum-r[i];
                sum=r[i];
            }
        }
        cout<<ans<<endl;
    }
     
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值