catismyfav's blog

By catismyfav, history, 5 years ago, In English

Hello! I was trying this problem Bear and Prime 100. I have used fflush(stdout) but it is showing idleness limit exceeded. Please help me with this. Here is the code and submission link ~~~~~

int square[] = {4,9,25,49};
int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int div=0;
for(int i=0;i<15;i++){
    cout<<primes[i]<<endl;
    fflush(stdout);
    string response;
    cin>>response;
    if(response[0]=='y') div++;
}
if(div>=2){
    cout<<"composite"<<endl; return ;
}
div=0;
for(int i=0;i<4;i++){
    cout<<square[i]<<endl;
    fflush(stdout);
    string response;
    cin>>response;
    if(response[0]=='y') div++;
}
if(div){
    cout<<"composite"<<endl; return;
}
cout<<"prime"<<endl;

~~~~~

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By catismyfav, history, 5 years ago, In English

Hello all! I have started studying dfs and it's applications and I was studying topological sorting (https://www.spoj.com/problems/TOPOSORT/). I am stuck at the part to check the graph is Acyclic or not? Can anyone help with any easier way to check this? Thanks!

Full text and comments »

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

By catismyfav, history, 5 years ago, In English

Hello all! I was trying this problem. I understand the part that we have to count the numbers according to their modulo with 3 but I am stuck how to form DP states. Can someone please explain that. Thanks!

Full text and comments »

Tags #dp
  • Vote: I like it
  • +4
  • Vote: I do not like it