「赛后补题」HBCPC2018题目代码与思路简析

这次比赛(2018年第二届河北省大学生程序设计竞赛)虽然没有打,但是题目还是要写的。未完成的题目(还差比较硬核的四题)和思路分析会陆续更新完。

Problem A 2011 Mex Query

/*
 * Operation China Wall
 * Author: Zuiho
 * Date: 2018-05
 * Problem: 2011-Mex Query
 */
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define QUICKIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll=long long;
using ull=unsigned long long;

int main()
{
QUICKIO

    unordered_map<int,int> m;
    int n,T; cin>>T;
    bool firstLine=true;
    while(T--)
    {
        //if(firstLine) firstLine=false;
        //else cout<<endl;
        cin>>n; m.clear();
        int maxm=0;
        rep(i,1,n)
        {
            int tmp; cin>>tmp;
            m[tmp]++;
            maxm=max(maxm,tmp);
        }
        rep(i,0,maxm)
        {
            if(m[i]==0)
            {
                cout<<i<<endl; break;
            }
        }
    }
    return 0;
}

Problem B 2012 icebound的商店

/*
 * Operation China Wall
 * Author: Zuiho
 * Date: 2018-05
 * Problem: 2012-Icebound's Shops
 * Tips: A Simple DP.
 */
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)

using namespace std;
using ll=long long;
using ull=unsigned long long;
const int mod=1000000009;
ll dp[20][3005];
int w[20]={
  0,1,2};
/*
dp[i][j]=dp[1~i][j-w[1~i]]
*/
ll solve(int x,int y)
{
    if(dp[x][y]!=-1)
        return dp[x][y];
    else
    {
        //cout<<"?"<<endl;
        if(y==0) return dp[x][y]=1;
        ll ans=0;
        rep(i,1,x)
        {
            //printf("%d,%d\n",y,w[i]);
            if(y-w[i]>=0)
                ans=(ans+solve(i,y-w[i]))%mod;
            else 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值