首页 > 其他分享 >Educational Codeforces Round 158 (Rated for Div. 2)

Educational Codeforces Round 158 (Rated for Div. 2)

时间:2023-11-28 23:34:20浏览次数:33  
标签:Educational Rated point int 158 gas le car line

A. Line Trip

There is a road, which can be represented as a number line. You are located in the point \(0\) of the number line, and you want to travel from the point \(0\) to the point \(x\), and back to the point \(0\).

You travel by car, which spends \(1\) liter of gasoline per \(1\) unit of distance travelled. When you start at the point \(0\), your car is fully fueled (its gas tank contains the maximum possible amount of fuel).

There are \(n\) gas stations, located in points \(a_1, a_2, \dots, a_n\). When you arrive at a gas station, you fully refuel your car. Note that you can refuel only at gas stations, and there are no gas stations in points \(0\) and \(x\).

You have to calculate the minimum possible volume of the gas tank in your car (in liters) that will allow you to travel from the point \(0\) to the point \(x\) and back to the point \(0\).

Input

The first line contains one integer \(t\) (\(1 \le t \le 1000\)) — the number of test cases.

Each test case consists of two lines:

  • the first line contains two integers \(n\) and \(x\) (\(1 \le n \le 50\); \(2 \le x \le 100\));
  • the second line contains \(n\) integers \(a_1, a_2, \dots, a_n\).

Output

For each test case, print one integer — the minimum possible volume of the gas tank in your car that will allow you to travel from the point \(0\) to the point \(x\) and back.

翻译:

有一条路,可以用一条数线来表示。你位于数线上的点 \(0\) ,你想从点 \(0\) 到点 \(x\) ,再回到点 \(0\) 。

你乘汽车旅行,每行驶 \(1\) 个单位的距离要花费 \(1\) 升汽油。当您从点 \(0\) 出发时,汽车已加满油(油箱中的油量已达到最大值)。

在 \(a_1, a_2, \dots, a_n\) 点有 \(n\) 个加油站。到达加油站后,为汽车加满油。注意只能在加油站加油, \(0\) 和 \(x\) 点没有加油站

你必须计算出你的汽车油箱的最小容积(以升为单位),这样你才能从点 \(0\) 行驶到点 \(x\) 并返回到点 \(0\)

#include <bits/stdc++.h>
using namespace std;
bool a[1000];
void solve()
{
    memset(a,0,sizeof a);
    int n,x;
    cin >> n >> x;
    int ans = 0,res = 0;
    int last = 0;
    for(int i = 0;i<n;i++)
    {
        int k;
        cin >> k;
        a[k] = true;
        last = max(last,k);
    }
    for(int i = 1;i<=x;i++)
    {
        res++;
        ans = max(res,ans);
        if(a[i])res = 0;
        //cout << res << endl;
    }
    ans = max(ans,(x - last)*2);
    cout << ans << endl;
}
int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}

标签:Educational,Rated,point,int,158,gas,le,car,line
From: https://www.cnblogs.com/howardsblog/p/17863418.html

相关文章

  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    看到B官方题解写了一堆,而如果能注意到一些性质,几行就写完了题意:给一个A,B构成的字符串,可以将“AB”翻转成"BA",问最多可以进行多少次翻转?实际上在手动模拟以后发现,由于题目限制了每个位置只能翻转一次,所以情况简单了不少。只要还没过最后一个B,那么最后一个B之前的所有A就会被反......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound7(Div.1+Div.2,Rated,Prizes!)A-JaggedSwaps思路:a2到an的数只要相邻为逆序都可以交换,只需要判断a1是否为1即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128#definedoublelongdoubletypedefpai......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    20231127A.JaggedSwaps题意是:给你一个数组进行无数次的操作问你能不能单调思路:通过观察发现进行操作大的一定会被放在后面,所以一定会单调,但是操作是从2开始的,所以下表1的地方一定要是1usingnamespacestd;inta[20];voidsolve(){intn;cin>>n;for(in......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound7(Div.1+Div.2,Rated,Prizes!)A-JaggedSwaps解题思路:若\(a[1]=1\),则可以。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;typedefpair<int,int>pii;#definefifirst#definesesecondvoidsolve(){......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound7(Div.1+Div.2,Rated,Prizes!)A-JaggedSwapsintmain(){IOS;for(cin>>_;_;--_){cin>>n;rep(i,1,n)cin>>a[i];while(true){boolf=0;rep(i,......
  • CF 158 (Rated for Div
    CF-158这次比赛较上次也是有进步,成功地多AC了一道题。但第4题也是很遗憾只差一点了。A.LineTrip题意:车在数轴上从$0$点到达$x$点又返回$0$点,有$k$点的油,可以走$k$个单位,在数轴上$a_1,a_2,a_3...a_n$处可以加油到$k$点,$0$点处和$x$点处无法加油,问$k$的最小值。思路:那么根据题......
  • How Can South Asia Adapt Integrated River Basin Management to Its Soil Erosion
    Duetotheinstabilityofthemonsoon,floodsanddroughtsarefrequentinSouthAsia,resultinginseveresoilerosion.Everyyear,SouthAsiasuffershugelossesduetosoilerosion,includingpropertydamage,humancasualties,andenvironmentaldamage.......
  • CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
    CodeTONRound7(Div.1+Div.2,Rated,Prizes!)基本情况A题花了快半小时,做出来了但是不如正解。B题又是老毛病,一条路走到黑,爆搜打出来超时就死命想剪枝和记忆化,没想过换方法(觉得贪心不可行)。A-JaggedSwaps我的解法没啥好说的,纯模拟。看到\(n\leq10\)知道能过。......
  • Educational Codeforces Round 158 (Rated for Div. 2)
    EducationalCodeforcesRound158(RatedforDiv.2)基本情况A题很水,几分钟秒了。B题想到一个解,被自己hack掉之后没有重新想,一直想在自己一开始的基础上改好,结果最后B都没拿下。B.ChipandRibbon我的思路其实也是找规律,根本没严谨地证明正确性。不应该一条路走到黑的......
  • Educational Codeforces Round 158 补题(A~D)
    A.思路找出最大耗油的路程即可ac代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;consti64inf=8e18;typedefpair<int,int>pii;voidsolve(){intn,x;cin>>n>>x;std::vector<int>v(n);f......