diff --git a/1115/11780.cpp b/1115/11780.cpp new file mode 100644 index 0000000..94b2e5b --- /dev/null +++ b/1115/11780.cpp @@ -0,0 +1,71 @@ +// +// Created by LG on 2021-11-13. +// +#include +#include + +using namespace std; + +const int INF = 1e7; +typedef pair ci; + +void floydWarshall(int n, vector> &graph, vector> &table){ + for(int k=1; k<=n; k++){ + for(int i=1; i<=n; i++){ + for(int j=1; j<=n; j++){ + int dist = graph[i][k] + graph[k][j]; + if(dist < graph[i][j]){ + graph[i][j] = dist; + table[i][j] = {table[i][k].first+table[k][j].first, table[i][k].second}; + } + } + } + } +} + +int main(){ + + int n, m, a, b, c; + cin >> n >> m; + vector> graph(n+1, vector(n+1, INF)); + vector> table(n+1, vector(n+1)); + for(int i=1; i<=n; i++) + graph[i][i] = 0; + + while(m--){ + cin >> a >> b >> c; + if(graph[a][b] > c){ + graph[a][b] = c; + table[a][b] = {1, b}; + } + } + + floydWarshall(n, graph, table); + + for(int i=1; i<=n; i++){ + for(int j=1; j<=n; j++){ + if(graph[i][j] == INF) + cout << '0' << ' '; + else + cout << graph[i][j] << ' '; + } + cout << '\n'; + } + + for(int i=1; i<=n; i++){ + for(int j=1; j<=n; j++){ + if(graph[i][j] == INF || graph[i][j] == 0) + cout << '0'; + else{ + cout << table[i][j].first+1 << ' ' << i << ' '; + int t = table[i][j].second; + while(t != j){ + cout << t << ' '; + t = table[t][j].second; + } + cout << j; + } + cout << '\n'; + } + } +} diff --git a/1115/12852.cpp b/1115/12852.cpp new file mode 100644 index 0000000..6a52105 --- /dev/null +++ b/1115/12852.cpp @@ -0,0 +1,61 @@ +// +// Created by LG on 2021-11-11. +// +#include +#include + +using namespace std; + +typedef pair ci; + +int main() { + int n; + cin >> n; + vector count(n + 1, {0, 0}); + + if (n % 3 == 0) { + count[n / 3] = {1, n}; + } + if (n % 2 == 0) { + count[n / 2] = {1, n}; + } + count[n - 1] = {1, n}; + + for (int i = n - 1; i > 1; i--) { + if (count[i].first == 0) + continue; + if (i % 3 == 0) { + if (count[i / 3].first == 0) + count[i / 3] = {count[i].first + 1, i}; + else { + if (count[i / 3].first > count[i].first + 1) + count[i / 3] = {count[i].first + 1, i}; + } + } + if (i % 2 == 0) { + if (count[i / 2].first == 0) + count[i / 2] = {count[i].first + 1, i}; + else { + if (count[i / 2].first > count[i].first + 1) + count[i / 2] = {count[i].first + 1, i}; + } + } + if (count[i - 1].first == 0) + count[i - 1] = {count[i].first + 1, i}; + else { + if (count[i - 1].first > count[i].first + 1) + count[i - 1] = {count[i].first + 1, i}; + } + } + + int ans = count[1].first; + cout << ans << '\n'; + vector path(ans + 1); + path[0] = 1; + for (int i = 0; i < ans; i++) + path[i + 1] = count[path[i]].second; + + for (int i = ans; i >= 0; i--) + cout << path[i] << ' '; +} + diff --git a/1115/1719.cpp b/1115/1719.cpp new file mode 100644 index 0000000..2feea3c --- /dev/null +++ b/1115/1719.cpp @@ -0,0 +1,54 @@ +// +// Created by LG on 2021-11-13. +// +#include +#include + +using namespace std; + +const int INF = 2*1e5; + +void floydWarshall(int n, vector> graph, vector> &table){ + for(int k=1; k<=n; k++){ + for(int i=1; i<=n; i++){ + for(int j=1; j<=n; j++){ + int dist = graph[i][k] + graph[k][j]; + if(dist < graph[i][j]){ + graph[i][j] = dist; + table[i][j] = table[i][k]; + } + } + } + } +} + +int main(){ + int n, m, u, v, w; + cin >> n >> m; + vector> graph(n+1, vector(n+1, INF)); + vector> table(n+1, vector(n+1)); + for(int i=0; i> u >> v >> w; + if(graph[u][v] > w){ + graph[u][v] = w; + graph[v][u] = w; + table[u][v] = v; + table[v][u] = u; + } + } + + floydWarshall(n, graph, table); + + for(int i=1; i<=n; i++){ + for(int j=1; j<=n; j++){ + if(i==j) + cout << '-' << ' '; + else + cout << table[i][j] << ' '; + } + cout << '\n'; + } +} diff --git a/1115/2615.cpp b/1115/2615.cpp new file mode 100644 index 0000000..fd13540 --- /dev/null +++ b/1115/2615.cpp @@ -0,0 +1,92 @@ +#include +#include + +using namespace std; + +bool five(int color, int i, int j, vector> board){ + bool check = true; + for(int k = 1; k < 5; k++){ + if(j>15 || board[i][j+k] != color){ + check = false; + break; + } + } + if(check){ + if((j==1 || board[i][j-1] != color) && (j==15 || board[i][j+5] != color)) + return true; + } + + check = true; + for (int k = 1; k < 5; k++) { + if(i>15 || board[i+k][j] != color){ + check = false; + break; + } + } + if(check){ + if((i==1 || board[i-1][j] != color) && (i==15 || board[i+5][j] != color)) + return true; + } + + check = true; + for(int k = 1; k < 5; k++){ + if(i>15 || j>15 || board[i+k][j+k] != color){ + check = false; + break; + } + } + if(check){ + if((i==1 || j==1 || board[i-1][j-1] != color) && (i==15 || j==15 || board[i+5][j+5] != color)) + return true; + } + + check = true; + for(int k=1; k<5; k++){ + if(i<5 || j>15 || board[i-k][j+k] != color){ + check = false; + break; + } + } + if(check){ + if((i==1 || j==19 || board[i+1][j-1] != color) && (i==5 || j==15 || board[i-5][j+5] != color)) + return true; + } + + return false; + +} + +int main() { + + vector> board(20, vector(20)); + for(int i=1; i<20; i++){ + for(int j=1; j<20; j++){ + cin >> board[i][j]; + } + } + + bool check; + for(int i=1; i<20; i++){ + for(int j=1; j<20; j++){ + int color = board[i][j]; + if(color == 1) { + check = five(1, i, j, board); + if(check) { + cout << color << '\n' << i << ' ' << j; + return 0; + } + } + else if(color == 2){ + check = five(2, i, j, board); + if(check){ + cout << color << '\n' << i << ' ' << j; + return 0; + } + } + } + } + + cout << 0; + return 0; + +}