Sunday, 3 September 2017

CodeForce Problem 318A - Even Odds (C++)

Problem:

Please find the problem here
.

Solution:

This is one of the easiest problem I ever had, just implement the given formulas! However, it does take me a few minutes to write.

Code:
//Even Odds Solution
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
using namespace std;
int main(){
ll n, k;
cin>>n>>k;
//Suppose n=10.
//Odd series then Even series 1,3,5,7,9,2,4,6,8,10.
n=(n+1)/2; //Finding the mid point.In above case it is 9.
//Condition 1.greater than 9 Even and vice-versa(Odd).
cout<<(k>n? 2*(k-n):2*k-1)<<endl;//if and else condition

return 0;
}

No comments:

Post a Comment

Spoj Problem ACMCEG2C - Pick the candies (C++)

  The problem link may be found here.       Explanation: Use Deque to keep track of elements of the variety of candies. If i is gre...