Advertisement
stanevplamen

03.01.10.CoordinateCamel

Jul 2nd, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class CoordinateCamel
  5. {
  6.     static void Main()
  7.     {
  8.         // chetem broia
  9.         int numbersAmountN = int.Parse(Console.ReadLine());
  10.         int variationsAmountK = numbersAmountN;
  11.  
  12.         BigInteger meters = 0;
  13.         for (int i = 0; i < numbersAmountN; i++)
  14.         {
  15.             string notUsed = Console.ReadLine();
  16.             // chetem dvete koordinati
  17.             string[] twoNumbers = Console.ReadLine().Split();
  18.             int x = int.Parse(twoNumbers[0]);
  19.             int y = int.Parse(twoNumbers[1]);
  20.  
  21.             meters = meters + Math.Abs(x) + Math.Abs(y);
  22.         }
  23.  
  24.         BigInteger result = 0;
  25.         for (int k = 1; k <= variationsAmountK; k++)
  26.         {
  27.  
  28.             BigInteger factorialKminus = 1;
  29.             for (int j = 1; j <= k - 1; j++)
  30.             {
  31.                 factorialKminus = factorialKminus * j;
  32.             }
  33.  
  34.             BigInteger factorialNminusK = 1;
  35.             for (int j = 1; j <= numbersAmountN - k; j++)
  36.             {
  37.                 factorialNminusK = factorialNminusK * j;
  38.             }
  39.  
  40.             BigInteger factorialN = 1;
  41.             for (int j = 1; j <= numbersAmountN; j++)
  42.             {
  43.                 factorialN = factorialN * j;
  44.             }
  45.  
  46.             BigInteger repeatingTimes = factorialN / (factorialNminusK * factorialKminus * numbersAmountN );
  47.             if (k == numbersAmountN)
  48.             {
  49.                 repeatingTimes = 1;
  50.             }
  51.  
  52.             result = result + repeatingTimes * meters;
  53.         }
  54.         Console.WriteLine(result);      
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement