这次比赛(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 break;
//else if(y==w[i]) ans=(ans+solve(i,y-w[i])+1)%mod;
}
//printf("dp[%d][%d]=%lld\n",x,y,ans%mod);
return dp[x][y]=ans%mod;
}
}
int main()
{
int T; cin>>T;
memset(dp,-1,sizeof(dp));
rep(i,3,15) w[i]=w[i-1]+w[i-2];
while(T--)
{
int x; cin>>x;
if(T>0)
cout<<solve(15,x)<<endl;
else cout<<solve(15,x);
//rep(i,1,x) cout<<dp[i]<<" "; cout<<endl;
}
return 0;
}

Problem C 2013 Nim Game

/*
* Operation China Wall
* Author: Zuiho
* Date: 2018-05
* Problem: 2013-Nim Game
* Notice: The code finishes after my reading the answer.
* Tips: A Simple Nim Game. Remember a xor b xor b = a,
* And everything turns out to be okay.
*/
#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;
ll s[1000005];
int main()
{
QUICKIO
int T; cin>>T;
while(T--)
{
int n,m; cin>>n>>m;
s[0]=0;
rep(i,1,n)
{
ll tmp; cin>>tmp;
s[i]=s[i-1]^tmp;
}
ll ans=0,mod=1e9+7;
rep(i,1,m)
{
int l,r; cin>>l>>r;
ans=(ans*2+((s[r]^s[l-1])>0))%mod;
}
cout<<ans<<endl;
}
return 0;
}

Problem D 2014 Defending Plan Support

未完成,待做。

Problem E 2015 Bitmap

未完成,待做。

Problem F 2016 神殿

/*
* Operation China Wall
* Author: Zuiho
* Date: 2018-05
* Problem: 2016-Temple
* Tips: It's a problem about implementation and greedy. ;)
*/
#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;
int main()
{
ll l,r;
bool firstLine=true;
while(cin>>l>>r)
{
if(firstLine) firstLine=false;
else cout<<endl;
ll ans=l; int pos=-1;
while(++pos<=32)
{
if(((ans>>(pos))&1)==0)
{
if(ans+(ll(1)<<pos)<=r)
ans+=(1<<pos);
}
}
cout<<ans;
}
return 0;
}

Problem G 2017 K Multiple Longest Commom Subsequence

应为Common。

/*
* Operation China Wall
* Author: Zuiho
* Date: 2018-05
* Problem: 2017-K Multiple Longest Commom Subsequence
* Notice: The code finishes after my reading the answer.
* Tips: It's adapted from the classical dp problem. However,
* its rescriction makes it more interesting and difficult. ;)
* * *
* Okay, Let's think about the meaning of K Multiple Longest
* 'Commom'. That means we need to build a com-sub (I make this
* abbreviation of common subsequence) based on the same substring.
* Oh f@ck, see the self-documented code! ;)
*/
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ZERO(x) memset((x),0,sizeof(x))
#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;
using pi=pair<int,int>;
using pii=pair<pi,int>;
int k,n,m,dp[1005][1005];
int a[1005],b[1005];
int pa[1005],pb[1005];
int main()
{
QUICKIO
int T; cin>>T;
while(T--)
{
cin>>k>>n>>m;
ZERO(dp);
memset(pa,0,sizeof(pa));
memset(pb,0,sizeof(pb));
rep(i,1,n) cin>>a[i];
rep(i,1,m) cin>>b[i];
queue<int> q[1005];
rep(i,1,n)
{
q[a[i]].push(i);
if(q[a[i]].size()==k)
{
pa[i]=q[a[i]].front();
q[a[i]].pop();
}
}
rep(i,1,n) while(!q[i].empty()) q[i].pop();
rep(i,1,m)
{
q[b[i]].push(i);
if(q[b[i]].size()==k)
{
pb[i]=q[b[i]].front();
q[b[i]].pop();
}
else if(q[b[i]].size()==1) pb[i]=0;
}
rep(i,1,n)
rep(j,1,m)
{
int ans=max(dp[i-1][j],dp[i][j-1]);
if(a[i]==b[j] && pa[i]!=0 && pb[j]!=0)
ans=max(ans,dp[pa[i]-1][pb[j]-1]+k);
dp[i][j]=max(dp[i][j],ans);
}
cout<<dp[n][m]<<endl;
}
return 0;
}

Problem H 2018 跑图

/*
* Operation China Wall
* Author: Zuiho
* Date: 2018-05
* Problem: 2018-Running out of poisonous areas
* Tips: The origin algorithm is not fast enough.
* A BFS is better choice.
*/
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ZERO(x) memset((x),0,sizeof(x))
#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;
using pi=pair<int,int>;
using pii=pair<pi,int>;
bool matrix[505][505];
int dist[505][505];
bool vis[505][505];
int dx[]={0,1,0,-1},
dy[]={1,0,-1,0};
int main()
{
QUICKIO int n,m;
//bool firstLine=true;
while(cin>>n>>m)
{
///if(firstLine) firstLine=false;
//else cout<<endl;
ZERO(matrix);
ZERO(dist);
ZERO(vis);
queue<pii> q;
rep(i,1,n)
rep(j,1,m)
{
cin>>matrix[i][j];
if(matrix[i][j])
{
q.push(MP(MP(i,j),0));
dist[i][j]=0;
vis[i][j]=true;
} }
while(!q.empty())
{
auto now=q.front(); q.pop();
rep(i,0,3)
{
int tx=now.fi.fi+dx[i],
ty=now.fi.se+dy[i];
if(tx>=1 && tx<=n && ty>=1 && ty<=m && !vis[tx][ty])
{
vis[tx][ty]=true;
dist[tx][ty]=now.se+1;
q.push(MP(MP(tx,ty),now.se+1));
}
}
}
rep(i,1,n)
rep(j,1,m)
{
if(j==m)
cout<<dist[i][j]<<endl;
else cout<<dist[i][j]<<" ";
}
}
return 0;
}

