Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2870 | Accepted: 961 |
Description
Input
Output
Sample Input
4 1 0 0 2 1 0 2 0 3 -1 -1 1 1 2 2 2 0 1 0 2
Sample Output
400
Hint
Source
#include <map> #include <set> #include <list> #include <stack> #include <vector> #include <queue> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; double dp[110][50]; vector<pair<int, int> >pp[110]; double dist(int x1, int y1, int x2, int y2) { return sqrt((double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ); } int main() { int n; while (~scanf("%d", &n)) { int cnt, x, y; for (int i = 1; i <= n; ++i) { scanf("%d", &cnt); for (int j = 0; j < cnt; ++j) { scanf("%d%d", &x, &y); pp[i].push_back( make_pair(x, y) ); } } memset (dp, 0, sizeof(dp) ); double ans = 0x3f3f3f3f; int fc = pp[1].size(); for (int i = 0; i < fc; ++i) // 枚举第一行 { int sc = pp[2].size(); for (int p = 0; p < sc; ++p) { dp[2][p] = dist(pp[1][i].first, pp[1][i].second, pp[2][p].first, pp[2][p].second); } for (int j = 3; j <= n; ++j) { int tc = pp[j].size(); for (int k = 0; k < tc; ++k) { int ffc = pp[j - 1].size(); double mins = 0x3f3f3f3f; for (int q = 0; q < ffc; ++q) { mins = min(mins, dp[j - 1][q] + dist(pp[j - 1][q].first, pp[j - 1][q].second, pp[j][k].first, pp[j][k].second)); } dp[j][k] = mins; if (j == n) { ans = min(ans, dp[n][k] + dist(pp[n][k].first, pp[n][k].second, pp[1][i].first, pp[1][i].second)); } } } } printf("%d\n", int(ans * 100)); } return 0; }