zoukankan      html  css  js  c++  java
  • Codeforces Round #262 (Div. 2) A B C

    题目链接

    A. Vasya and Socks

    time limit per test:2 seconds
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    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.

    题意 : 初始有n双袜子,妈妈每m天给他买一双袜子,他每天早上穿新袜子,晚上扔掉,问多少天之后他没有袜子穿。

    思路 : 我的思路是循环模拟。看了官方解题报告最终答案是n+(n-1)/(m-1).

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 
     5 using namespace std ;
     6 
     7 int main()
     8 {
     9     int n,m ;
    10     while(~scanf("%d %d",&n,&m))
    11     {
    12         int cnt = 1;
    13         while(1)
    14         {
    15             n -- ;
    16             if(cnt % m == 0)
    17                 n ++ ;
    18             if(n == 0) break ;
    19             cnt ++ ;
    20         }
    21         printf("%d
    ",cnt) ;
    22     }
    23     return 0 ;
    24 }
    View Code

    B. Little Dima and Equation

    time limit per test:2 seconds
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    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

    题意 : 给你abc,找出所有满足这个式子的数x = b·s(x)a + c,其中s(x)代表的是把x的每一位加起来。

    思路 :枚举s(x),因为x最大是10^9,所以s(x)最大是81,所以枚举s(x)的时候求出x,判断x的每一位相加是否等于s(x)。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <algorithm>
     6 #define LL __int64
     7 
     8 using namespace std ;
     9 
    10 LL sh[101010] ;
    11 
    12 LL poww(int a,int n)
    13 {
    14     LL s = 1 ;
    15     for(int i = 1 ; i <= n ; i++)
    16         s *= (LL)a ;
    17     return s;
    18 }
    19 int main()
    20 {
    21     int a,b,c ,cnt;
    22     while(~scanf("%d %d %d",&a,&b,&c))
    23     {
    24         cnt = 0 ;
    25         memset(sh,0,sizeof(sh)) ;
    26         for(int i = 1 ; i <= 81 ; i++)
    27         {
    28             LL sum = 0 ,sum1 = 0;
    29             sum1 = b*poww(i,a)+c ;
    30             LL sum2 = sum1 ;
    31             while(sum2)
    32             {
    33                 sum += sum2%10 ;
    34                 sum2 /= 10 ;
    35             }
    36             if(sum == i && sum1 < 1e9)
    37                 sh[cnt ++] = sum1 ;
    38         }
    39         printf("%d
    ",cnt) ;
    40         if(cnt)
    41         {
    42             for(int i = 0 ; i < cnt-1 ; i++)
    43                 printf("%I64d ",sh[i]) ;
    44             printf("%I64d
    ",sh[cnt-1]) ;
    45         }
    46     }
    47     return 0 ;
    48 }
    View Code

    C. Present

    time limit per test:2 seconds
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    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 w contiguous 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.

    题意 : n盆花,编号1到n,每盆花都有高度值,还有m天,每天只能浇一次水,且每次浇只能浇连续的w盆花,每浇一次,被浇的花长一个高度值。求怎样浇花,能让其中最矮的花取到最高值。

    思路 : 二分+贪心。二分最小值,然后再贪心,二分最小值,然后求出每盆花与最小值的差值,然后从左到右进行扫描,分段浇水,第一盆浇了3次水的花,前w盆的值都相应的减掉3.

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <algorithm>
     5 #define LL __int64
     6 using namespace std;
     7 LL a[200010],b[200010],c[200010] ;
     8 
     9 int main()
    10 {
    11     int n,m,w ;
    12     while(~scanf("%d %d %d",&n,&m,&w))
    13     {
    14         LL low = 1e10 , high = -1 ,mid,ans = 0 ;
    15         for(int i = 0 ; i < n ; i ++)
    16           {
    17              scanf("%I64d",&a[i]) ;
    18              low = min(low,a[i]) ;
    19              high = max(high,a[i]) ;
    20           }
    21         high += m ;
    22         while(low <= high)
    23         {
    24             memset(c,0,sizeof(c)) ;
    25             mid = (low+high)/2 ;
    26             for(int i = 0 ;  i < n ; i++)
    27                 b[i] = max(0LL,mid-a[i]) ;//用数组b保存每朵花还需要浇水的次数
    28             LL days = m,sum = 0 ;
    29             for(int i = 0 ; i < n ; i++)
    30             {
    31                 sum += c[i] ;
    32                 b[i] -= sum ;//将前边浇连续段已经浇的减掉
    33                 if(b[i] > 0)
    34                 {
    35                     days -= b[i] ;
    36                     if(days < 0) break ;
    37                     sum += b[i] ;//已浇b[i]天;
    38                     c[i+w] -= b[i] ;
    39                 }
    40             }
    41             if(days < 0) high = mid - 1 ;
    42             else {
    43                 ans = mid ;
    44                 low = mid+1 ;
    45             }
    46         }
    47         printf("%I64d
    ",ans) ;
    48     }
    49     return 0 ;
    50 }
    View Code
  • 相关阅读:
    xmlTextTextReaderNodeType来读取XML元素的类型
    [转]关于两个坐标点的距离的计算问题
    Incorrect decrement of the reference count of an object that is not owned at this point by the caller1
    让ipad时时显示内存剩余量
    【转】苹果开发者账号注册流程
    自定义百度地图气泡
    [转] iOS 常用数学函数
    [转]JDK环境变量的配置
    纬度在换算距离上一度等于多少公里?
    [转]UIDevice uniqueGlobalDeviceIdentifier(百度地图API的那些事)
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3930553.html
Copyright © 2011-2022 走看看