Codeforces Round #621 (Div. 1 + Div. 2)重现

A - Cow and Haybales

The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of nn haybale piles on the farm. The ii-th pile contains aiai haybales.

However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adjacent pile. Formally, in one day she can choose any two indices ii and jj (1≤i,j≤n1≤i,j≤n) such that |i−j|=1|i−j|=1 and ai>0ai>0 and apply ai=ai−1ai=ai−1, aj=aj+1aj=aj+1. She may also decide to not do anything on some days because she is lazy.

Bessie wants to maximize the number of haybales in pile 11 (i.e. to maximize a1a1), and she only has dd days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile 11 if she acts optimally!

Input
The input consists of multiple test cases. The first line contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases. Next 2t2t lines contain a description of test cases — two lines per test case.

The first line of each test case contains integers nn and dd (1≤n,d≤1001≤n,d≤100) — the number of haybale piles and the number of days, respectively.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1000≤ai≤100) — the number of haybales in each pile.

Output
For each test case, output one integer: the maximum number of haybales that may be in pile 11 after dd days if Bessie acts optimally.

Example
Input
3
4 5
1 0 3 2
2 2
100 1
1 8
0
Output
3
101
0
Note
In the first test case of the sample, this is one possible way Bessie can end up with 33 haybales in pile 11:

On day one, move a haybale from pile 33 to pile 22
On day two, move a haybale from pile 33 to pile 22
On day three, move a haybale from pile 22 to pile 11
On day four, move a haybale from pile 22 to pile 11
On day five, do nothing
In the second test case of the sample, Bessie can do nothing on the first day and move a haybale from pile 22 to pile 11 on the second day.

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int t;
    cin>>t;
    int n,d;
    while(t--){
        cin>>n>>d;
         int a[101]={0};
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int j=1;
        int k=0;
        for(int i=0;i<d;i++){
                k++;
            if(a[j]!=0&&k==j){
                a[0]++;
                k=0;
                a[j]--;
            }
            if(a[j]==0){
                j++;
            }
        }
        printf("%d\n",a[0]);
    }
    return 0;
}

B - Cow and Friend

Bessie has way too many friends because she is everyone’s favorite cow! Her new friend Rabbit is trying to hop over so they can play!

More specifically, he wants to get from (0,0)(0,0) to (x,0)(x,0) by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance between the endpoints of a hop is one of its nn favorite numbers: a1,a2,…,ana1,a2,…,an. What is the minimum number of hops Rabbit needs to get from (0,0)(0,0) to (x,0)(x,0)? Rabbit may land on points with non-integer coordinates. It can be proved that Rabbit can always reach his destination.

Recall that the Euclidean distance between points (xi,yi)(xi,yi) and (xj,yj)(xj,yj) is (xi−xj)2+(yi−yj)2−−−−−−−−−−−−−−−−−√(xi−xj)2+(yi−yj)2.

For example, if Rabbit has favorite numbers 11 and 33 he could hop from (0,0)(0,0) to (4,0)(4,0) in two hops as shown below. Note that there also exists other valid ways to hop to (4,0)(4,0) in 22 hops (e.g. (0,0)(0,0) →→ (2,−5–√)(2,−5) →→ (4,0)(4,0)).

Here is a graphic for the first example. Both hops have distance 33, one of Rabbit’s favorite numbers.
In other words, each time Rabbit chooses some number aiai and hops with distance equal to aiai in any direction he wants. The same number can be used multiple times.

Input
The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Next 2t2t lines contain test cases — two lines per test case.

The first line of each test case contains two integers nn and xx (1≤n≤1051≤n≤105, 1≤x≤1091≤x≤109) — the number of favorite numbers and the distance Rabbit wants to travel, respectively.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — Rabbit’s favorite numbers. It is guaranteed that the favorite numbers are distinct.

It is guaranteed that the sum of nn over all the test cases will not exceed 105105.

Output
For each test case, print a single integer — the minimum number of hops needed.

Example
Input
4
2 4
1 3
3 12
3 4 5
1 5
5
2 10
15 4
Output
2
3
1
2
Note
The first test case of the sample is shown in the picture above. Rabbit can hop to (2,5–√)(2,5), then to (4,0)(4,0) for a total of two hops. Each hop has a distance of 33, which is one of his favorite numbers.

In the second test case of the sample, one way for Rabbit to hop 33 times is: (0,0)(0,0) →→ (4,0)(4,0) →→ (8,0)(8,0) →→ (12,0)(12,0).

In the third test case of the sample, Rabbit can hop from (0,0)(0,0) to (5,0)(5,0).

In the fourth test case of the sample, Rabbit can hop: (0,0)(0,0) →→ (5,102–√)(5,102) →→ (10,0)(10,0).

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int t;
    long long int n,x;
    cin>>t;
    while(t--){
        long long int a[200000]={0};
        cin>>n>>x;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        long long int mmax=1,ans=0;
        int flag=0,flag1=0;
        for(int i=0;i<n;i++){
            if(a[i]<=x&&a[i]>mmax)
                    mmax=a[i];
            if(a[i]>x)
                flag=1;
            if(a[i]==x)
                flag1=1;
        }
        if(x%mmax==0)
            ans=x/mmax;
        else
            ans=x/mmax+1;
        if(flag1==1)
            ans=1;
        if(flag==1&&flag1!=1)
            ans=2;
        printf("%lld\n",ans);
    }
    return 0;
}

发布了12 篇原创文章 · 获赞 0 · 访问量 166

猜你喜欢

转载自blog.csdn.net/qq_45981086/article/details/104437141