Sunday, April 30, 2017

URI Solution 1031 - Power Crisis | Solution in C++ | Ad Hoc

URI Solution 1031 - Power Crisis | Solution in C++ | Ad Hoc


URI Online Judge Solution  | Ad Hoc


Problem Name: URI Problem
Problem Number : URI - 1031
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1031 Code in CPP:


#include <cstdio>
#include <vector>

#define PB push_back
#define SC1(a) scanf("%d", &a)
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)

using namespace std;

typedef vector<int> VI;

bool crisis(int n, int k)
{
 int p = 0;
 VI v;

 REP(i, 1, n)
  v.PB(i);

 if(v.size() > 1){
  do{
   v.erase(v.begin() + p);
   p = (p - 1 + k) % v.size();
  }while(v.size() > 1);
 }

 return (v[0] == 13);
}

int main(int argc, char const *argv[])
{
 int n, r;

 while(SC1(n) && n)
 {
  r = 1;
  while(!crisis(n, r))
   r++;

  printf("%d\n", r);
 }

 return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.