传送门

A.BowWow and the Timetable

•题意

给你一个二进制数,让你求小于这个数的所有4的幂的个数

•思路

第一反应是二进制与四进制转换

(其实不用真正的转换 QwQ)

由于二进制的两位对应四进制的一位

所以可以得到四进制下的位数

四进制的位数就是小于等于这个数的所有4的幂的个数,类比10进制下10的幂

由于不能有等于,所以根据二进制判断一下这个数是不是4的幂

因为12,1002,100002 ,二进制下4的幂除了首位的1,后面是偶数个0

所以判断是否是1带偶数个0,是的话个数减一

•代码

 #include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
char s[maxn];
int main()
{
scanf("%s",s+);
int len=strlen(s+),flag=;
int cnt=(len+)/;
for(int i=;i<=len;i++)
if(s[i]=='') flag++;
if(flag==len- && len&)
cnt--;
printf("%d\n",cnt);
}

B.Mislove Has Lost an Array

•题意

数组中只存在$1$或者$x$

$x$是偶数并且$x/2$必须在数组中存在

给定$l,r$数组中最少有$l$个不同的数,最多有$r$个不同的数

求数组里数的和的最小最大值

•思路

最小值是有$1,2,4...$等$l$个数,如果不足n个用$1$补齐

最大值是有$1,2,4...$等$r$个数,如果不足用这$r$个数中最大的补齐

•代码

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n,l,r;
cin>>n>>l>>r;
ll Min=;
int cnt,i;
for(i=,cnt=;i<=l;cnt*=,i++)
Min+=cnt;
Min+=(n-l); ll Max=;
for(cnt=,i=;i<=min(n,r);cnt*=,i++)
Max+=cnt;
cnt/=;
if(r<=n)
Max+=1ll*(n-r)*cnt;
cout<<Min<<' '<<Max<<endl;
}

C. Anna, Svyatoslav and Maps

•题意

给出邻接矩阵表示一个有向图

"1"代表有路,"0"代表没有路

给出长度为$m$的序列,表示一条最短路

求,这个序列的一个子序列s,

满足这个子序列s的最短路是m的序列,且s最短

•思路

由于从一个点到另一个点的路径可能不止一条

一旦固定了路径,那么从这个点到另一个点不必须经过的点如果在固定的路径中的话

就必须有,防止从其它点经过

二那些必须经过的点,就不用有了,因为要使长度最短

固定路径1,2,3,4

1可以直接到3而不必须经过2,但是固定路径里有2

所以2必须存在,才能使得经过1,2

2到4必须经过3,所以2->4路径有存在了3

为了使s最短,3不会有

•代码

 #include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn=1e6+;
char s[][];
int dis[][];
int a[maxn],ans[maxn];
int n,m; void Init()
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
dis[i][j]=inf;
if(i==j) dis[i][j]=;
if(s[i][j]=='') dis[i][j]=;
}
}
} void floyd()
{
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%s",s[i]+);
Init();
floyd(); scanf("%d",&m);
for(int i=;i<=m;i++)
scanf("%d",a+i); int cnt=;
ans[++cnt]=a[];///首
int pre=a[];
for(int i=;i<=m;i++)
{
int cur=a[i-];
int nex=a[i];
if(pre==cur)
continue;
///要不必须经过的点
///不要必须经过的点
if(dis[pre][cur]+dis[cur][nex]!=dis[pre][nex])
{
ans[++cnt]=cur;
pre=cur;
}
}
ans[++cnt]=a[m];///尾 printf("%d\n",cnt);
for(int i=;i<=cnt;i++)
printf("%d ",ans[i]);
puts("");
}

D.Kirk and a Binary String

•题意

给你一个$01$字符串s,让你找到一个t串,使得

  • t串与s串的区间所有单调非递减长度相同
  • t串中0个数最多

•思路

对于一个字符串,当前位置有$0,1$两种情况

  • 当前位置是0

  当前位置是0,对于以他为起点的单调非递减子序列肯定有贡献,

  如果变为1,大多数情况下长度会减小(除了0后面全是1的情况,011111长度不变)

  如果变为1,0的数量比不变减少违背第二个任务

  • 当前位置是1

  如果变为0,对于以他(也就是以1) 为起点的单调非递减子序列来说,长度无影响

  对于以0为起点的单调非递减子序列来说,长度会受到影响

既然想要更多的0,那就需要尽可能的把1 变成0,那如何才能没有影响呢?

那就需要以他(也就是以1) 为起点的单调非递减子序列的长度大于以0为起点的单调非递减子序列长度

因为影响大局的最长的那个,那就让即使小的变化了,也不会对大局产生影响!

