Posts

Showing posts from February, 2017

uva 1237 - Expert Enough? Solution

Algorithm   :  Binary Search #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <algorithm> #include <vector> #include <stdio.h> using namespace std; class Car{ public: string name; long low_cost; long high_cost; }; bool car_sort_with_low_cost(Car *c1, Car *c2){ if (c1->low_cost < c2->low_cost) return true; return false; } vector<Car*> vec; void car_binary_search(int start, int end, int val, int &index){ if (start == end){ index = start; return; } int mid = (start + end) / 2; int val1 = vec[mid]->low_cost; int val2 = vec[mid+1]->low_cost; if (val > val1 && val <= val2){ index = mid; return; } if (val2 == val){ car_binary_search(mid + 1, end, val, index); return; } if (val1 == val){ index = mid; return; } if (val1>val){ car_binary_search(start, mid,val,index); return; } if (val2 > ...