当前位置:网站首页>PAT甲级 1018 Public Bike Management
PAT甲级 1018 Public Bike Management
2022-06-27 02:44:00 【九是否非随机的称呼】
迪杰特斯拉方式,要额外添加经过的站点数量,经过站点的单车总和等统计数组
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<bits/stdc++.h>
using namespace std;
int main(){
int C, N, Sp, M, i, j, a, b , c, d, e, cap, minnum;
cin>>C>>N>>Sp>>M;
cap = C/2;
int nowbikes[N + 1] = {0};
int waypath[N+1][N+1];
memset((void *)waypath, 9999999, sizeof(int) * (N+1) * (N+1));
for(i = 0; i < N; i++) cin>>nowbikes[i + 1];
for(i = 0; i < M; i++){
cin>>a>>b>>c;
waypath[b][a] = waypath[a][b] = c;
}
int mindis[N + 1] = {9999999};
memset((void *)mindis, 9999999, sizeof(int) * (N + 1));
int sumbike[N + 1];
int visited[N + 1] = {0};
int points[N + 1];
mindis[0] = 0;
sumbike[0] = 0;
points[0] = 0;
int vec[N + 1] = {0};
for(i = 0; i < N + 1; i++){
minnum = 9999999;
for( j = i; j < N + 1; j++){
if(mindis[j] < minnum && visited[j]==0){
minnum = mindis[j];
d = j;
}
}
visited[d] = 1;
for( j = 0; j < N + 1; j++){
if((minnum + waypath[d][j]) < mindis[j] && visited[j]==0){
mindis[j] = minnum + waypath[d][j];
vec[j] = d;
points[j] = points[d] + 1;
sumbike[j] = sumbike[d] + nowbikes[j];
}else if((minnum + waypath[d][j]) == mindis[j] && visited[j]==0){
a = (points[d] + 1) * cap;
if(a < (sumbike[d] + nowbikes[j])){
if((sumbike[d] + nowbikes[j]) < sumbike[j]){
sumbike[j] = sumbike[d] + nowbikes[j];
mindis[j] = minnum + waypath[d][j];
vec[j] = d;
points[j] = points[d] + 1;
}
}else if(a > (sumbike[d] + nowbikes[j])){
if((sumbike[d] + nowbikes[j]) > sumbike[j]){
sumbike[j] = sumbike[d] + nowbikes[j];
mindis[j] = minnum + waypath[d][j];
vec[j] = d;
points[j] = points[d] + 1;
}
}else{
sumbike[j] = sumbike[d] + nowbikes[j];
mindis[j] = minnum + waypath[d][j];
vec[j] = d;
points[j] = points[d] + 1;
}
}
}
}
a = vec[Sp];
vector<int> vr{Sp};
vr.push_back(a);
while(a!=0){
a = vec[a];
vr.push_back(a);
}
reverse(vr.begin(), vr.end());
a = sumbike[Sp];
b = points[Sp] * cap;
if(a>=b) cout<<0<<" ";
else cout<<(b-a)<<" ";
for(i = 0; i < vr.size(); i++){
cout<<vr[i];
if(i!=(vr.size() - 1)) cout<<"->";
}
if(a>=b) cout<<" "<<(a-b);
else cout<<" "<<0;
return 0;
}边栏推荐
- Questions and answers of chlor alkali electrolysis process in 2022
- Calculation of average wind direction and speed (unit vector method)
- lottie. JS creative switch button animal head
- Flink learning 4:flink technology stack
- 学习太极创客 — MQTT(七)MQTT 主题进阶
- Parameter estimation -- Chapter 7 study report of probability theory and mathematical statistics (point estimation)
- Learning Tai Chi Maker - mqtt Chapter 2 (II) esp8266 QoS application
- YaLM 100B:来自俄罗斯Yandex的1000亿参数开源大模型,允许商业用途
- 2022中式面点师(高级)复训题库及在线模拟考试
- What if asreml-r does not converge in operation?
猜你喜欢

p5.js死亡星球

记录unity 自带读取excel的方法和遇到的一些坑的解决办法

Topolvm: kubernetes local persistence scheme based on LVM, capacity aware, dynamically create PV, and easily use local disk

What if asreml-r does not converge in operation?

平均风向风速计算(单位矢量法)

Would rather go to 996 than stay at home! 24 years old, unemployed for 7 months, worse than work, no work

使用命令行安装达梦数据库

h5液体动画js特效代码

Installing the Damon database using the command line

Super detailed, 20000 word detailed explanation, thoroughly understand es!
随机推荐
剑指Offer || :栈与队列(简单)
Paddlepaddle 21 is implemented based on dropout with 4 lines of code droplock
XSS attack (note)
【微服务|Sentinel】降级规则|慢调用比例|异常比例|异常数
学习太极创客 — MQTT 第二章(三)保留消息
Geometric distribution (a discrete distribution)
[array] sword finger offer II 012 The sum of left and right subarrays is equal | sword finger offer II 013 Sum of two dimensional submatrix
Learning Tai Chi Maker - mqtt (VII) advanced mqtt theme
Learn Tai Chi maker mqtt (IX) esp8266 subscribe to and publish mqtt messages at the same time
jwt的认证流程和使用案例
1、项目准备与新建
Oracle/PLSQL: From_ Tz function
Would rather go to 996 than stay at home! 24 years old, unemployed for 7 months, worse than work, no work
P5.js death planet
使用命令行安装达梦数据库
Solve the problem of error reporting in cherry pick submission
Getting started with Scala_ Immutable list and variable list
Questions and answers of chlor alkali electrolysis process in 2022
paddlepaddle 20 指数移动平均(ExponentialMovingAverage,EMA)的实现与使用(支持静态图与动态图)
Logarithm
https://github.com/ZouJiu1/PAT