• A
  • B
  • C
  • D
  • E

这场打的很爽,题目质量很高.

A

给一个01序列,能将一个子串取反,求整个序列的最多1的个数.
数据范围很小,暴力枚举所有子串取反,求最大的值即可.

#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){int x=0,f=1;char c=gc();for (;!isdigit(c);c=gc()) f^=c=='-';for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return f?x:-x;}
template <typename mitsuha>
inline bool read(mitsuha &x){x=0;int f=1;char c=gc();for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';if (!~c) return 0;for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return x=f?x:-x,1;}
template <typename mitsuha>
inline int write(mitsuha x){if (!x) return 0&pc(48);if (x<0) x=-x,pc('-');int bit[20],i,p=0;for (;x;x/=10) bit[++p]=x%10;for (i=p;i;--i) pc(bit[i]+48);return 0;}
inline char fuhao(){char c=gc();for (;isspace(c);c=gc());return c;}
}using namespace chtholly;
using namespace std;
int a[999],n,b[999];int main(){
scanf("%d",&n);
for (int i=1;i<=n;++i) a[i]=read();
int ans=0;
for (int i=1;i<=n;++i){for (int j=i;j<=n;++j){int tmp=0;memcpy(b,a,sizeof b);for (int k=i;k<=j;++k) b[k]=!b[k];for (int k=1;k<=n;++k) tmp+=b[k];ans=max(ans,tmp);}}write(ans);
}

B

让你构造一个长度为n,严格递增,前面的数不能整除后面的数的序列.
很容易想到构造质数数列.输出前nnn个质数即可.

#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){int x=0,f=1;char c=gc();for (;!isdigit(c);c=gc()) f^=c=='-';for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return f?x:-x;}
template <typename mitsuha>
inline bool read(mitsuha &x){x=0;int f=1;char c=gc();for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';if (!~c) return 0;for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return x=f?x:-x,1;}
template <typename mitsuha>
inline int write(mitsuha x){if (!x) return 0&pc(48);if (x<0) x=-x,pc('-');int bit[20],i,p=0;for (;x;x/=10) bit[++p]=x%10;for (i=p;i;--i) pc(bit[i]+48);return 0;}
inline char fuhao(){char c=gc();for (;isspace(c);c=gc());return c;}
}using namespace chtholly;
using namespace std;
const int mulu=2e6;
int p[mulu|10]={1,1},pr[mulu|10];void pre(){
int i,j;
for (i=2;i<=mulu;++i) if (!p[i]){pr[++pr[0]]=i;for (j=i<<1;j<=mulu;j+=i) p[j]=1;}
}int main(){
int n=read();
pre();
for (int i=1;i<=n;++i) write(pr[i]),p32;
}

C

给出一个数字,将它重复k次,可以去掉一些数字使它变成5的倍数,可以有前导0.
问有多少种去掉的方法,mod 1e9+7.

对于每一位的5" role="presentation" style="position: relative;">555和000,它前面的数字都可以随便取.
所以每一位的5" role="presentation" style="position: relative;">555和000都可以构造出一个等比数列求和,稍微推一下公式用快速幂搞定.

#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){int x=0,f=1;char c=gc();for (;!isdigit(c);c=gc()) f^=c=='-';for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return f?x:-x;}
template <typename mitsuha>
inline bool read(mitsuha &x){x=0;int f=1;char c=gc();for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';if (!~c) return 0;for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return x=f?x:-x,1;}
template <typename mitsuha>
inline int write(mitsuha x){if (!x) return 0&pc(48);if (x<0) x=-x,pc('-');int bit[20],i,p=0;for (;x;x/=10) bit[++p]=x%10;for (i=p;i;--i) pc(bit[i]+48);return 0;}
inline char fuhao(){char c=gc();for (;isspace(c);c=gc());return c;}
}using namespace chtholly;
using namespace std;
const int yuzu=1e5,mod=1e9+7;
char c[yuzu|10];ll kasumi(ll a,ll b){
ll s=1;
for (;b;b>>=1,a=a*a%mod) if (b&1) s=s*a%mod;
return s;
}int main(){
scanf("%s",c+1);
int k=read(),i,j,len=strlen(c+1),cnt=0;
ll ans=0;
int inv=kasumi(kasumi(2,len)-1,mod-2);
for (j=1;j<=len;++j){if (c[j]=='0'||c[j]=='5'){ans=(ans+(kasumi(2,j+1ll*k*len-1)-kasumi(2,j-1)+mod)*inv%mod+mod)%mod;}}write(ans);
}

D

一个方格图中有一些障碍物.你可以执行3种操作:
1.在空地上建一个蓝色房子;
2.在蓝色房子的旁边建一个红色房子.
3.推倒一座房子.
红色房子的价值是蓝色房子的两倍.
给你地图,在1e6步以内构造出一种建造方法使得造出房子的总价值最大.

很明显每一个连通块里只留一座蓝色房子,剩下的都建红色房子.
那么只要先全建上蓝色房子,按照建造顺序倒回去推倒重建红色房子即可.

#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){int x=0,f=1;char c=gc();for (;!isdigit(c);c=gc()) f^=c=='-';for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return f?x:-x;}
template <typename mitsuha>
inline bool read(mitsuha &x){x=0;int f=1;char c=gc();for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';if (!~c) return 0;for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');return x=f?x:-x,1;}
template <typename mitsuha>
inline int write(mitsuha x){if (!x) return 0&pc(48);if (x<0) x=-x,pc('-');int bit[20],i,p=0;for (;x;x/=10) bit[++p]=x%10;for (i=p;i;--i) pc(bit[i]+48);return 0;}
inline char fuhao(){char c=gc();for (;isspace(c);c=gc());return c;}
}using namespace chtholly;
using namespace std;
const int yuzu=1e6,d[]={1,0,-1,0,0,1,0,-1};
int n=read(),m=read(),vis[505][505];
char c[505][505];#define yi first
#define er second
typedef pair<int,int> node;int k;
struct ans{
int x,y;char op;
}llx[yuzu|10];void bfs(int sx,int sy,int last){
queue<node> q;
vis[sx][sy]=1;
q.push(node(sx,sy));
llx[++k]={sx,sy,'B'};
for (;!q.empty();){node u=q.front();q.pop();for (int i=0;i<4;++i){int nx=u.yi+d[i],ny=u.er+d[i+4];if (nx>0&&ny>0&&nx<=n&&ny<=m&&c[nx][ny]^'#'&&!vis[nx][ny]){q.push(node(nx,ny));llx[++k]={nx,ny,'B'};vis[nx][ny]=1;}}}
int i,now=k;
for (i=now;i>last+1;--i){llx[++k]={llx[i].x,llx[i].y,'D'};llx[++k]={llx[i].x,llx[i].y,'R'};}
}int main(){
int i,j;
for (i=1;i<=n;++i) scanf("%s",c[i]+1);
for (i=1;i<=n;++i){for (j=1;j<=m;++j){if (c[i][j]^'#'&&!vis[i][j]) bfs(i,j,k);}}
cout<<k<<endl;
for (i=1;i<=k;++i){printf("%c %d %d\n",llx[i].op,llx[i].x,llx[i].y);}
}

E

给出一串数字和至多两个不幸运的数字,求该串数字有多少个排列没有一个前缀和等于某个不幸运的数字.
折半枚举?不存在的!状压瞎搞!
dp[i]=dp[i−lowbit(i)]+dp[lowbit(i)]" role="presentation" style="position: relative;">dp[i]=dp[i−lowbit(i)]+dp[lowbit(i)]dp[i]=dp[i−lowbit(i)]+dp[lowbit(i)]dp[i]=dp[i-lowbit(i)]+dp[lowbit(i)]

