Monday, May 1, 2017

URI Solution 1379 Mean Median Problem - Solution in C++ | Ad Hoc

URI Solution 1379 Mean Median Problem - Solution in C++ | Ad Hoc


URI Online Judge Solution Mean Median Problem  | Ad Hoc
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1379

Problem Name: URI Problem Mean Median Problem
Problem Number : URI Problem 1379 Solution
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1379 Code in CPP:


#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;

bool check(ll a,ll b, ll c)
{
 ll d[4];
 d[1] = a; d[2] = b; d[3] = c;

 sort(d + 1,d + 4);

 if(((a+b+c) % 3 == 0) && ((a+b+c)/3 == d[2])) return true;

 return false;
}

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

 while(scanf("%lld %lld", &a, &b) && (a || b))
 {
  r = 30000000001;

  if(check(a, b, 2 * a - b)) r = min(r, 2 * a - b);
  if(check(a, b, 2 * b - a)) r = min(r, 2 * b - a);
  if(check(a, b, (a + b) / 2)) r = min(r, (a + b) / 2);

  printf("%lld\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 Bloggertheme9 | Distributed By Gooyaabi Templates
Powered by Blogger.