http://codeforces.com/gym/100712/attachments

题意:

给出一串数字,每次选择连续的k个数字加上任意数(超过10就取余),最后要使得所有数字都相等,求最大的k。

思路:

开关翻转问题。

算法具体可以参考《挑战程序竞赛》常用技巧篇。

这道题目就是在枚举k的同时再枚举一下最后要转换成的数字即可。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,long long> pll;
const int INF = 0x3f3f;
const int maxn=+; int n,k;
int a[maxn];
int b[maxn];
int f[maxn];
char str[maxn]; bool calc(int k)
{
memcpy(b,a,sizeof(a));
for(int t=;t<;t++) //枚举最后转换的数
{
memset(f,,sizeof(f));
int sum=;
for(int i=;i+k<=n;i++)
{
if(((b[i]+sum)%)!=t)
f[i]=((t-b[i]-sum)%+)%;
sum+=f[i];
if(i-k+>=) sum-=f[i-k+];
} bool flag=true;
for(int i=n-k+;i<n;i++)
{
if(((b[i]+sum)%)!=t)
{
flag=false;
break;
}
if(i-k+>=) sum-=f[i-k+];
}
if(flag) return true;
}
return false;
} int main()
{
//freopen("input.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
getchar();
scanf("%s",str); n=strlen(str);
for(int i=;i<n;i++) a[i]=str[i]-''; for(int k=n;k>=;k--)
{
if(calc(k))
{
printf("%d\n",k);
break;
}
}
}
return ;
}

Gym 100712I Bahosain and Digits(开关翻转问题)的更多相关文章

  1. UVA 679 Dropping Balls 由小见大,分析思考 二叉树放小球,开关翻转,小球最终落下叶子编号。

    A number of K balls are dropped one by one from the root of a fully binary tree structure FBT. Each ...

  2. 18春季训练01-3/11 2015 ACM Amman Collegiate Programming Contest

    Solved A Gym 100712A Who Is The Winner Solved B Gym 100712B Rock-Paper-Scissors Solved C Gym 100712C ...

  3. 2015 ACM Amman Collegiate Programming Contest 题解

    [题目链接] A - Who Is The Winner 模拟. #include <bits/stdc++.h> using namespace std; int T; int n; s ...

  4. 浅谈Power Signoff

    Power Analysis是芯片设计实现中极重要的一环,因为它直接关系到芯片的性能和可靠性.Power Analysis 需要Timing Analysis 产生包含频率.transition 等时 ...

  5. B. Light bulbs

    B. Light bulbs There are NNN light bulbs indexed from 000 to N−1N-1N−1. Initially, all of them are o ...

  6. Codeforces Gym 100531D Digits 暴力

    Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...

  7. POJ 1222 EXTENDED LIGHTS OUT(翻转+二维开关问题)

    POJ 1222 EXTENDED LIGHTS OUT 今天真是完美的一天,这是我在poj上的100A,留个纪念,马上就要期中考试了,可能后面几周刷题就没这么快了,不管怎样,为下一个200A奋斗, ...

  8. 翻转整数 Reverse digits of a number

    两种方法翻转一个整数.顺序翻转和递归翻转 这里没考虑overflow的情况 递归的作用是使得反向处理.即从递归栈的最低端開始处理.通过绘图可得. 假设是rec(num/10): 12345 1234 ...

  9. Gym 100531D Digits (暴力)

    题意:给定一个数字,问你找 n 个数,使得这 n 个数各位数字之和都相等,并且和最小. 析:暴力,去枚举和是 1 2 3...,然后去选择最小的. 代码如下: #pragma comment(link ...

随机推荐

  1. 破谣言——iPhone砍价

    微信朋友圈和QQ空间很多朋友在传一个iPhone砍价免费送的活动.好吧,砍页面下面的那邪恶广告,第一感觉就是假的.但我要给出证明,所以就有了下面的代码.[只需把UID换成自己的就行],当你砍到5分钱的 ...

  2. 一个Activity中使用两个layout实例

    package com.sbs.aas2l; import android.app.Activity; import android.os.Bundle; import android.view.Vi ...

  3. Oracle在linux下命令行无法使用退格键退格,无法使用上下键切换历史命令的解决办法

    使用xshell等客户端登录oracl时在命令行无法使用退格键也无法使用上下键切换历史命令可以使用rlwrap解决 1,linux环境 2,下载rlwrap wget http://files.cnb ...

  4. 针对Redis队列的理解,实例操作(转)

    原文:本文出自 “峰云,就她了.”  http://rfyiamcool.blog.51cto.com/1030776/1131271 为什么要使用消息队列 用我的话来说, 队列特点是先进先出,在任务 ...

  5. 解决redis远程连接不上的问题

    解决redis远程连接不上的问题 redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf(有的 ...

  6. 安装Ruby、Sass在WebStrom添加Watcher实现编辑scss文件时自动生成.map和压缩后的.css文件

    前言 这段时间一直在看Bootstrap,V3官方直接提供了Less版本的源码,就先将Less学完了,很简单的语法,学习写Demo都是在Webstorm里写的,配置了Watcher自动编译(详见< ...

  7. public boolean onKeyDown(int keyCode, KeyEvent event)

    @Override 2 public boolean onKeyDown(int keyCode, KeyEvent event) { 3 // TODO Auto-generated method ...

  8. MySQL和MSSQL差异(增量)备份的原理

    MySQL和MSSQL差异(增量)备份的原理 对于真正的增量备份来说,只需要记录当前每页最后的检查点的LSN,如果大于之前全备时的LSN,则备份该页面,否则不用备份 这大大加快了备份速度和恢复时间,同 ...

  9. 001-Spring的设计理念和整体架构

    一.概述 1.1.Spring的各个子项目 网站:https://spring.io/ 基于Spring的项目:https://spring.io/projects 文档列表:https://spri ...

  10. PHP debug_backtrace() 函数打印调用处的调试信息

    http://php.net/manual/zh/function.debug-backtrace.php debug_backtrace (PHP 4 >= 4.3.0, PHP 5, PHP ...