Codeforces Beta Round #5

A题,无聊的题目。

#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
set<string>st;
int main()
{
    char str[100];
    int i,ans,temp,len;
    ans = 0;
    temp = 0;
    while(gets(str) != 0)
    {
        len = strlen(str);
        if(str[0] == '+')
        {
            st.insert(str);
            temp ++;
        }
        else if(str[0] == '-')
        {
            st.erase(str);
            temp --;
        }
        else
        {
            for(i = 0;i < len;i ++)
            {
                if(str[i] == ':') break;
            }
            ans += (len - i - 1)*temp;
        }
    }
    printf("%d\n",ans);
    return 0;
}
View Code

 B题,无聊题目,1Y.

#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
char str[1001][1001];
int main()
{
    int n,i,j,maxz,len,mod,st,z;
    //freopen("a.txt","r",stdin);
    maxz = 0;
    i = 0;
    while(gets(str[i]) != 0)
    {
        len = strlen(str[i++]);
        maxz = max(len,maxz);
    }
    n = i;
    mod = maxz%2;
    for(i = 0;i <= maxz+1;i ++)
    printf("*");
    printf("\n");
    z = 0;
    for(i = 0;i < n;i ++)
    {
        printf("*");
        len = strlen(str[i]);
        if(len%2 == mod)
        {
            st = (maxz - len)/2;
        }
        else
        {
            st = (maxz - len)/2 + z;
            z = (z+1)%2;
        }
        for(j = 0;j < st;j ++)
        {
            printf(" ");
        }
        for(;j < len+st;j ++)
        printf("%c",str[i][j-st]);
        for(;j < maxz;j ++)
        printf(" ");
        printf("*\n");
    }
    for(i = 0;i <= maxz+1;i ++)
    printf("*");
    printf("\n");
    return 0;
}
View Code

 C题,乱搞题,我用栈找到左右括号对应的位置,然后再从头扫一边,利用这个标记,找到最长的。怀疑有可能超时,但还是过了。

#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
char str[1000100];
int s[1000100];
int flag[1000100];
int main()
{
    int len,i,top,maxz,ans,temp,dis;
    scanf("%s",str);
    len = strlen(str);
    top = 0;
    maxz = 0;
    ans = 1;
    for(i = 0;i < len;i ++)
    {
        if(str[i] == ')')
        {
            if(top == 0) continue;
            top --;
            flag[s[top]] = i;
        }
        else
        {
            s[top++] = i;
        }
    }
    for(i = 0;i < len;i ++)
    {
        temp = i;
        dis = 0;
        if(maxz > len - i + 1) break;
        while(str[temp] == '(')
        {
            if(!flag[temp]) break;
            dis += flag[temp] - temp + 1;
            temp = flag[temp] + 1;
            if(temp == len) break;
        }
        if(dis == 0) continue;
        if(maxz < dis)
        {
            maxz = dis;
            ans = 1;
        }
        else if(maxz == dis)
        ans ++;
    }
    printf("%d %d\n",maxz,ans);
    return 0;
}
View Code

 D题,物理题,被题意绕了一下,注意只有d点限速,不是某一段路限速。然后就是各种if else 各种算。。

#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    double a,v,l,d,w;
    double t1,t2,s1,s2,t3,s3;
    scanf("%lf%lf%lf%lf%lf",&a,&v,&l,&d,&w);
    if(w >= v)
    {
        t1 = v*1.0/a;
        s1 = 0.5*a*t1*t1;
        if(s1 > l)
        {
            printf("%.8lf\n",sqrt(2*l*1.0/a));
        }
        else
        {
            printf("%.8lf\n",t1 + (l-s1)/v);
        }
    }
    else
    {
        t1 = w*1.0/a;
        s1 = 0.5*a*t1*t1;
        if(s1 > d)
        {
            t1 = v*1.0/a;
            s1 = 0.5*a*t1*t1;
            if(s1 > l)
            {
                printf("%.8lf\n",sqrt(2*l*1.0/a));
            }
            else
            {
                printf("%.8lf\n",t1 + (l-s1)/v);
            }
        }
        else
        {
            t1 = v/a;
            s1 = 0.5*a*t1*t1;
            t2 = (v-w)/a;
            s2 = (v+w)/2*t2;
            double v0;
            if(s1+s2 > d)
            {
                v0 = sqrt(a*(d +(w*w/2/a)));
                t2 = v0/a + (v0-w)/a;
            }
            else
            {
                t2 =  t1 + t2 + (d-s1-s2)/v;
            }
            t3 = (v-w)/a;
            s3 = w*t3 + 0.5*a*t3*t3;
            if(s3 > l-d)
            {
                t3 = (-w+sqrt(w*w+2*a*(l-d)))/a;
                printf("%.8lf\n",t3+t2);
            }
            else
            {
                printf("%.8lf\n",t3+t2+(l-d-s3)/v);
            }
        }
    }
    return 0;
}
View Code

 E题,留坑吧。托了好久,想了错的思路。看了题解,两种做法,都是把最大的找出来,转化成链,然后用栈做,怎么做的,我也没看明白。

还有一种就是标记左边第一个大的l,右边第一个大的r,然后l-r之间有多少个相同的。就能求一个位置的对数了。

posted @ 2014-04-16 19:15  Naix_x  阅读(207)  评论(0编辑  收藏  举报