Codeforces Beta Round #7

A题,应该是水题,我没看懂。。。

B题,这题很多坑,注意x是LL,而且x = 0的情况,所以初始化要为-1,最后这题是内存管理啊。。操作系统学的不好,题意读不懂啊。

申请内存的时候,是从头找 如果这一段的长度>=申请的,就可以申请内存。调整什么的,删除应该比较好理解。

C题,以前做过,扩展欧几里德,基本问题。

D题,前缀回文串,自己写了个bfs判断0-i是回文串,果断超时了。。然后看别人用非常简单的哈希办法,给A了。。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
using namespace std;
#define LL __int64
int dp[5000001];
char str[5000001];
int main()
{
    int i,len,ans;
    unsigned int l = 0,r = 0,t = 1,num = 99;
    scanf("%s",str);
    len = strlen(str);
    ans = 0;
    for(i = 0;i < len;i ++)
    {
        l = l*num + (str[i]-'a');
        r = r + t*(str[i]-'a');
        t *= num;
        if(l == r) dp[i] = dp[(i-1)/2] + 1;
        ans += dp[i];
    }
    printf("%d\n",ans);
    return 0;
}
View Code

 

posted @ 2014-04-18 20:13  Naix_x  阅读(156)  评论(0编辑  收藏  举报