Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <string>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <fstream>
- #include <ctime>
- using namespace std;
- #define TASK "path"
- struct item {
- double x, y;
- int type;
- };
- int main() {
- srand(time(0));
- #ifdef _DEBUG
- //freopen("debug.in", "r", stdin);
- //freopen("debug.out", "w", stdout);
- #else
- //freopen(TASK".in", "r", stdin);
- //freopen(TASK".out", "w", stdout);
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif // _DEBUG
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout.precision(6);
- ofstream fout;
- for (int i = 1; i <= 5; i++) {
- string filename = "";
- filename += (i < 10 ? '0' : char(i / 10 + '0'));
- filename += char(i % 10 + '0');
- fout.open(filename + ".tst");
- int n = rand() % 1001 + 1, m = rand() % 1001 + 1;
- fout << n << " " << m << "\n";
- vector < item > preps(n), places(m);
- for (int k = 0; k < n; k++) {
- preps[k].type = rand() % 3 + 1;
- preps[k].x = rand() % 10001;
- preps[k].y = rand() % 10001;
- fout << preps[k].type << " " << preps[k].x << " " << preps[k].y << "\n";
- }
- for (int k = 0; k < m; k++) {
- places[k].type = rand() % 3 + 1;
- places[k].x = rand() % 10001;
- places[k].y = rand() % 10001;
- fout << places[k].type << " " << places[k].x << " " << places[k].y << "\n";
- }
- fout.close();
- fout.open(filename + ".ans");
- item ans = places[0];
- double sadness, xx, yy, sans = 1e9;
- int type;
- for (int a = 0; a < m; a++) {
- sadness = 0;
- xx = places[a].x;
- yy = places[a].y;
- type = places[a].type;
- for (int b = 0; b < n; b++) {
- double tmp = sqrt((preps[b].x - xx) * (preps[b].x - xx) + (preps[b].y - yy) * (preps[b].y - yy));
- sadness += tmp * (type == preps[b].type ? 1 : 2);
- }
- if (sadness < sans || sadness == sans && (xx < ans.x || xx == ans.x && yy < ans.y)) {
- ans = places[a];
- sans = sadness;
- }
- }
- fout << ans.x << " " << ans.y;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement