个人训练赛#3

传送门:https://vjudge.net/contest/180494#overview

A - A

 

Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.

Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.

Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.

After how many full years will Limak become strictly larger (strictly heavier) than Bob?

Input

The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.

Output

Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.

Example
Input
4 7
Output
2
Input
4 9
Output
3
Input
1 1
Output
1
Note

In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.

In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.

In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.


水题,模拟

代码如下:

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b,ant;
    while(~scanf("%d%d",&a,&b))
    {
        ant=0;
        while(a<=b)
        {
            ant++;
            a*=3;
            b*=2;
        }
        printf("%d\n",ant);
    }
    return 0;
}


B - B

 

Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.

She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.

Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.

Input

The first line contains two integers n and k (1 ≤ n ≤ 1051 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.

The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.

Output

The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.

Example
Input
3 2
2 3 4
Output
3
Input
5 4
3 1 8 9 7
Output
5
Note

In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.

Optimal sequence of actions in the second sample case:

  • In the first day Anastasia collects 8 pebbles of the third type.
  • In the second day she collects 8 pebbles of the fourth type.
  • In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.
  • In the fourth day she collects 7 pebbles of the fifth type.
  • In the fifth day she collects 1 pebble of the second type.


题意:两个口袋,一个口袋能装k个石子,问多少次将石子,拿走

模拟

代码如下:

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int n,k,w;
    scanf("%d%d",&n,&k);
    int ant=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&w);
        ant+=w/k;
        if(w%k!=0)
            ant++;
    }
    int ans=ant/2+ant%2;
    printf("%d\n",ans);
    return 0;
}

C - C

 

There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a1, a2, ..., an. All coordinates are pairwise distinct.

It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates.

It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs.

Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.

Input

The first line contains one integer number n (2 ≤ n ≤ 2·105).

The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). All numbers ai are pairwise distinct.

Output

Print two integer numbers — the minimal distance and the quantity of pairs with this distance.

Example
Input
4
6 -3 0 4
Output
2 1
Input
3
-2 0 2
Output
2 2
Note

In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.


题意:问最小距离,并有几对

水题

代码如下:

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int ll;
#define INF 10000000000
#define N 300000
ll a[N];
int main()
{
    int n,ant;
    ll st,et;
    while(~scanf("%d",&n))
    {
        st=INF;
        ll minn=INF;
        for(int i=0;i<n;i++)
            scanf("%lld",&a[i]);
        sort(a,a+n);
        for(int i=0;i<n;i++)
        {
            et=a[i];
            ll s=fabs(et-st);
            if(s<minn)
            {
                ant=1;
                minn=s;
            }
            else if(s==minn)
                ant++;
            st=a[i];
        }
        printf("%lld %d\n",minn,ant);
    }
    return 0;
}

E - E

 

n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out aipeople in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader.

For example, if there are children with numbers [8, 10, 13, 14, 16] currently in the circle, the leader is child 13 and ai = 12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader.

You have to write a program which prints the number of the child to be eliminated on every step.

Input

The first line contains two integer numbers n and k (2 ≤ n ≤ 1001 ≤ k ≤ n - 1).

The next line contains k integer numbers a1, a2, ..., ak (1 ≤ ai ≤ 109).

Output

Print k numbers, the i-th one corresponds to the number of child to be eliminated at the i-th step.

Example
Input
7 5
10 4 11 4 1
Output
4 2 5 6 1 
Input
3 2
2 5
Output
3 2 
Note

Let's consider first example:

  • In the first step child 4 is eliminated, child 5 becomes the leader.
  • In the second step child 2 is eliminated, child 3 becomes the leader.
  • In the third step child 5 is eliminated, child 6 becomes the leader.
  • In the fourth step child 6 is eliminated, child 7 becomes the leader.
  • In the final step child 1 is eliminated, child 3 becomes the leader.

水题,模拟,需要一点儿优化,不然会超时


代码如下:

#include<iostream>
#include<stdio.h>
using namespace std;
const int N=104;
int a[N];
int main()
{
    int n,t,k,num;
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++)
        a[i]=1;
    int st=2;
    num=n;
    for(int i=0;i<t;i++)
    {
        scanf("%d",&k);
        if(k%num==0)
            k=num;
        else
            k=k%num;//优化
        int ant=1;
        while(1)
        {
            if(ant==k)
            {
                a[st]=0;
                if(i==0)
                    printf("%d",st);
                else
                    printf(" %d",st);
                break;
            }
            st++;
            if(st>n)
                st=st-n;
            if(a[st]!=0)
                ant++;
        }
        st++;
        while(a[st]==0)
        {
            st++;
            if(st>n)
                st=1;
        }
        st++;
        while(a[st]==0)
        {
            st++;
            if(st>n)
                st=1;
        }
        if(st>n)
            st=st-n;
        num--;
    }
    printf("\n");
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值