-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path547.cpp
More file actions
73 lines (65 loc) · 1.82 KB
/
547.cpp
File metadata and controls
73 lines (65 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <math.h>
//level one
class Pillars
{
public:
double getExpectedLength(int w, int x, int y);
};
double Pillars::getExpectedLength(int w, int x, int y)
{
double result = 0;
int count = 0;
for ( int i = 1 ; i <= x; i++ ){
//int low = ( i - w > 0 ) ? i - w: 0;
for ( int j = 1 ; j <= y;j++ ){
double s = sqrt((double)(( i - j ) * ( i - j ) + w * w));
result += s;
count++;
}
}
if ( count == 0 ) return 0;
return result/count;
}
class RectangularSum
{
public:
long minimalArea(int height, int width, long S);
};
//need check
long RectangularSum::minimalArea(int height, int width, long S)
{
long result = 0x7fffffff;
for ( int i = 1 ; i <= height; i++ )
{
for ( int j = 1; j <= width; j++ ){
long long temp = ( i * ( i - 1) /2 ) * j * width + ( j * ( j - 1) / 2) * i ;
if ( temp > S )
break;
/*if ( temp < S )
continue;
long count = i * j;
result = result > count ? count : result;*/
long long res = S - temp;
if ( res % ( i * j ) != 0 )
//cannot find the result in the sub result
continue;
long val = res / i / j;
long r = val / i, c = val % j;
if ( r + i <= height && c + j <= width ) {
long count = i * j;
result = result > count ? count : result;
}
}
}
return result;
}
int main()
{
/*Pillars pl;
double result = pl.getExpectedLength(10, 15,23);*/
RectangularSum rs;
long result = rs.minimalArea(50000, 50000, 963761198400);
printf("result is %d\n", result);
return 0;
}