dp 20190617
这个标的是dp,但是我感觉就只能算思维题,不是特别难,
你仔细想想就知道,你先求出01这样子满足条件的个数,如果要进行改变,最多只可以增加两个,也可以增加一个或者不增加。
如果有连续的两个1或者0那么肯定至少可以增加一个,如果有两个不同的00 或者11 或者是两个11连续 或者两个00不连续 或者三个相同的0或者1都是可以增加两个的。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define inf 0x3ff3f3f
using namespace std;
const int maxn = 1e6 + ;
char a[maxn];
int num[maxn]; int main()
{
int n;
scanf("%d", &n);
scanf("%s", a + );
int len = strlen(a + );
int ans = ;
int f = ;
for(int i=;i<=len;i++) num[i] = a[i] - '';
int flag = num[];
for(int i=;i<=len;i++) if (num[i] == !flag) flag = num[i], ans++;
for (int i = ; i < len; i++) if (num[i] == num[i + ]) f = ;
//printf("%d\n", ans);
int ex = ;
if(f) printf("%d\n", ans);
else
{
for(int i=;i<len;i++)
{
if(num[i]==num[i+])
{
ex++;
int x = i;
while (num[x] == num[x + ]) x++;
i = x;
}
}
for (int i = ; i < len - ; i++) if (num[i] == num[i + ] && num[i] == num[i + ]) ex = ;
if (ex >= ) printf("%d\n", ans + );
else printf("%d\n", ans + );
}
return ; }
/*
56
10101011010101010101010101010101010101011010101010101010
*/
A
这个题目不是很难,思维题,这个题目有几种情况要考虑,
第一个是存在1的情况,那么答案就是n-flag,flag表示1的数量。
第二个就是看他们的所有数gcd是不是等于1 如果不是那么就输出-1
第三个就是gcd==1 所以但是没有1 这个时候我们就可以找到每一个一段进行gcd==1 把所有的段都保存下来,然后求最小的数值让他gcd==1
找到之后就再加上n-1即可。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 2e3 + ;
queue<int>que;
int a[maxn]; int gcd(int a,int b)
{
return b == ? a : gcd(b, a%b);
} int main()
{
int n;
scanf("%d", &n);
int flag = ;
for (int i = ; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == ) flag++;
}
if(flag)
{
printf("%d\n", n - flag);
return ;
}
flag = ;
int ans = a[];
int ax = a[];
for(int i=;i<=n;i++)
{
if (gcd(a[i], a[i - ]) == ) flag = ;
ans = gcd(ans, a[i]);
ax = gcd(ax, a[i]);
if(ans==)
{
que.push(i);
ans = a[i + ];
}
}
if (flag) printf("%d\n", n);
else if (ax != ) printf("-1\n");
else
{
int an = inf;
while(!que.empty())
{
int num = ;
int u = que.front(); que.pop();
int ex = a[u]; u--;
while(ex!=)
{
ex = gcd(ex, a[u]);
u--;
num++;
}
an = min(an, num);
}
printf("%d\n", n - + an);
}
return ;
}
A
dp 20190617的更多相关文章
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
- AEAI DP V3.7.0 发布,开源综合应用开发平台
1 升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...
- AEAI DP V3.6.0 升级说明,开源综合应用开发平台
AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4026 Solved: 1473[Submit] ...
- [斜率优化DP]【学习笔记】【更新中】
参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...
- BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]
1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9812 Solved: 3978[Submit][St ...
- px、dp和sp,这些单位有什么区别?
DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...
- android px转换为dip/dp
/** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...
随机推荐
- Java正则表达式基础知识及实例说明
众所周知,在程序开发中,难免会遇到需要匹配.查找.替换.判断字符串的情况发生,而这些情况有时又比较复杂,如果用纯编码方式解决,往往会浪费程序员的时间及精力.因此,学习及使用正则表达式,便成了解决这一矛 ...
- 01-css3之过渡
一.介绍 过渡(transition)是CSS3中具有颠覆性的特征之一,我们可以在不使用 Flash 动画或 JavaScript 的情况下,当元素从一种样式变换为另一种样式时为元素添加效果,经常和 ...
- Starlims Client Request Portal 客户申请门户
用户可以直接在starlims对外的"客户申请门户"上发起检验申请,并追踪检验进度等. 工作流程图示如下:
- 用threejs 实现3D物体在浏览器展示
用threejs 实现3D物体在浏览器展示,通过鼠标平移,缩放,键盘箭头按钮左右移动等功能展示. <!DOCTYPE html> <html> <head> < ...
- L23模型微调fine tuning
resnet185352 链接:https://pan.baidu.com/s/1EZs9XVUjUf1MzaKYbJlcSA 提取码:axd1 9.2 微调 在前面的一些章节中,我们介绍了如何在只有 ...
- I - Red and Black DFS
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A ...
- 【特征检测】BRISK特征提取算法
[特征检测]BRISK特征提取算法原创hujingshuang 发布于2015-07-24 22:59:21 阅读数 17840 收藏展开简介 BRISK算法是2011年ICCV上< ...
- python基础-json、pickle模块
json.pickle区别 总结: """ json: 1.不是所有的数据类型否可以序列化,序列化返回结果为字符串 2.不能多次对同一文件序列化 3.json数据可以跨语 ...
- Volatile的应用DCL单例模式(四)
Volatile的应用 单例模式DCL代码 首先回顾一下,单线程下的单例模式代码 /** * 单例模式 * * @author xiaocheng * @date 2020/4/22 9:19 */ ...
- 常见web漏洞整理之进击吧xss!!!
XSS在线测试环境: http://xss-quiz.int21h.jp/ https://brutelogic.com.br/xss.php 这两个站对xss的理解很有帮助!!! 参考链接: htt ...