Блог пользователя Mohsina_Shaikh

Автор Mohsina_Shaikh, история, 9 месяцев назад, По-английски

Hello, Can anyone please help me to understand why Greedy works for the above problem Painting Eggs I have read the editorial and not able to fully understand how greedy is the correct solution for the problem.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

Автор Mohsina_Shaikh, история, 17 месяцев назад, По-английски

Can anyone please provide an approach or hint on how we can solve the below problem using two pointers. Shopping Clothes

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор Mohsina_Shaikh, история, 21 месяц назад, По-английски

Hello can anyone please explain how to optimize this code.Currently It is giving TLE.

#include<bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	std::cin >> t;
	while(t--)
	{
       int n,m,q;
       cin>>n>>m;
       vector<pair<int,int>> haters(m,make_pair(0,0));
       int x=0,y=0;
       for(int i=0;i<m;i++){
           cin>>x>>y;
           haters[i].first=x;
           haters[i].second=y;
       }
       cin>>q;
       int k=0,li=0,ri=0;
      
       while(q--){
            
            bitset<200005> b1;
            cin>>k;
            for(int i=0;i<k;i++){
                 cin>>li>>ri;
                 //setting bits from range l to r
                 for(int j=li;j<=ri;j++){
                     b1[j]=1;
                 }
            }
             int i=0;
             for(i=0;i<m;i++){
                 //iterating over all m pairs
                 //to find if haters pair is set
                 if(b1[haters[i].first]==1 && b1[haters[i].second]==1){
                     break;
                 }
             }
             if(i==m){
                 cout<<"YES"<<"\n";
             }else{
                 cout<<"NO"<<"\n";
             }
       }
     }
	return 0;
}

Adding the Problem Link : PARTY Can anyone please help on how we can optimize this

Полный текст и комментарии »

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

Автор Mohsina_Shaikh, история, 21 месяц назад, По-английски
#include <bits/stdc++.h>

using namespace std;

int main()
{
    bitset<8> bt(3);
    bt[1]|=1;
    cout<<bt[1]<<"\n";
    return 0;
}

The program throws error. Why cannot we perform bitwise operations on bitsets like this.can anyone please explain.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

Автор Mohsina_Shaikh, история, 21 месяц назад, По-английски

Can anyone please explain why my program crashes without mentioning any error If I try to create vector of size 10^9 in c++.Anyway If I decrease the size of vector let's suppose to something like 10^7 and 10^6 it works fine

Полный текст и комментарии »

  • Проголосовать: нравится
  • -4
  • Проголосовать: не нравится

Автор Mohsina_Shaikh, история, 21 месяц назад, По-английски

Hello can anyone please help on how to solve this problem.

Adding the link for reference Bulb Switcher

Im not able to reach to a solution for this problem.Any help would be appreciated.Thanks

Полный текст и комментарии »

  • Проголосовать: нравится
  • -18
  • Проголосовать: не нравится

Автор Mohsina_Shaikh, история, 21 месяц назад, По-английски

Is finding rightmost set bit by this approach wrong.

int ans=xorsum,int rightmost=0;
 while(ans){
            int mask=1<<i;
            if(ans&mask){
                break;
            }
            ans=ans>>1; 
            i++;
        }
   rightmost=1<<i;

My code gave WA for some test cases when I used this code snippet to find rightmost set bit.It worked when I removed this with rightmost=xorsum&(-xorsum) can anyone please why the above got snippet may not work.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится