Codeforces Round #300 A B C

A - Cutting Banner 给出一个字符串S,从中间删掉一部分子串T之后,剩下的S-T的串里面有没有“CODEFORCES”这个串。

string a = "CODEFORCES", b;

int main()
{
    while( cin >> b )
    {
        bool f = 0;
        int len = b.length();
        for( int i = 0; i < len; ++i )
        {
            for( int j = i+1; j <= len; ++j )
            {
                if( b.substr(0, i) + b.substr( j ) == a )
                {
                    f = 1;
                    break;
                }
            }
        }
        puts( f ? "YES" : "NO" );
    }
    return 0;
}

B - Quasi Binary 给出一个数字n,问能不能分解成只包含数字 1,0的数。

将所有的只包含0,1的数字预处理出来,然后将其看成是价值,花费看成1,那么就是一个完全背包了。

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 1000010;

vector <int> _01, res;
int dp[N], path[N];
int n;

void dfs( int cur )
{
    if( cur > N )
        return;
    _01.push_back( cur );
    dfs( cur * 10 + 1 );
    dfs( cur * 10 );
}

void find_path( int x )
{
    if( !x )
        return;
    res.push_back( path[x] );
    find_path( x - path[x] );
}

int main()
{
    _01.clear();
    dfs( 1 );
    sort( _01.begin(), _01.end() );
    while( ~scanf("%d", &n) )
    {
        res.clear();
        memset( dp, inf, sizeof( dp ) );
        path[0] = dp[0] = 0;
        int sz = _01.size();
        for( int i = 0; i < sz; ++i )
        {
            if( _01[i] <= n )
            {
                for( int j = _01[i]; j <= n; ++j )
                {
                    if( dp[j] > dp[j - _01[i]] + 1 )
                    {
                        dp[j] = dp[j - _01[i]] + 1;
                        path[j] = _01[i];
                    }
                }
            }
        }
        printf("%d\n", dp[n]);
        find_path( n );
        for( int i = 0; i < res.size(); ++i )
        {
            printf("%d ", res[i]);
        }
        puts("");
    }
    return 0;
}

C - Tourist's Notes 给出n,m表示某些人一共爬了n天的山,其中有m份记录。每份记录表示di天在高度hi的地方。问合理情况(hi - hi-1 <= 1)下爬到最高的地方是多少米,不合理输出“IMPOSSIBLE”。

注意特殊处理d1和dn的情况,因为d1,dn不一定是第一天或最后一天

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;

int n, m;
int d, h;

int main()
{
    while( ~scanf("%d%d", &n, &m) )
    {
        int cur, maxx, lastd;
        bool OK = 0;
        scanf("%d%d", &lastd, &cur);
        maxx = lastd - 1 + cur;
        m--;
        while ( m-- )
        {
            scanf("%d%d", &d, &h);
            if( OK )
                continue;
            if( abs( d-lastd) < abs(h-cur) )
            {
                ///printf("d: %d h: %d\n", d, h);
                OK = 1;
                continue;
            }
            int t = ( d - lastd );
            maxx = max( maxx, ( t + cur - h ) / 2 + h );
            lastd = d;
            cur = h;
        }
        maxx = max( maxx, n - lastd + cur );
        if( OK )
            puts("IMPOSSIBLE");
        else
            printf("%d\n", maxx);
    }
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值