You are not logged in. Please login at www.codechef.com to post your questions!

×

STRLBP - Editorial

PROBLEM LINK:

Practice
Contest

Author: Praveen Dhinwa
Tester: Jingbo Shang
Editorialist: Utkarsh Saxena

PROBLEM

Given a binary string of length $8$. Make the string circular. Count number of places where adjacent bits are different. Print "Uniform" if this count $\le 2$

EXPLANATION

Since this problem was a cakewalk, it is quite straightforward to code. There is quite less to explain apart from giving some observations.

Bruteforce C++

for(int i=0;i<8;++i) count += s[i] != s[(i+1)&7];

Bruteforce Python

for i in range(8): count += s[i] != s[i-1]

Random observations

To have $count=0$ the string must have $8\space 0's$ or $8\space 1's$.

It is not possible to have $count=1$.

To have $count = 2$, the string must have exactly one $1$ or exactly one $0$.

So for this problem the total number of $1$ in the string can be $0, 1, 7, 8$.

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.
Tester's solution can be found here.

This question is marked "community wiki".

asked 13 Jan, 17:59

usaxena95's gravatar image

7★usaxena95
2211312
accept rate: 0%

edited 20 Feb, 16:59

admin's gravatar image

0★admin ♦♦
19.6k349497539


**include<iostream.h> void main() { int s[10],c=0; for(int i=0;i<8;i++) { if (s[i]!=s[i+1]) { c=c+1 } } if(c<=2) { cout<<"uniform";} else cout<<"non-uniform"; }

link

answered 18 Jan, 22:40

harry1314's gravatar image

0★harry1314
1
accept rate: 0%

include<bits stdc++.h="">

using namespace std; int main() { int t; cin>>t; while(t--) { string s; cin>>s; int x=unique(s.begin(),s.end())-s.begin(); if(x<=3) { cout<<"uniform\n"; } else { cout<<"non-uniform\n"; } } return 0; }

link

answered 05 Dec, 21:11

jatinmunjal2k's gravatar image

3★jatinmunjal2k
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,192
×1,579
×94
×24
×3

question asked: 13 Jan, 17:59

question was seen: 920 times

last updated: 05 Dec, 21:11