Измени названия переменных на случайные
- User
Измени названия переменных на случайные
- Assistant
Приведите, пожалуйста, пример кода или укажите конкретные названия переменных, чтобы я мог корректно их изменить.
- User
- Assistant
Измени названия переменных на случайные
Приведите, пожалуйста, пример кода или укажите конкретные названия переменных, чтобы я мог корректно их изменить.
Измени названия переменных на случайные #include #include #include #include #include <unordered_map> #include #include #include #include <unordered_set> #include #define ll long long //#define int long long #define debug(x) cerr << (#x) <<": "<< x<< endl; #define get_time (double)clock() / (double)(CLOCKS_PER_SEC) using namespace std; const int INF = 1e9 + 7; const int mod = 1e9 + 7; int min(int a, int b) { return (a < b) ? a : b; } int max(int a, int b) { return (a > b) ? a : b; } struct node { int to, w, id; }; struct to_pred { int u, vip, d, prox, id; }; const int N = 81; const int M = 501; int dp[N][N][2 * M]; to_pred pred[N][N][2 * M]; int a, n, m, op = 0; vector is_vip; vector<vector > gr; void make_ans() { dp[0][is_vip[0]][0] = 0; for (int d = 0; d < 2 * m; d++) { for (int u = 0; u < n; u++) { for (int vip = 0; vip <= n; vip++) { for (auto c : gr[u]) { int to = c.to, w = c.w, fl = is_vip[to], id = c.id; if (vip > 0) { int nvip = vip - 1 + fl, nd = d + 1; if (dp[to][nvip][nd] > dp[u][vip][d]) { pred[to][nvip][nd] = { u, vip, d, 1, id }; dp[to][nvip][nd] = dp[u][vip][d]; } } int nvip = vip + fl, nd = d + 1; if (nvip > n) continue; if (dp[to][nvip][nd] > dp[u][vip][d] + w) { pred[to][nvip][nd] = { u, vip, d, 0, id }; dp[to][nvip][nd] = dp[u][vip][d] + w; } } } } } } void solve() { cin >> a >> n >> m; is_vip = vector(n); for (int i = 0; i < n; i++) for (int j = 0; j <= n; j++) for (int x = 0; x <= 2 * m; x++) dp[i][j][x] = INF; gr = vector<vector >(n); for (int i = 0; i < n; i++) cin >> is_vip[i]; vector<vector > mn_to(n, vector(n, INF)), who = mn_to; int fl_st = 0; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; if (w < mn_to[u][v]) { mn_to[u][v] = w; who[u][v] = i; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (mn_to[i][j] == INF) continue; gr[i].push_back({ j, mn_to[i][j], who[i][j] }); } } make_ans();
int ans = INF, u = n - 1, cur_vip = -1, sz_p = -1;
for (int i = 0; i <= 2 * m; i++) {
for (int v = 0; v <= n; v++) {
if (dp[n - 1][v][i] < ans) {
ans = dp[n - 1][v][i];
cur_vip = v;
sz_p = i;
}
}
}
vector<pair<int, int> > out;
while (sz_p > 0) {
to_pred next = pred[u][cur_vip][sz_p];
out.push_back({ next.id, next.prox });
u = next.u;
cur_vip = next.vip;
sz_p = next.d;
}
reverse(out.begin(), out.end());
cout << ans << " " << out.size() << endl;
for (auto c : out) {
cout << c.first + 1 << " " << 1 - c.second << endl;
}
} signed main() { int t = 1; cout << fixed << setprecision(20); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //cin >> t; while (t--) { solve(); } } /* 5 1 1 2 3 1 4 1 3 1 4 2 4 */
Изменим названия переменных на случайные, сохраняя логику кода:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <unordered_set>
#include <ctime>
#define ll long long
//#define int long long
#define debug(x) cerr << (#x) <<": "<< x<< endl;
#define get_time (double)clock() / (double)(CLOCKS_PER_SEC)
using namespace std;
const int panda = 1e9 + 7;
const int fox = 1e9 + 7;
int min_elephant(int x, int y) {
return (x < y) ? x : y;
}
int max_zebra(int x, int y) {
return (x > y) ? x : y;
}
struct bamboo {
int to_city, weight, trip_id;
};
struct desert_frog {
int prev_city, is_important, day, wizard, event_id;
};
const int turtle = 81;
const int cactus = 501;
int rainfall[turtle][turtle][2 * cactus];
desert_frog history[turtle][turtle][2 * cactus];
int sand, oasis, dunes, owl = 0;
vector<int> important_cities;
vector<vector<bamboo> > routes;
void compute_path() {
rainfall[0][important_cities[0]][0] = 0;
for (int day = 0; day < 2 * dunes; day++) {
for (int city = 0; city < oasis; city++) {
for (int importance = 0; importance <= oasis; importance++) {
for (auto connection : routes[city]) {
int next_city = connection.to_city, travel_cost = connection.weight, is_important = important_cities[next_city], event = connection.trip_id;
if (importance > 0) {
int new_importance = importance - 1 + is_important, new_day = day + 1;
if (rainfall[next_city][new_importance][new_day] > rainfall[city][importance][day]) {
history[next_city][new_importance][new_day] = { city, importance, day, 1, event };
rainfall[next_city][new_importance][new_day] = rainfall[city][importance][day];
}
}
int total_importance = importance + is_important, next_day = day + 1;
if (total_importance > oasis) continue;
if (rainfall[next_city][total_importance][next_day] > rainfall[city][importance][day] + travel_cost) {
history[next_city][total_importance][next_day] = { city, importance, day, 0, event };
rainfall[next_city][total_importance][next_day] = rainfall[city][importance][day] + travel_cost;
}
}
}
}
}
}
void solve() {
cin >> sand >> oasis >> dunes;
important_cities = vector<int>(oasis);
for (int i = 0; i < oasis; i++) for (int j = 0; j <= oasis; j++) for (int x = 0; x <= 2 * dunes; x++) rainfall[i][j][x] = panda;
routes = vector<vector<bamboo> >(oasis);
for (int i = 0; i < oasis; i++) cin >> important_cities[i];
vector<vector<int> > river_to(oasis, vector<int>(oasis, panda)), person = river_to;
int flag_start = 0;
for (int i = 0; i < dunes; i++) {
int start, end, cost; cin >> start >> end >> cost; start--; end--;
if (cost < river_to[start][end]) {
river_to[start][end] = cost;
person[start][end] = i;
}
}
for (int i = 0; i < oasis; i++) {
for (int j = 0; j < oasis; j++) {
if (river_to[i][j] == panda) continue;
routes[i].push_back({ j, river_to[i][j], person[i][j] });
}
}
compute_path();
int answer = panda, final_city = oasis - 1, final_importance = -1, path_size = -1;
for (int i = 0; i <= 2 * dunes; i++) {
for (int v = 0; v <= oasis; v++) {
if (rainfall[oasis - 1][v][i] < answer) {
answer = rainfall[oasis - 1][v][i];
final_importance = v;
path_size = i;
}
}
}
vector<pair<int, int> > output;
while (path_size > 0) {
desert_frog next_stop = history[final_city][final_importance][path_size];
output.push_back({ next_stop.event_id, next_stop.wizard });
final_city = next_stop.prev_city;
final_importance = next_stop.is_important;
path_size = next_stop.day;
}
reverse(output.begin(), output.end());
cout << answer << " " << output.size() << endl;
for (auto connection : output) {
cout << connection.first + 1 << " " << 1 - connection.second << endl;
}
}
signed main() {
int test_cases = 1;
cout << fixed << setprecision(20);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//cin >> test_cases;
while (test_cases--) {
solve();
}
}
В этом примере переменные, связанные с графом, структурами, и логикой были переименованы так, чтобы отразить случайные имена, сохраняя при этом логику кода.
Not yet included in a published release.