A. Alternative Thinking

这个标的是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

A. Pride

这个题目不是很难,思维题,这个题目有几种情况要考虑,

第一个是存在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的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 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 ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

随机推荐

  1. VirtualBox的四种网络连接方式【转】

    VirtualBox中有4中网络连接方式: NAT Bridged Adapter Internal Host-only Adapter VMWare中有三种,其实他跟VMWare 的网络连接方式都是 ...

  2. 一个java 码手 的老牛 --- 涉及 一些不错的java 基础课程

    http://www.zuidaima.      com/user/1550463811307520/share/collect.htm

  3. 一个不错的java学习博客

    http://iteye.blog.163.com/blog/static/18630809620131484835129/

  4. Netperf网络性能测试工具详解教程

    本文下载链接: [学习笔记]Netperf网络性能测试工具.pdf 一.Netperf工具简介 1.什么是Netperf ? (1)Netperf是由惠普公司开发的一种网络性能测量工具,主要针对基于T ...

  5. 【python实现卷积神经网络】开始训练

    代码来源:https://github.com/eriklindernoren/ML-From-Scratch 卷积神经网络中卷积层Conv2D(带stride.padding)的具体实现:https ...

  6. Python导出数据到Excel表格-NotImplementedError: formatting_info=True not yet implemented

    在使用Python写入数据到Excel表格中时出现报错信息记录:“NotImplementedError: formatting_info=True not yet implemented” 报错分析 ...

  7. 测评软件Lemon教程

    Lemon 信息技术测评软件 目录 下载与安装 编译器配置 添加样例和选手 完成测评 1.下载与安装 万恶的 伟大的百度网盘: 链接: https://pan.baidu.com/s/1BfMhs_z ...

  8. Go gRPC进阶-proto数据验证(九)

    前言 上篇介绍了go-grpc-middleware的grpc_zap.grpc_auth和grpc_recovery使用,本篇将介绍grpc_validator,它可以对gRPC数据的输入和输出进行 ...

  9. 设计模式 - 模板方法模式详解及其在Spring中的应用

    基本介绍 模板方法模式(Template Method Pattern)也叫模板模式,它在一个抽象类中公开定义了执行它的方法的模板,它的字类可以按需重写方法实现,但调用将以抽象类中定义的方式进行. 简 ...

  10. 【翻译】TensorFlow卷积神经网络识别CIFAR 10Convolutional Neural Network (CNN)| CIFAR 10 TensorFlow

    原网址:https://data-flair.training/blogs/cnn-tensorflow-cifar-10/ by DataFlair Team · Published May 21, ...