Monday, May 1, 2017

URI Solution 1311 Army Buddies - Solution in C++ | Ad Hoc

URI Solution 1311 Army Buddies - Solution in C++ | Ad Hoc


URI Online Judge Solution  Army Buddies| Ad Hoc
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1311

Problem Name: URI Problem 1311 Army Buddies
Problem Number : URI Problem 1311 Solution
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus


URI Solution 1311 Code in CPP:


#include <cstdio>

#define sc2(a, b) scanf("%d %d", &a, &b)
#define for(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int left[1000100], right[1000100];

int main(int argc, char const *argv[])
{
 int s, b, l, r;

 while(sc2(s, b) && (s || b))
 {
  for(i, (s + 1))
  {
   left[i] = i - 1;
   right[i] = i + 1;
  }

  for(i, b)
  {
   sc2(l, r);
   if(left[l] < 1) printf("*");
   else printf("%d", left[l]);

   if(right[r] > s) printf(" *\n");
   else printf(" %d\n", right[r]);

   left[right[r]] = left[l];
   right[left[l]] = right[r];
  }

  printf("-\n");
 }

 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.