当前位置:网站首页>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;
}边栏推荐
- Enterprise digital transformation: informatization and digitalization
- TechSmith Camtasia最新2022版详细功能讲解下载
- 2022茶艺师(高级)上岗证题库模拟考试平台操作
- The use and introduction of pytorch 23 hook and the implementation of plug and play dropblock based on hook
- Paddlepaddle 21 is implemented based on dropout with 4 lines of code droplock
- Flink learning 2: application scenarios
- 学习太极创客 — MQTT 第二章(三)保留消息
- 流沙画模拟器源码
- 记录unity 自带读取excel的方法和遇到的一些坑的解决办法
- STM32入门介绍
猜你喜欢

Sample development of WiFi IOT Hongmeng development kit

Mmdetection valueerror: need at least one array to concatenate solution

执念斩长河暑期规划

Learn Tai Chi Maker - mqtt (VI) esp8266 releases mqtt message

解决cherry pick提交报错问题

Record the method of reading excel provided by unity and the solution to some pits encountered

ConstraintLayout(约束布局)开发指南

【数组】剑指 Offer II 012. 左右两边子数组的和相等 | 剑指 Offer II 013. 二维子矩阵的和

Learning Tai Chi Maker - mqtt Chapter 2 (II) esp8266 QoS application

TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
随机推荐
How does the C # TCP server limit the number of connections to the same IP?
bluecms代码审计入门
TechSmith Camtasia latest 2022 detailed function explanation Download
2022年氯碱电解工艺试题及答案
【一起上水硕系列】Day 6
Yalm 100b: 100billion parameter open source large model from yandex, Russia, allowing commercial use
P5.js death planet
paddlepaddle 19 动态修改模型的最后一层
学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息
Why pass SPIF_ Sendchange flag systemparametersinfo will hang?
STM32入门介绍
Yuantou firm offer weekly record 20220627
The use and introduction of pytorch 23 hook and the implementation of plug and play dropblock based on hook
SQLite reader plug-in tests SQLite syntax
达梦数据库安装
Cs5213 HDMI to VGA (with audio) single turn scheme, cs5213 HDMI to VGA (with audio) IC
h5液体动画js特效代码
Flink学习4:flink技术栈
Parameter estimation -- Chapter 7 study report of probability theory and mathematical statistics (point estimation)
pytorch 23 hook的使用与介绍 及基于hook实现即插即用的DropBlock
https://github.com/ZouJiu1/PAT