Problem I 2019 Power Seq

未完成。待做。

Problem J 2020 Beautiful Array

未完成。待做。

Problem K 2021 520

/*
* Operation China Wall
* Author: Zuiho
* Date: 2018-05
* Problem: 2021-520
*/
#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;
ll quick_mod(ll a, ll b, ll n)
{
if(b==0) return 1%n;
else if(b==1) return a%n;
else
{
int tmp=quick_mod(a,b/2,n);
return ((((tmp%n)*tmp)%n)*quick_mod(a,b%2,n))%n;
}
}
int main()
{
ll n; cin>>n;
cout<<quick_mod(2,n,20180520);
return 0;
}

Problem L 2022 icebound的账单

/*
* Operation China Wall
* Author: Zuiho
* Date: 2018-05
* Problem: 2022-icebound's bill
*/
#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; int main()
{
ll n; cin>>n;
ll sum=0;
rep(i,1,n)
{
int tmp; cin>>tmp;
sum+=tmp;
}
if(sum>0) cout<<"icebound is happy.";
else if(sum==0) cout<<"icebound is ok.";
else cout<<"icebound is sad.";
return 0;
}

ps:估计下一届的难度不会这么easy了2333
单机车七题还是难度不足的,不过也是考虑到广大兄弟院校了。

「赛后补题」HBCPC2018题目代码与思路简析的更多相关文章

  1. 「赛后补题」Meeting(HDU-5521)

    题意 A,B两个人分别在1和n区.每个区有若干点(区之间的点可以重复,各个区内点间的距离一致),给出区之间有联系的图以及到达所需时间.求两个人见面最短时间以及在哪个区碰面(可有多个) 分析 隐式图搜索 ...

  2. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  3. LibreOJ #6014. 「网络流 24 题」最长 k 可重区间集

    #6014. 「网络流 24 题」最长 k 可重区间集 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   ...

  4. LibreOJ #6013. 「网络流 24 题」负载平衡 最小费用最大流 供应平衡问题

    #6013. 「网络流 24 题」负载平衡 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  5. LIbreOJ #6011. 「网络流 24 题」运输问题 最小费用最大流

    #6011. 「网络流 24 题」运输问题 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  6. LibreOJ #6008. 「网络流 24 题」餐巾计划 最小费用最大流 建图

    #6008. 「网络流 24 题」餐巾计划 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  7. LibreOJ 6004. 「网络流 24 题」圆桌聚餐 网络流版子题

    #6004. 「网络流 24 题」圆桌聚餐 内存限制:256 MiB时间限制:5000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测试数 ...

  8. LibreOJ 6003. 「网络流 24 题」魔术球 贪心或者最小路径覆盖

    6003. 「网络流 24 题」魔术球 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测试数据 ...

  9. LibreOJ #6002. 「网络流 24 题」最小路径覆盖

    #6002. 「网络流 24 题」最小路径覆盖 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测 ...

随机推荐

  1. ettercap_缺少组件问题

    原因:缺少WinPcap组件解决:安装即可

  2. Visual Studio 发布 Windows Service小记

    第一步:新建一个Window服务 第二步:添加安装程序 第三步,配置属性信息(Account选择LocalService) 第四步,在 OnStart和OnStop方法中写上你要干的事情吧.我这里用Q ...

  3. Docker 安装tomcat7

    [root@VM_0_7_centos ~]# docker pull tomcat:7-jre7 [root@VM_0_7_centos ~]# docker run -di --name=tomc ...

  4. Android学习笔记_32_通过WebView实现JS代码与Java代码互相通信

    webview两种实现方法,覆盖onKeyDown()方法 缓存 WebSettings应用注意的几个问题 1.要实现JS代码与Java代码互相通信,需要通过Android的WebView控件,在视图 ...

  5. Hive中使用LZO

    hive 中使用lzo 1 启动hive 错误Exception in thread "main" java.lang.NoClassDefFoundError: org/apac ...

  6. ubuntu开启ssh连接

    1.安装openssh-server sudo apt-get install -y openssh-server 2.修改/etc/ssh/sshd-config配置 PermitRootLogin ...

  7. Javascript 基础汇总

    1 javascript字符串 属性:.length  计算字符串长度 转义字符 \     \n 换行 \r 回车 字符串断行 需要使用反斜杠  \ 2 字符串方法 charAt(n)  返回指定索 ...

  8. sql server 自增长显式添加值

    如果想在自增列添加数据,会提示我们不能插入显式值 解决:

  9. tracking

    https://reid-mct.github.io/   1st Workshop on Target Re-Identification and Multi-Target Multi-Camera ...

  10. Sass 基础(七)

    Sass Maps 的函数-map-remove($map,$key),keywords($args) map-remove($map,$key) map-remove($map,$key)函数是用来 ...