#include<bits/stdc++.h> //Ithea Myse Valgulious
using namespace std;
const int mulu=1<<24,mod=1e9+7;
int dp[mulu],a[mulu];
#define lowbit(x) (x&-x)
int r[2]={-1,-1};
int main(){
int i,j,n,k;
scanf("%d",&n);
for (i=0;i<n;++i) scanf("%d",&dp[1<<i]);
for (scanf("%d",&k),i=0;i<k;++i) scanf("%d",&r[i]);
for (a[0]=1,i=1;i<(1<<n);++i){if ((i^lowbit(i))&&(dp[i]=dp[i^lowbit(i)]+dp[lowbit(i)])>mod) dp[i]=mod;if (dp[i]^r[0]&&dp[i]^r[1]){for (j=i;j;j-=lowbit(j)){//枚举每一个子集进行转移.a[i]+=a[i^lowbit(j)];if (a[i]>=mod) a[i]-=mod;}}}printf("%d\n",a[(1<<n)-1]);
}

Codeforces Round #191 (Div.2) 题解相关推荐

  1. Codeforces Round #514 (Div. 2)题解

    Codeforces Round #514 (Div. 2)题解 A 喵,直接模拟. B 枚举所有盖章时的,合法的,左上角的位置.能盖的话就盖一下.最后check一下图案是否相等即可 C 一轮一轮的扔 ...

  2. 贪心 Codeforces Round #191 (Div. 2) A. Flipping Game

    题目传送门 1 /* 2 贪心:暴力贪心水水 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cs ...

  3. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  4. 【算法题解】Codeforces Round #817 (Div. 4)题解

    文章目录 Codeforces Round #817 (Div. 4)题解 A. Spell Check B. Colourblindness C. Word Game D. Line E. Coun ...

  5. Codeforces Round #747 (Div. 2)题解

    Codeforces Round #747 (Div. 2)题解 (本博客将持续更新以后每场CF div2的题解,喜欢ACM.OI的小伙伴记得点个关注哟) 昨天夜晚刷网络流刷入迷了,渐渐就忘记了我还要 ...

  6. Codeforces Round #789 (Div. 2)题解

    Codeforces Round #789 (Div. 2)题解 A. Tokitsukaze and All Zero Sequence 原题链接 算法标签 贪心 排序 思路 情况一:数组存在零 → ...

  7. Codeforces Round #748 (Div. 3) 题解 完整A~G

    Codeforces Round #748 (Div. 3) 题解 A. Elections 题意 已知竞选中三个候选人的当前得票数 a , b , c a,b,c a,b,c,现在可以增加任何一个人 ...

  8. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  9. Codeforces Round #734 (Div. 3) 题解

    Hello大家好,今天给大家带来的是 Codeforces Round #734 (Div. 3) 的全题目讲解. 本文链接:https://www.lanqiao.cn/questions/2040 ...

最新文章

  1. 邪恶的Java帝国是怎么欺负小函数的?
  2. pat乙级相当于什么水平_雅思6.5是什么水平?相当于托福多少分?
  3. 深度学习(四十五)条件对抗网络
  4. IOS一些常用的越狱渠道
  5. 自定义scrollview右侧的滑动条
  6. Python练习题2.分支结构练习
  7. 运动控制卡,越来越简单了
  8. C++Builder实现鼠标钩子
  9. 大数据服务节点配置参考
  10. Author Agreement
  11. 卡尔曼滤波实例——预测橘子的轨迹
  12. 第一讲_SQP添加与查询语句
  13. 君莫笑:小白的堆(bai_dui)
  14. 安卓使用服务完成音乐播放器
  15. 赖大师新文章 :Xilinx 开箱-KV260相机,两个小时轻松搞定,文章不能用我坐飞机过去帮你调哈。
  16. 28 Apr 10:25:21.537 # HandleServiceCommands: system error caught. error code=1072, message = Create
  17. 8名清华北大研究生不出国,街道办事处上班!难道公务员比互联网还卷?
  18. 睡到自然醒的7个关键
  19. Linux系统下搭建常用服务器
  20. Android多线程的四种方式:Handler、AsyncTask、ThreadPoolExector、IntentService

热门文章

  1. matlab最小字典序,12小球称重问题 完美解决方案(转自 skywind.name)
  2. 获奖之后,感慨万分……
  3. 闯缸鱼:看懂python如何实现整数加和,再决定是否自学编程
  4. 如何成为一名异构并行计算工程师
  5. 【计算机网络大题】一个自治系统有6个局域网,其连接图如下图所示。LAN1至LAN6上的主机数分别为:10、12、240、110、50和20台。该自治系统分配到的IP地址为161.26.118.0/23
  6. sonic私有云真机平台搭建记录
  7. [FROM WOJ]#3775 次小生成树
  8. 牛客 华华给月月出题 (积性函数+欧拉筛+快速幂)
  9. IBM CEO向特朗普发公开信:支持税改 为促进就业建言
  10. 不保留缓冲区重叠部分