2017HDU多校第8场

本文提供了两道ACM竞赛题目的详细解答,包括08HybridCrystals和11KillerNames。通过C++代码展示了如何使用数据结构和算法解决复杂问题,涉及字符串处理、快速幂运算等技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接


01:http://acm.hdu.edu.cn/showproblem.php?pid=6133
02:http://acm.hdu.edu.cn/showproblem.php?pid=6134
03:http://acm.hdu.edu.cn/showproblem.php?pid=6135
04:http://acm.hdu.edu.cn/showproblem.php?pid=6136
05:http://acm.hdu.edu.cn/showproblem.php?pid=6137
06:http://acm.hdu.edu.cn/showproblem.php?pid=6138
07:http://acm.hdu.edu.cn/showproblem.php?pid=6139
08:http://acm.hdu.edu.cn/showproblem.php?pid=6140
09:http://acm.hdu.edu.cn/showproblem.php?pid=6141
10:http://acm.hdu.edu.cn/showproblem.php?pid=6142
11:http://acm.hdu.edu.cn/showproblem.php?pid=6143
这把比赛做出两题,全靠队友最后半小时a掉2题。

一些题解


08 Hybrid Crystals

#include <bits/stdc++.h>
const int maxn = 1010;
using namespace std;
inline int read()
{
    int x=0,f=1;char ch = getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
struct node{
    int num;
    char sta[5];
    bool operator < ( node &b)
    {
        return num < b.num;
    }
}a[maxn];


int main()
{
    int T = read();
    while(T--)
    {
        int n = read(),k = read();
        for(int i = 0; i < n; i++) a[i].num = read();
        for(int i = 0; i < n; i++) scanf("%s", a[i].sta);
        int cnt = 0;
        int p = n-1;

        while(p >= 0)
        {
            if(cnt < k)
            {
                while(strcmp(a[p--].sta, "D") == 0 && p >= 0);
                cnt += a[p+1].num;
            }
            else
            {
                while(strcmp(a[p--].sta, "L") == 0  && p >= 0);
                    cnt -= a[p+1].num;
            }

            if(cnt==k) break;
        }
        if(cnt == k) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

11 Killer Names

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 2500;
const ll mod = 1e9+7;
ll c[maxn][maxn];
ll f[maxn];
ll mi[maxn];

ll quick_mod(ll a, ll b)
{
    ll ans = 1;
    a %= mod;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * a % mod;
            b--;
        }
        b >>= 1;
        a = a * a % mod;
    }
    return ans;
}

void init()
{
    f[1] = 1;
    f[2] = 2;
    for(ll i = 3; i < maxn; i++)
        f[i] = f[i-1] * i % mod;
    c[1][0] = c[1][1] = 1;
    for(ll i = 2; i < maxn; i++)
    {
        c[i][0] = 1;
        for(ll j = 1; j < maxn; j++)
        {
            c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
        }
    }
}

ll solve(ll n, ll i)
{
    ll he = mi[i]%mod;
    ll sign = 1;
    for(ll ii = i-1; ii > 0; ii--)
    {
        if(sign == 1)
        {
            he -= (c[i][ii]%mod)*(mi[ii]%mod);
            he = he%mod;
            while(he < 0 )
                he += mod;
            sign = 0;
        }
        else
        {
            he += (c[i][ii]%mod)*(mi[ii]%mod);
            he = he%mod;
            sign = 1;
        }
    }
    return he;
}

int main()
{
    ll T;
    scanf("%lld", &T);
    init();
    while(T--)
    {
        ll n, m;
        scanf("%lld%lld", &n, &m);
        ll ans = 0;
        for(ll i = 1; i <= m; i++)
            mi[i] = quick_mod(i, n);
        for(ll i = 1; i < m && i <= n; i++)
        {
            ll NAME1 = solve(n, i);
            ll NAME2 = mi[m-i];
            ll TOT = (NAME1%mod)*(NAME2%mod)%mod;
            ans += TOT * c[m][i];
            ans %= mod;
        }
        printf("%lld\n", ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值