GHOUS1425's blog

By GHOUS1425, history, 2 weeks ago, In English

Howdy,

GHOUS1425 is here to help beginners who are either new to CP or want to get better at implementation. I will suggest some problems(they are the best!) that will not only help you get better at implementation, but also teach you skills on what to do and what not to do.

Starting off with learning a language(I prefer Py, C++, Java && it depends on you what you want to do).

Now Its not easy ik, it is not easy from beginning but it will be! I tried 8 problems and now I am not just getting better at implementation but the different ways of thinking too. Here are those 8 problems I got from Codeforce and cses

  1. Weird Algorithm.

  2. Missing Number.

  3. Repetitions.

  4. Increasing Array.

  5. Wrong Subtraction.

  6. 1-1

  7. Specialty String

  8. Teamwork (I made this one)

Full text and comments »

  • Vote: I like it
  • -15
  • Vote: I do not like it

By GHOUS1425, history, 5 weeks ago, In English

Hey,

In this blog, I will explain my own method on how to solve this problem from this contest.

So what I did in my code was I checked two cases, 1. Maximum, 2. Minimum. In case 1, I checked that If s[i-1] & s[i+1] are equal to '1'. If they were, I made s[i] = '1'. And after the loop, I made a var called maximum which had the count of 1's in the modified string.

In case 2, I checked if s[i-1] and s[i+1] are equal to '1'. If they were, I made s[i] = '0'. Now after the loop, I made a var called minimum which had the count of '1' in the string modified in the loop. Now at the end I printed Minimum and maximum.

#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        string s;
        cin >> n >> s;
        for(int i=0;i<n;i++) {
            if(s[i-1]=='1' && s[i+1]=='1') {
                s[i]='1';
            }
        }
        int maxi= count(s.begin(), s.end(), '1');
 
        for(int i=0;i<n;i++) {
            if(s[i-1]=='1' && s[i+1]=='1') {
                s[i]='0';
            }
        }
        int mini= count(s.begin(), s.end(), '1');
 
        cout << mini << " " << maxi << endl;
    }
  return 0;
}

No one still answered my question.. "why wasn't it a dijkstra?"

Hope the blog helped

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it