Codeforces Round #278 (Div. 2) A B

A. Giga Tower
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from  - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor  - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.

In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,  - 180, 808 are all lucky while42,  - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).

Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.

Input

The only line of input contains an integer a ( - 109 ≤ a ≤ 109).

Output

Print the minimum b in a line.

Sample test(s)
input
179
output
1
input
-1
output
9
input
18
output
10


#include <iostream>
#include <algorithm>
#include <iterator>
#include <deque>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <valarray>
#include <list>
#include <stack>
#include <array>
#include <iomanip>
#include <map>
#include <string>
#include <queue>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <stdio.h>

using namespace std;

long long  n,m,x;

int check (long long a)
{
    if( a < 0 )
             a = -a;
    while ( a )
    {
        if (a % 10 == 8 )
            return 1 ;
        a /= 10;
    }
    return 0;
}

int main()
{
    while (scanf("%I64d",&n)!=EOF)
    {
       
        int ans =0 ;
        while (true)
        {
            ans ++;
            n++;
            if (check (n))
            {
                printf("%d\n",ans);
                break;
            }
        }
    }
    return 0;
}

B暴力

http://codeforces.com/contest/488/problem/B

B. Candy Boxes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x1, x2, x3, x4} (x1 ≤ x2 ≤ x3 ≤ x4arithmetic mean is median is  and range is x4 - x1The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a "debugging field" and codes in the field will have no bugs.

For example, 1, 1, 3, 3 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.

Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0 ≤ n ≤ 4) boxes remaining. The i-th remaining box contains ai candies.

Now Jeff wants to know: is there a possible way to find the number of candies of the 4 - n missing boxes, meeting the condition above (the mean, median and range are equal)?

Input

The first line of input contains an only integer n (0 ≤ n ≤ 4).

The next n lines contain integers ai, denoting the number of candies in the i-th box (1 ≤ ai ≤ 500).

Output

In the first output line, print "YES" if a solution exists, or print "NO" if there is no solution.

If a solution exists, you should output 4 - n more lines, each line containing an integer b, denoting the number of candies in a missing box.

All your numbers b must satisfy inequality 1 ≤ b ≤ 106. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them.

Given numbers ai may follow in any order in the input, not necessary in non-decreasing.

ai may have stood at any positions in the original set, not necessary on lowest n first positions.

Sample test(s)
input
2
1
1
output
YES
3
3
input
3
1
1
1
output
NO
input
4
1
2
2
3
output
YES
Note

For the first sample, the numbers of candies in 4 boxes can be 1, 1, 3, 3. The arithmetic mean, the median and the range of them are all 2.

For the second sample, it's impossible to find the missing number of candies.

In the third example no box has been lost and numbers satisfy the condition.

You may output b in any order.



#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#define inf 0x7fffffff

using namespace std;

const int maxn=100+10;

int main()
{
    int n;
    int an[5];
    while (scanf("%d",&n)!=EOF)
    {
        for (int i=1 ;i<=n ;i++) scanf("%d",&an[i]);
        sort(an+1,an+n+1);
        if (n==0)
        {
            printf("YES\n");
            printf("1\n1\n3\n3\n");continue;
        }
        if (n==1)
        {
            int t=2*an[1];
            printf("YES\n");
            printf("%d\n%d\n%d\n",t/2,t/2*3,t/2*3);
            continue;
        }
        if (n==2)
        {
            int flag=0;
            // 1   2
            int t=2*an[1];
            int bn[5];
            bn[1]=an[1],bn[4]=3*bn[1];
            bn[2]=an[2];
            bn[3]=4*bn[1]-bn[2];
            if (bn[2]>=bn[1] && bn[3]>=bn[2] && bn[4]>=bn[3] && bn[4]<=1000000)
            {
                flag=1;
                printf("YES\n");
                printf("%d\n%d\n",bn[3],bn[4]);
                continue;
            }
            // 1   3
            t=2*an[1];
            bn[1]=an[1];
            bn[3]=an[2];
            bn[2]=2*t-bn[3];
            bn[4]=bn[1]+t;
            if (bn[2]>=bn[1] && bn[3]>=bn[2] && bn[4]>=bn[3] && bn[4]<=1000000)
            {
                flag=1;
                printf("YES\n");
                printf("%d\n%d\n",bn[2],bn[4]);
                continue;
            }
            // 1   4
            t=2*an[1];
            bn[1]=an[1];
            bn[4]=bn[1]+t;
            if (an[2]==bn[4])
            {
                bn[2]=bn[1];
                bn[3]=bn[4];
                if (bn[2]>=bn[1] && bn[3]>=bn[2] && bn[4]>=bn[3] && bn[4]<=1000000)
                {
                    flag=1;
                    printf("YES\n");
                    printf("%d\n%d\n",bn[2],bn[3]);
                    continue;
                }
            }
            // 2   3
            double cn[5];
            double tt=(double)(an[1]+an[2])/2;
            cn[2]=an[1] ;cn[3]=an[2] ;
            cn[1]=tt/2.0;
            cn[4]=1.5*tt;
            if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)
            {
                flag=1;
                printf("YES\n");
                printf("%.0lf\n%.0lf\n",cn[3],cn[4]);
                continue;
            }
            // 2   4
            cn[4]=an[2];
            cn[2]=an[1];
            tt=2.0*cn[4]/3.0;
            cn[1]=tt/2.0;
            cn[3]=2.0*tt-cn[2];
            if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)
            {
                flag=1;
                printf("YES\n");
                printf("%.0lf\n%.0lf\n",cn[1],cn[3]);
                continue;
            }
            // 3   4
            cn[3]=an[1];
            cn[4]=an[2];
            tt=2.0*cn[4]/3.0;
            cn[1]=tt/2.0;
            cn[2]=2.0*tt-cn[3];
            if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)
            {
                flag=1;
                printf("YES\n");
                printf("%.0lf\n%.0lf\n",cn[1],cn[2]);
                continue;
            }
            if (!flag) printf("NO\n");
        }
        if (n==3)
        {
            // 1   2  3
            double cn[5];
            int flag=0;
            cn[1]=an[1] ;cn[2]=an[2] ;cn[3]=an[3] ;
            double tt=2.0*cn[1];
            cn[4]=1.5*tt;
            if (cn[2]+cn[3]==2.0*tt)
            {
                if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)
                {
                    flag=1;
                    printf("YES\n");
                    printf("%.0lf\n",cn[4]);
                    continue;
                }
            }
            // 1   2  4
            cn[1]=an[1] ;cn[2]=an[2] ;cn[4]=an[3];
            tt=2.0*cn[1];
            cn[3]=2.0*tt-cn[2];
            if (2.0*cn[4]==3.0*tt)
            {
                if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)
                {
                    flag=1;
                    printf("YES\n");
                    printf("%.0lf\n",cn[3]);
                    continue;
                }
            }
            // 2   3  4
            cn[2]=an[1] ;cn[3]=an[2] ;cn[4]=an[3] ;
            tt=(cn[2]+cn[3])/2.0;
            cn[1]=tt/2.0;
            if (cn[4]*2.0==3.0*tt)
            {
                if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)
                {
                    flag=1;
                    printf("YES\n");
                    printf("%.0lf\n",cn[1]);
                    continue;
                }
            }
            // 1   3  4
            cn[1]=an[1] ;cn[3]=an[2] ;cn[4]=an[3] ;
            tt=2.0*cn[1];
            cn[2]=2.0*tt-cn[3];
            if (2.0*cn[4]==3.0*tt)
            {
                if (cn[2]>=cn[1] && cn[3]>=cn[2] && cn[4]>=cn[3] && cn[4]<=1000000)
                {
                    flag=1;
                    printf("YES\n");
                    printf("%.0lf\n",cn[2]);
                    continue;
                }
            }
            if (!flag) printf("NO\n");
        }
        if (n==4)
        {
            double tt=2.0*an[1];
            int flag=0;
            if (an[2]+an[3]==2.0*tt && 2.0*an[4]==3.0*tt)
            {
                if (an[2]>=an[1] && an[3]>=an[2] && an[4]>=an[3] && an[4]<=1000000)
                {
                    flag=1;
                    printf("YES\n");
                    continue;
                }
            }
            if (!flag) printf("NO\n");
        }
    }
    return 0;
}






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值