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.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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.
Can anyone please provide an approach or hint on how we can solve the below problem using two pointers. Shopping Clothes
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
#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.
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
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
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.
Название |
---|