Problem H. The Fence

/**
题目:Problem H. The Fence
链接:https://vjudge.net/problem/Gym-101090H
题意:给定一个字符串,只有0或者1;
问:假如两个不同的1之间的0,1数量是k的倍数(包括0倍)则输出这两个1的位置;
思路:%k;直到遇到两个相同的余数,说明之间的01数量为k的倍数。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int vis[N];
char s[N];
int main(){
    int k;
    cin>>k;
    scanf("%s",s+1);
    int len = strlen(s + 1);
    memset(vis,0,sizeof(vis));
    for(int i = 1;i <= len;i++){
        if(s[i] == ‘1‘){
            if(vis[(i + k -1)%k]){
                    printf("%d %d\n",vis[(k - 1 + i)%k],i);
                    return 0;
            }
            vis[i%k] = i;
        }
    }
    printf("0 0\n");
    return 0;
}
时间: 2024-10-13 15:54:36

Problem H. The Fence的相关文章

Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description In a Famous TV Show “Find Out” there are n characters and only one Horrible Truth. To make the series breathtaking all way long, the sc

Moscow Subregional 2010 Problem H. Hometask 转化、素数筛选

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010 Problem H. Hometask Time limit: 1 second Memory limit: 256 megabytes Kolya is still trying to pass a test on Numbers Theory. The lecturer is so desperate about Kolya's knowl

Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description Andrew is having a hard time preparing his 239-th contest for Petrozavodsk. This time the solution to the problem is based on Di

ZCMU Problem H: Crixalis&#39;s Equipment(贪心,排序)

#include<stdio.h> #include<stdlib.h> struct node { int a,b; }c[1002]; int cmpxy(const struct node *c,const struct node *d) { return (d->b - d->a) - (c->b - c->a); } int main() { int n,i,v,t,flag; // freopen("a.txt","

实验12:Problem H: 整型数组运算符重载

Home Web Board ProblemSet Standing Status Statistics Problem H: 整型数组运算符重载 Problem H: 整型数组运算符重载 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 643  Solved: 401[Submit][Status][Web Board] Description 定义Array类: 1.拥有数据成员int length和int *mems,分别是数组中元素的个数和元

HDU 6326 Problem H Monster Hunter

\(\mathtt{Problem H}\) \(\mathtt{Monster}\) \(\mathtt{Hunter}\) \(\mathcal{Description}\) 题目 给定一棵 \(n\)\((n \leq 10^6)\) 个点的树,除 \(1\) 号结点外每个结点都有一只怪兽,打败他需要先消耗 \(a_i\) 点 \(HP\),击败后可以获得 \(b_i\) 点 \(HP\),求打败所有怪兽需要的最小 \(HP\). \(\mathcal{Solution}\) 先不考虑父亲

Problem H: 小火山的围棋梦想 多校训练2(小火山专场)

题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1908 题意:如果'.'被'*'围起来,就把'.'变为'*'. 分析:如果是'*'直接输出,如果是'.' 则要对其搜索 如果四个方向都是封闭的,则可以改变.即w[i][j]=4; 如果查询的是'*'或者查询的是已被查询过的'.'  ,则记录上: 如果查询的是'.'而且没有查询标记过,则进行查询: 1 #include<iostream> 2 #include<algorithm&g

UESTC_邱老师选妹子 2015 UESTC Training for Dynamic Programming&lt;Problem H&gt;

H - 邱老师选妹子 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 邱老师长得帅这是人尽皆知,于是追他的妹子就会很多. 但是你知道,邱老师是一个很专一的人,所以他心里面只能有一个人. 于是他决定从追他的众多妹子里挑选一个出来.于是酱神给邱老师出来一个主意,已知有一些妹子,恰好可以给她们从l到r排号,使得每一个妹子有单独的数字,而正好有r-l+1个妹

UESTC_秋实大哥打游戏 2015 UESTC Training for Data Structures&lt;Problem H&gt;

H - 秋实大哥打游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status ”也许人生就是游戏,你却执意耕耘着春秋.” —— 秋实大哥叹道. 秋实大哥是一个喜欢玩游戏的人,相较于其他种类的游戏,秋实大哥更喜欢自由开放的沙盒游戏,尤其是minecraft. 现在,秋实大哥发现了N个独立的小岛(编号1,2,3.....N),于是他要把这些小岛连起来. 每一次