LZD_DeViL0902's blog

By LZD_DeViL0902, history, 4 years ago, In English

Okay, so I again came up with a similar String question and I don't know how to approach these questions(Optimally), I will be thankful for the explanations if any..

Question Given a sentence string with no spaces in between, find the minimum number of spaces that can be there in the string so that all the generated words are present in a given dictionary. Example:

string: abcdef,,, No.of words in dictionary: 5,,, Dictionary: a bc def ab abc,,,

Answer: 1 ,,,,,, Explanation : By inserting 1 space as shown — 'abc def' we get 2 words abc and def which are valid words in the language Note: You could also split it as 'a bc def' But this would not be the case with minimum number of spaces.

I will be Thankful to the helping responses.

Full text and comments »

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

By LZD_DeViL0902, history, 4 years ago, In English

x is and Element of Array 1 and y is the element of array 2, Find the number of ways in the two arrays where x^y>y^x (NOTE: ^ denotes power here and not the XOR)

First line inputs the number of test cases, second line input the number of elements in two upcoming arrays third line inputs the first array fourth line inputs the second array

EXAMPLE: sampleINPUT:

1
3 2
2 1 6
1 5

sampleOUTPUT 3

<<HERE IS MY POOR CODE,JUST A BRUTE FORCE!!>> IS THERE ANY WAY TO SOLVE IT IN TIME LESS THAN THIS??

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

int main()
{

    int t;
    cin>>t;
    while(t--)
    {
        int m,n;
        cin>>m>>n;
        vector<int> vm(m,0);
        vector<int> vn(n,0);
        for(auto &it:vm)
            cin>>it;
        for(auto &it:vn)
            cin>>it;
            int counts=0;
        for(int x:vm)
            for(int y:vn)
        {

            if(pow(x,y)>(pow(y,x)))
            {
                counts++;

            }
            continue;
        }
        cout<<counts<<endl;
    }
}

Full text and comments »

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