diff options
| author | Aditya Naik | 2018-05-12 21:00:48 -0400 |
|---|---|---|
| committer | Aditya Naik | 2018-05-12 21:00:48 -0400 |
| commit | 6fc7554c74c5745c8890f2367628d3d1cf3ddac7 (patch) | |
| tree | 7593c2050df9e5290c8c64bc63cfa472769ef6de /591 | |
| parent | 240b65a7e9c514acde1cb33b24053cdcac06c7e8 (diff) | |
huatuo and bricks
Diffstat (limited to '591')
| -rw-r--r-- | 591/bricks.c | 23 | ||||
| -rw-r--r-- | 591/bricks.in | 3 |
2 files changed, 26 insertions, 0 deletions
diff --git a/591/bricks.c b/591/bricks.c new file mode 100644 index 0000000..bd4d047 --- /dev/null +++ b/591/bricks.c @@ -0,0 +1,23 @@ +#include <stdio.h> + +int main(){ + int n, j=0; + scanf("%d", &n); + while(n>0){ + j++; + int heights[100], avg, sum=0, i, moves=0, move, h; + for(i=0; i<n; i++){ + scanf("%d", &h); + sum+=h; + heights[i]=h; + } + avg = sum/n; + for(i=0; i<n; i++){ + move = avg-heights[i]; + moves += (move < 0 ? move*-1 : move); + } + printf("Set #%d\nThe minimum number of moves is %d.\n\n", j, moves/2); + scanf("%d", &n); + } + return 0; +} diff --git a/591/bricks.in b/591/bricks.in new file mode 100644 index 0000000..5d2efdf --- /dev/null +++ b/591/bricks.in @@ -0,0 +1,3 @@ +4 +1 1 3 3 +0
\ No newline at end of file |
