Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Consider a pair of integers, (a,b). The following operations can be performed on (a,b) in any order, zero or more times: - (a,b) -> ( a+b, b ) - (a,b) -> ( a, a+b )

static LinkedList<Pair<Integer,Integer>> pairs = new LinkedList<Pair<Integer, Integer>>();
    public static String isItPossible(Integer a, Integer b, Integer c, Integer d){
        pairs.addLast(new Pair<Integer, Integer>(a,b));
        while (!pairs.isEmpty()){
            Pair<Integer,Integer> pair = pairs.poll();
            Integer key = pair.getKey();
            Integer value = pair.getValue();
            if(key.equals(a) &&
                    value.equals(b)){
                return "YES";
            }
            int sum=key+value;
            if (sum<=c){
                pairs.addLast(new Pair<Integer, Integer>(sum,value));
            }
            if (sum<=d){
                pairs.addLast(new Pair<Integer, Integer>(key,sum));
            }
 
        }
 
        return "NO";
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: bounded and unbounded solution in lpp 
Cpp :: return value optimization example 
Cpp :: c++ else 
Cpp :: sum of 2 arrays c++ 
Cpp :: dualSort 
Cpp :: assoc-right antlr 
Cpp :: how to calculate the sum of primary diagonal matrix and secondary diagonal matrix using c++ 
Cpp :: executing linux scripts 
Cpp :: how to get the numbers in a vector c++ sfml 
Cpp :: opengl triangle example 
Cpp :: pointers in c++ 
Cpp :: what does : mean in c++ 
Cpp :: stack in c++ 
Cpp :: transform cpp 
Cpp :: c++ destructor 
Cpp :: can derived class access private members 
Cpp :: convert c++ to mips assembly code online 
Cpp :: qt graphics scene map cursor position 
C :: install kubernetes kubectl on mac 
C :: c remove last character from a string 
C :: roll binary c 
C :: how to find all the missing dates and increment the series in r 
C :: random number c 
C :: c format specifiers 
C :: 0/1 knapsack problem in c 
C :: check if the c code is a palindrome 
C :: how to open a website in c 
C :: read string with space c 
C :: text berjalan html 
C :: how to open a file with open in c 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =