Skip to main content

Posts

Showing posts from December, 2017

Watching Video

                            Watching Video                                                                   binary search Problem Link #include <iostream> using namespace std; long n, d; long arr[1000001]; bool func(int t) {     long long tmp=0;     for(int i=1;i<=t;i++)         tmp+=arr[i];     t++;          while(tmp>=d && t < n+1) {         if(tmp <d)             return false;         tmp -= d;         tmp+=arr[t];         t++;     }          if(t==n+1)         return true;     else         return false; } int bs(int low, int high) {     int mid;     while(low < high)     {         mid = (low + high) / 2;                 if(func(mid))         {             high = mid;         }         else         {             low = mid + 1;         }     }     return high; } int main() {     cin >> n >> d;     for(int i = 1; i <= n; i++)     {         cin >> arr[i];     }     for(int i

Round Table Meeting

                          Round Table Meeting Problem Link #include <iostream> #include <cmath> #include <climits> using namespace std; int main() {     int n, q;     int x, y;     cin >> n >> q;     int arr[2 * n + 1];     for(int i = 1; i <= n; i++)     {         cin >> arr[i];         arr[i + n] = arr[i];     }     for(int k = 0; k < q; k++)     {         cin >> x >> y;         int dist = INT_MAX;         int minDist = INT_MAX;         int posx = -1;         int posy = -1;                 if(x == y)         {                       minDist = 0;                     }                 else         {                                 for(int i = 1; i <= 2 * n; i++)             {                 if(arr[i] == x)                 {                       posx = i;                                 }                 else if(arr[i] == y)                 {                       posy = i;