VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)

昨天晚上做了一下CF。本来心情很好,提交了三道题。比以前总是两道提高了一道题啊。。可是今天醒来发现,就对了一道。。伤心啊。。。rating

A:自己多考虑了一下,中间小小的卡了一下精度,提交时没考虑,去了自己多考虑的情况就对了,如果不去加上高精度也对。哎。还是不够缜密。

n个瓶子,原来装有a[i]毫升Ber-Cola,大桶里中有b升Ber-Cola,要将b升分到n各瓶子里,是每个瓶子的容量相等,只要求出总的平均数,然后依次判断每个瓶子要装多少,如果出现大于平均数的就输出NO

View Code
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#define maxn 107

using namespace std;

const double eps = 1e-8;

int a[maxn];

int main()

{

    int n,i;

    double b;

    while (~scanf("%d%lf",&n,&b))

    {

        double sum = b;

        for (i = 0; i < n; ++i)

        {

            scanf("%d",&a[i]);

            sum += a[i];

        }

        double av = sum/n;

        for (i = 0; i < n; ++i)

        {

            //printf("%lf %lf %d %lf\n",av,b,a[i],av - a[i]);

            if (a[i] > av) break;

            //这一步其实去了就对了,要不去就加eps

            else

            {

                if (av - a[i] > b + eps)

                {

                    break;

                }

                else

                {

                    b -= (av- a[i]);

                }

            }

        }

        if (i == n)

        {

            for (i = 0; i < n; ++i)

            {

                printf("%.6lf\n",av - 1.0*a[i]);

            }

        }

        else

        {

            printf("-1\n");

        }



    }

    return 0;

}

B题就是一个模拟题要考虑各种情况,A.b文件 1<=A<=8,1<=b<=3,给一个总的字符串,

数据:

.hfiehfi

hfu.fefefef.

gfueigf.efeff.f

huweh.f.dw

View Code
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#define maxn 400007

using namespace std;

char str[maxn];

int pos[maxn];

int main()

{

    int i,j;

    while (scanf("%s",str) != EOF)

    {

        int len = strlen(str);

        str[len] = '#';

        int ct = 0;

        for (i = 0; i <= len; ++i)//先查看"."之前的是否满足

        {

            if (str[i] == '.' || str[i] == '#') break;

            ct++;

        }

        if (ct > 8 || ct < 1 || i >= len - 1)

        {

            printf("NO\n");

            continue;

        }

        i++; ct = 0;

        int l = 0;

        for (; i <= len; ++i)

        {

            if (str[i] == '.' || str[i] == '#')

            {

                //printf(">>>%d %d\n",ct,i);

                if (ct > 11 || ct == 0 || (ct > 3 && i == len)) break;//

                else if (ct == 1 && i != len) break;//hfugh.g.gfrg这个情况处理

                else

                {

                    if (ct > 3)

                    pos[l++] = i - (ct - 3);

                    else

                    pos[l++] = i - 1;

                }

                //printf(">>>>>>>%d\n",pos[l -1]);

                ct = 0;

            }

            else

            ct++;

        }

        if (i == len + 1)

        {

            printf("YES\n");

            j = 0;

            for (i = 0; i < len; ++i)

            {

                if (i == pos[j] && j < l - 1)

                {

                    printf("\n");

                    j++;

                }

                 printf("%c",str[i]);

            }

            printf("\n");

        }

        else

        {

            printf("NO\n");

        }

    }

    return 0;

}

C:tle了。。。。晕死啊。。还没看懂呢。

你可能感兴趣的:(round)