Skip to content

Commit fba0336

Browse files
committed
1019 and 1020
1 parent d2d61b0 commit fba0336

File tree

4 files changed

+238
-0
lines changed

4 files changed

+238
-0
lines changed

1017.cpp

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include <fstream>
2+
#include <iostream>
3+
#include <stdio.h>
4+
#include <vector>
5+
#include <map>
6+
#include <algorithm>
7+
using namespace std;
8+
9+
int main()
10+
{
11+
12+
int t;
13+
int n;
14+
int x;
15+
int y;
16+
int w;
17+
int kmax;
18+
int ans[101][101][101];
19+
fstream cin;
20+
cin.open("wow.in", ios::in);
21+
22+
cin >> t;
23+
//scanf("%d", &t);
24+
25+
for (int j = 1; j <= t; j++) {
26+
// scanf("%d", &n);
27+
// scanf("%d", &w);
28+
// scanf("%d", &kmax);
29+
map <int, int> a;
30+
vector <int> inp;
31+
cin >> n >> w >> kmax;
32+
33+
for (int i = 0; i < n; i++) {
34+
// scanf("%d", &x);
35+
// scanf("%d", &y);
36+
cin >> x >> y;
37+
if(!a.count(y)) {
38+
a[y] = 1;
39+
inp.push_back(y);
40+
}
41+
42+
else {
43+
a[y]++;
44+
}
45+
46+
}
47+
48+
sort(inp.begin(), inp.end());
49+
50+
for (int i = n; i >= 0; i--) {
51+
for (int k = kmax; k >= 0; k--) {
52+
for (int j = n; j >= 0; j--) {
53+
if(i == n) {
54+
ans[i][k][j] = 0;
55+
continue;
56+
}
57+
58+
if(j == n) {
59+
ans[i][k][j] = 0;
60+
continue;
61+
}
62+
63+
if(k == kmax) {
64+
ans[i][k][j] = 0;
65+
continue;
66+
}
67+
68+
if(inp[i] > w + inp[j]) {
69+
x = a[inp[i]] + ans[i + 1][ k + 1][i];
70+
y = ans[i + 1][k][j];
71+
cout << x << "<- x " << y << "y <- "<<endl;
72+
ans[i][k][j] = max(x, y);
73+
continue;
74+
}
75+
76+
else {
77+
ans[i][k][j] = a[inp[i]] + ans[i+1][k][j];
78+
cout << ans[i][k][j]<<endl;
79+
}
80+
81+
}
82+
83+
}
84+
85+
86+
}
87+
88+
printf("Case %d: %d\n", j, ans[0][0][0]);
89+
90+
91+
}
92+
93+
94+
}
95+
96+
97+
98+
99+
100+
101+
102+
103+

1019-Brush-5.cpp

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <stdio.h>
2+
#include <limits.h>
3+
#define INF 10000000
4+
using namespace std;
5+
int a[102][102];
6+
void setup()
7+
{
8+
9+
for (int i = 0; i < 101; i++) {
10+
for(int j = 0; j < 101; j++) {
11+
a[i][j] = INF;
12+
}
13+
14+
}
15+
}
16+
int min(int x, int y)
17+
{
18+
if(x < y) {
19+
return x;
20+
}
21+
22+
return y;
23+
}
24+
int main()
25+
{
26+
int n;
27+
int m;
28+
int x;
29+
int y;
30+
int w;
31+
int t;
32+
33+
scanf("%d", &t);
34+
35+
for(int p = 1; p <= t; p++) {
36+
setup();
37+
scanf("%d", &n);
38+
scanf("%d", &m);
39+
40+
for (int i = 0; i < m; i++) {
41+
scanf("%d", &x);
42+
scanf("%d", &y);
43+
scanf("%d", &w);
44+
45+
a[x][y] = min(w, a[x][y]);
46+
}
47+
48+
for (int k = 1; k <= n; k++) {
49+
for(int i = 0; i <= n; i++) {
50+
for (int j = 0; j <=n; j++) {
51+
if(a[i][j] > a[i][k] + a[k][j]) {
52+
a[i][j] = a[i][k] + a[k][j];
53+
}
54+
55+
}
56+
57+
}
58+
59+
}
60+
61+
if(a[1][n] != INF) {
62+
printf("Case %d: %d\n",p, a[1][n]);
63+
}
64+
65+
else {
66+
printf("Case %d: Impossible\n", p);
67+
}
68+
69+
}
70+
71+
72+
}
73+
74+
75+
76+
77+

1020-A-Childhood-Game.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <iostream>
2+
#include <stdio.h>
3+
#include <string.h>
4+
using namespace std;
5+
6+
int main()
7+
{
8+
9+
int t;
10+
long long n;
11+
char x[6];
12+
13+
scanf("%d", &t);
14+
15+
for (int j = 1; j <= t; j++) {
16+
scanf("%lld", &n);
17+
scanf("%s", x);
18+
19+
n = n % 3;
20+
if(strcmp(x, "Alice") == 0) {
21+
if(n == 0 or n == 2) {
22+
printf("Case %d: Alice\n", j);
23+
}
24+
25+
else {
26+
printf("Case %d: Bob\n", j);
27+
}
28+
29+
}
30+
31+
else
32+
{
33+
if(n == 1 or n == 2) {
34+
printf("Case %d: Bob\n", j);
35+
}
36+
37+
else {
38+
printf("Case %d: Alice\n", j);
39+
40+
}
41+
42+
}
43+
44+
45+
}
46+
47+
48+
49+
}
50+
51+
52+

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ This is also a normal Ad-Hoc problem. The simplified task is to find the divisor
4242

4343
###1016 - Brush II
4444
This is yet another adhoc problem. What you need to do is to ietrate over all the y points in ascending order in such a way that you increase the counter only when the difference of ym, ym+1, ....yn becomes greater than w. The counter would give you the answer.
45+
46+
###1019 - Brush IV
47+
This is a trivial application of Shortest Path algorithms. Implementing Floyd Warshal solution for this can accept the solution in a few lines of code
48+
49+
###1020 - A Childhood game
50+
This is a problem under Game theory. You can write the solution for this problem by just observing the pattern of win or loss. If Alice is taking the stone first she will get a win for 0, 2, 3, 5 .... and loss for 1, 4, 7 .... You can easily use this observation for solving the problem.

0 commit comments

Comments
 (0)