ACM (UVa) : 10784


Diagonal

Data type:
Double

Algorithm:

Basic Formula: Number of diagonal in N-gon is (N * (N-3) ) / 2.

U are given the right portion of the equation, now u have to find the value of N.

Suppose, Given value X

N = ceil ( (3 + sqrt (9 + ( 8 * N))) /2); [ceil >>> under <math.h>]

This equation comes from:
( N * ( N-3 ) ) / 2 = X
> N
2 – 3*N – 2*X = 0

We know, X = (– b + sqrt (b2 – 4 * a * c )) / 2 * a

In C/C++, u can print a double value like integer by using %0.lf.
For example, double X = 963.258;
printf(“%0.lf”, X);
output: 963

One thought on “ACM (UVa) : 10784

  1. hmmm….should I say it? aaa whatever…keep solving problems and when you guys save the world let me know ok? A possible algorithm: how to find world peace. hmmm interesting issue, no?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s