Problem Statement
You are given a circle of diameter d, with n points equally spaced around the circumference. The points are numbered in order around the circle 0, 1, 2, ... , n-1. Of those n points, c of them are colored red. The points that are colored red are given by the generator function (g * k) % n, for k = 0, 1, 2, ..., c-1.
You are given
Definition
- Class:
- QuadrilateralSearch
- Method:
- findLargest
- Parameters:
- int, int, int, int
- Returns:
- double
- Method signature:
- double findLargest(int d, int n, int c, int g)
- (be sure your method is public)
Notes
- The % operator is the modulus (remainder) operator.
- Notice that it makes no difference which point is point 0, and in which direction around the circle the points are numbered.
Constraints
- d will be between 1 and 1000, inclusive.
- n will be between 4 and 1000000000, inclusive.
- c will be between 4 and 500, inclusive.
- c will be less than or equal to n.
- g will be between 1 and n-1, inclusive, and will be relatively prime to n.
Examples
10
13
4
3
Returns: 48.9142858122447
Here, we have only four points that are colored red: 0, 3, 6, and 9. It's just a simple matter of calculating the area of the quadrilateral.
20
31
6
5
Returns: 179.10027343916573
Here, we have six points, so there are 15 possible quadrilaterals. We choose the largest of these.
1000
80000
50
3
Returns: 0.028489712517284715
Here, with 50 points, there are a lot of possible quadrilaterals, but they are all long and flat, so even with such a large circle, they have a very small area.
100
1200
20
139
Returns: 4965.195939678256
123
654321
123
542
Returns: 70.12880984159676
1000
1000000000
500
123456789
Returns: 499718.04154028185
1000
485941898
4
433465349
Returns: 123623.29419658787
7
917812527
417
469490540
Returns: 24.49974943490183
492
682914198
146
462852991
Returns: 120989.03546487243
182
860251130
401
543341301
Returns: 16475.852613059076
468
756769122
135
395816053
Returns: 109470.37892456003
325
485078038
408
363359455
Returns: 52811.11983240667
952
416576804
461
299709161
Returns: 453118.75393075484
660
884578408
356
771557771
Returns: 217797.39977388317
18
137434901
270
129105522
Returns: 161.45094189116742
238
541662396
414
250522913
Returns: 28321.962405276536
820
35066069
77
19578542
Returns: 335969.27029588306
329
581203641
464
21778868
Returns: 54119.49559231788
850
667594374
140
353088535
Returns: 361212.89279805066
467
869345368
10
715960973
Returns: 103969.7748605738
821
743402422
138
238955541
Returns: 337020.45986480213
136
652375401
226
436794958
Returns: 9247.040229894676
861
217663230
132
114844267
Returns: 370618.2644862393
559
22578896
42
13179731
Returns: 156228.1137905926
47
565474452
259
463590727
Returns: 1104.2824814258315
787
462866009
125
12733411
Returns: 309613.5766123615
530
902558745
44
517645126
Returns: 139554.98199260558
1000
19
4
12
Returns: 417888.2011720174
1000
843448655
11
826017634
Returns: 36593.97467726603
1000 11
1000
445350462
247
81202091
Returns: 499985.0057617111
1000
12
5
5
Returns: 466506.3509461097
1000
1000
500
3
Returns: 499995.0652140343
743
1000000000
500
834874743
Returns: 276023.10981023684
100
1000000000
500
999999999
Returns: 7.890246615793739E-13
1000
1000000000
4
999999997
Returns: 0.0
1000
1000000000
500
1
Returns: 7.890246789266087E-11
1000
1000000000
500
900000001
Returns: 475528.73675241636
100
1200
500
139
Returns: 4999.897192325458
997
99987324
497
19999
Returns: 4362.963038625141
100
1000000000
4
999999997
Returns: 0.0
1000
1000000000
500
139
Returns: 1.5328366735900545E-6
1000
1000000000
500
999999999
Returns: 7.890244013708525E-11
1000
1000000000
500
797375799
Returns: 499995.10110618296
1
1000000000
500
453432457
Returns: 0.4999996377227414
1000
1000000000
500
2452347
Returns: 499999.4246806687
1000
1000000000
500
333333333
Returns: 324759.7219832876
10
1000000000
40
999999999
Returns: 5.918152710379437E-15
1000
1000000000
500
39993937
Returns: 497592.35782514693
100
120000013
473
109000121
Returns: 4999.999779362206
1000
1000000000
500
139139139
Returns: 499973.4217768017
1
1000000000
500
13
Returns: 1.2859815141474766E-15
100
533
500
4
Returns: 4999.934860503239
512
991999992
477
491999231
Returns: 131071.98225481887