Codeforces Round #262 (Div. 2)

    

A. Vasya and Socks

Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?

Input

The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
2 2
output
3
input
9 3
output
13
Note

In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.

In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.


简单的模拟
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int n, m;
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        int cnt = 0;
        int day = 1;
        while(n)
        {
            if(day%m == 0)
            {
                //n ++;
                cnt ++;
                day ++;
            }
            else
            {
                n --;
                cnt ++;
                day ++;
            }
        }
        printf("%d\n",cnt);
    }
}

B. Little Dima and Equation

Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.

Find all integer solutions x (0 < x < 109) of the equation:

x = b·s(x)a + c, 

where abc are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.

The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: abc. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.

Input

The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000;  - 10000 ≤ c ≤ 10000).

Output

Print integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.

Sample test(s)
input
3 2 8
output
3
10 2008 13726 
input
1 2 -18
output
0
input
2 2 -1
output
4
1 31 337 967 
对于类似的公式的问题,可以先在纸上化一化公式,有助于思考,显然在该题中不能无脑for,我们可以看到s(x)的范围是小于等于81,所以枚举加判断就可以了,需要注意的是,x的范围是0到1e9,如果没有判断的话,会WA在test10、、、
 
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

typedef long long LL;
int a, b, c;
LL tp[100010];

LL s(LL n)
{
    LL ans = 0;
    while(n)
    {
        ans += n%10;
        n /= 10;
    }
    return ans;
}

LL pp(LL n, int t)
{
    LL ans = 1;
    for(int i = 0; i < t; i ++)
    {
        ans *= n;
    }
    return ans;
}

int main()
{
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        int amt = 0;
        for(int i = 1; i <= 82; i ++)
        {
            LL t1 = pp(i,a)*b+c;
            if(t1 > 0 && t1 < 1e9 && s(t1) == i)
            {
                tp[amt ++] = t1;
            }
        }

        printf("%d\n",amt);
        if(amt > 0)
        {
            printf("%d",tp[0]);
            for(int i = 1;i < amt; i ++)
                printf(" %d",tp[i]);
            printf("\n");
        }
    }
}

C. Present

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.

There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water wcontiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

Input

The first line contains space-separated integers nm and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the maximum final height of the smallest flower.

Sample test(s)
input
6 2 3
2 2 2 2 1 1
output
2
input
2 5 1
5 8
output
9
Note

In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.


真心想不到这题是二分- -。  下面上网上找的题解,好好理解一下,也希望下次可以有这么一点点的思路
----------------------------转自 这里    -----------------------

f数组表示当前点的累计浇水次数,如果对区间[l,r]浇水k次,那么就是f[l]+=k,f[r+1]-=k,并且每次要把前一个点的状态加到的下个点。举个例子:比如区间[0,2]浇2次水,区间[1,4]浇1次水。那么数组就是 2 1 0 -2 0 -1,从前向后f[i]+=f[i-1]得到 2 3 3 1 1 0 即每个点的浇水次数。

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <vector>
#define INF 0x7fffffff
using namespace std;

typedef long long LL;
int a[100005];
int f[100005];
int n,m,w;

bool check(int x)
{
    memset(f,0,sizeof(f));
    int k=m;
    for(int i=0;i<n;i++)
    {
        if(i!=0) f[i]+=f[i-1];
        int d=max(0,x-a[i]-f[i]);
        f[i]+=d;
        f[min(n,i+w)]-=d;
        k-=d;
        if(k<0) 
            return false;
    }
    return true;
}
int main()
{
    scanf("%d%d%d",&n,&m,&w);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);

    long long l=1,r=INF,mid;
    while(l<r)
    {
        mid=(l+r+1)/2;
        if(check(mid))
            l=mid;
        else
            r=mid-1;
    }
    printf("%I64d\n",l);
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值