-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f026d7
commit 8f6b559
Showing
15 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
//Uses https://en.wikipedia.org/wiki/Flexible_array_member at end of struct | ||
typedef struct { | ||
int dl; | ||
double el[]; | ||
} ciag; | ||
|
||
ciag *roznicowy(ciag *c) { | ||
ciag *r = malloc(sizeof(ciag) + (size_t)(c->dl - 1) * sizeof(double)); | ||
r->dl = c->dl - 1; | ||
|
||
for (int i = 0; i < r->dl; i++) | ||
r->el[i] = c->el[i + 1] - c->el[i]; | ||
|
||
return r; | ||
} | ||
|
||
ciag *readCiag() { | ||
int dl; | ||
if(!scanf("%d", &dl)) printf("wrong input"); | ||
|
||
ciag *c = malloc(sizeof(ciag) + (size_t)dl * sizeof(double)); | ||
c->dl = dl; | ||
|
||
for (int i = 0; i < dl; i++) | ||
if(!scanf("%lf", &(c->el[i]))) printf("wrong input"); | ||
|
||
return c; | ||
} | ||
|
||
void printCiag(ciag *c) { | ||
for (int i = 0; i < c->dl; i++) | ||
printf("%lf ", c->el[i]); | ||
} | ||
|
||
int main() { | ||
ciag *c = readCiag(); | ||
|
||
printCiag(roznicowy(c)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
//Uses https://en.wikipedia.org/wiki/Flexible_array_member at end of struct | ||
typedef struct ciag { | ||
int dl; | ||
struct ciag *next; | ||
double el[]; | ||
} ciag; | ||
|
||
ciag *roznicowyRec(ciag *c) { | ||
c->next = malloc(sizeof(ciag) + (size_t)(c->dl - 1) * sizeof(double)); | ||
c->next->dl = c->dl - 1; | ||
c->next->next = NULL; | ||
|
||
for (int i = 0; i < c->next->dl; i++) | ||
c->next->el[i] = c->el[i + 1] - c->el[i]; | ||
|
||
if(c->next->dl != 0) roznicowyRec(c->next); | ||
|
||
return c; | ||
} | ||
|
||
ciag *readCiag() { | ||
int dl; | ||
if(!scanf("%d", &dl)) printf("wrong input"); | ||
|
||
ciag *c = malloc(sizeof(ciag) + (size_t)dl * sizeof(double)); | ||
c->dl = dl; | ||
c->next = NULL; | ||
|
||
for (int i = 0; i < dl; i++) | ||
if(!scanf("%lf", &(c->el[i]))) printf("wrong input"); | ||
|
||
return c; | ||
} | ||
|
||
void printCiag(ciag *c) { | ||
for (int i = 0; i < c->dl; i++) | ||
printf("%lf ", c->el[i]); | ||
|
||
printf("\n"); | ||
|
||
if(c->next != NULL) printCiag(c->next); | ||
} | ||
|
||
int main() { | ||
ciag *c = readCiag(); | ||
|
||
printCiag(roznicowyRec(c)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define x_size 6 | ||
#define y_size 4 | ||
|
||
int orzechy(int a[x_size][y_size], int k) { | ||
int sumPref[x_size + 1][y_size + 1]; | ||
|
||
//Obliczanie sumy prefiksowej | ||
for (int y = 0; y < y_size + 1; y++) { | ||
for (int x = 0; x < x_size + 1; x++) { | ||
if (x == 0 || y == 0) { | ||
sumPref[x][y] = 0; | ||
} else { | ||
sumPref[x][y] = a[x - 1][y - 1] + sumPref[x - 1][y] + | ||
sumPref[x][y - 1] - sumPref[x - 1][y - 1]; | ||
} | ||
} | ||
} | ||
|
||
int maks = 0; | ||
|
||
//Sprawdzanie wszystkich prostokątów zaczynających się w x i y | ||
for (int x = 0; x < x_size; x++) { | ||
for (int y = 0; y < y_size; y++) { | ||
for (int w = 1; w <= k && x + w <= x_size; w++) { | ||
if (k % w != 0) | ||
continue; | ||
|
||
int h = k / w; | ||
|
||
if (y + h > y_size) | ||
continue; | ||
|
||
int suma = sumPref[x + w][y + h] - sumPref[x][y + h] - | ||
sumPref[x + w][y] + sumPref[x][y]; | ||
|
||
if (suma > maks) | ||
maks = suma; | ||
} | ||
} | ||
} | ||
|
||
return maks; | ||
} | ||
|
||
int main() { | ||
int k; | ||
int t[x_size][y_size]; | ||
|
||
for (int y = 0; y < y_size; y++) | ||
for (int x = 0; x < x_size; x++) | ||
if(!scanf("%d", &t[x][y])) printf("wrong input"); | ||
|
||
if(!scanf("%d", &k)) printf("wrong input"); | ||
|
||
printf("%d", orzechy(t, k)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 1 1 1 1 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.000000 0.000000 0.000000 0.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6 1 2 3 4 5 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.000000 1.000000 1.000000 1.000000 1.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
10 1 6 -3 2 10 12 3 5 24 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.000000 -9.000000 5.000000 8.000000 2.000000 -9.000000 2.000000 19.000000 -24.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4 1 2 4 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1.000000 2.000000 4.000000 7.000000 | ||
1.000000 2.000000 3.000000 | ||
1.000000 1.000000 | ||
0.000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
0 0 4 1 2 0 | ||
3 3 8 11 3 2 | ||
1 3 9 8 1 2 | ||
2 1 1 2 0 12 | ||
|
||
6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
42 |