换句话说,若想将$1$ 变为 $0$ ,必须保证后面所有的区间的单调非递减子序列长度必须和 1 的个数相等

也就是从后往前找,当$1$的个数大于$0$的个数时,$1$才可以变成$0$

•代码

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+;
char s[maxn];
int a[maxn];
int main()
{
scanf("%s",s+);
int len=strlen(s+);
int cnt=;
for(int i=len;i>=;i--)
{
if(s[i]=='')
cnt++;
else
{
if(cnt) --cnt;
else s[i]='';
}
} printf("%s",s+);
}
 

CodeForces 1204 (#581 div 2)的更多相关文章

  1. Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学

    Codeforces Round #581 (Div. 2)-E. Natasha, Sasha and the Prefix Sums-动态规划+组合数学 [Problem Description] ...

  2. 01串LIS(固定串思维)--Kirk and a Binary String (hard version)---Codeforces Round #581 (Div. 2)

    题意:https://codeforc.es/problemset/problem/1204/D2 给你一个01串,如:0111001100111011101000,让你改这个串(使0尽可能多,任意 ...

  3. Codeforces Round #581 (Div. 2)

    A:暴力. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm& ...

  4. Codeforces Round #581 (Div. 2) C. Anna, Svyatoslav and Maps (Floyd 算法,最短路)

    C. Anna, Svyatoslav and Maps time limit per test2 seconds memory limit per test256 megabytes inputst ...

  5. D2. Kirk and a Binary String (hard version) D1 Kirk and a Binary String (easy version) Codeforces Round #581 (Div. 2) (实现,构造)

    D2. Kirk and a Binary String (hard version) time limit per test1 second memory limit per test256 meg ...

  6. Codeforces Round #581 (Div. 2) B. Mislove Has Lost an Array (贪心)

    B. Mislove Has Lost an Array time limit per test1 second memory limit per test256 megabytes inputsta ...

  7. Codeforces Round #581 (Div. 2)A BowWow and the Timetable (思维)

    A. BowWow and the Timetable time limit per test1 second memory limit per test256 megabytes inputstan ...

  8. Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...

  9. Codeforces Round #581(Div. 2)

    Codeforces Round #581(Div. 2) CF 1204 A. BowWow and the Timetable 题解:发现,$4$的幂次的二进制就是一个$1$后面跟偶数个$0$. ...

随机推荐

  1. 阿里云容器Kubernetes监控(九) - Kubernetes事件离线工具kube-eventer正式开源

    前言 监控是保障系统稳定性的重要组成部分,在Kubernetes开源生态中,资源类的监控工具与组件百花齐放.除了社区自己孵化的metrics-server,还有从CNCF毕业的Prometheus等等 ...

  2. Eclipse中提示 找不到类 javax.servlet.http.HttpServletResponse

    问题如题, 解决方案如下: 复制tomcat的安装路径下\lib\servlet-api.jar 到WEB-INF/lib下即可.

  3. js cookies 的写入、读取、删除

    //写cookies //escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串.function setCookie(name,value) {     var Days ...

  4. jq动态添加代码监听问题

     $(document).on('click', '.class', function() { console.log($(this).attr('id')); }); 

  5. 在沙箱中IE不能上网的解决方法

    近期在解决一个问题,在我们的沙箱中IE不能上网 现象:     IE不能上网.输入www.baidu.com 提示:不能查找到DNS.也不能ping 通     其它浏览器上网没有问题(SG浏览器,C ...

  6. W600 一块新的 KiCad PCB

    W600 一块新的 KiCad PCB 打算做以下功能. Type-C USB. 使用 KiCad 画板. 加入串口芯片,方便调试. 使用 PCB 天线.

  7. SQL注入原理讲解,很不错!

    SQL注入原理讲解,很不错! 原文地址:http://www.cnblogs.com/rush/archive/2011/12/31/2309203.html 1.1.1 摘要 日前,国内最大的程序员 ...

  8. jq 监听返回事件

    <script> $(document).ready(function(e) {             var counter = 0;            if (window.hi ...

  9. Python基础:20类的定制

    类中有一些可自定义的特殊方法,它们中的一些有预定义的默认行为,而其它一些则没有,留到需要的时候去实现.这些特殊方法是Python中用来扩充类的强有力的方式.它们可以实现模拟标准类型和重载操作符等.比如 ...

  10. 从 Spark 到 Kubernetes — MaxCompute 的云原生开源生态实践之路

    2019年5月14日,喜提浙江省科学技术进步一等奖的 MaxCompute 是阿里巴巴自研的 EB 级大数据计算平台.该平台依托阿里云飞天基础架构,是阿里巴巴在10年前做飞天系统的三大件之分布式计算部 ...