problemscpp
A collection of my answers to algorithm problems in c++.
| 函数
pat::a::a1018 命名空间参考

1018 Public Bike Management 更多...

struct  frame
 
struct  frame_cmp
 

函数

int main (istream &cin, ostream &cout)
 
 TEST (a1018, case1)
 
 TEST (a1018, case2)
 
 TEST (a1018, case3)
 

详细描述

1018 Public Bike Management

函数说明

◆ main()

int pat::a::a1018::main ( istream &  cin,
ostream &  cout 
)

< the maximum capacity of each station

< the total number of stations

< the index of the problem station

< the number of roads

< the node number of bikes at Si respectively

在文件 pat.cpp4712 行定义.

4712 {
4713 unsigned cmax;
4714 unsigned n;
4715 unsigned sp;
4716 unsigned m;
4717 auto fc = frame_cmp();
4718 cin >> cmax >> n >> sp >> m;
4719 vector c(n + 1, 0);
4720 for(unsigned i = 1; i <= n; i++) {
4721 int ci;
4722 cin >> ci;
4723 c[i] = ci - static_cast<int>(cmax / 2);
4724 }
4725 vector<unordered_map<unsigned, unsigned>> g(n + 1);
4726 for(unsigned i = 0; i < m; i++) {
4727 unsigned si, sj, tij;
4728 cin >> si >> sj >> tij;
4729 g[si][sj] = tij;
4730 g[sj][si] = tij;
4731 }
4732 vector shortest(n + 1, -1);
4733 vector min_go(n + 1, -1);
4734 vector min_back(n + 1, -1);
4735 priority_queue<frame, vector<frame>, frame_cmp> pq;
4736 shortest[0] = 0;
4737 min_go[0] = 0;
4738 min_back[0] = 0;
4739 pq.push(frame(vector<unsigned>(1, 0), 0u, 0, 0u, 0u));
4740 while(!pq.empty()) {
4741 frame f = pq.top();
4742 pq.pop();
4743 if(f.node == sp) {
4744 cout << f.get_go() << ' ' << f.path[0];
4745 for(int i = 1; i < f.path.size(); i++) {
4746 cout << "->" << f.path[i];
4747 }
4748 cout << ' ' << f.get_back();
4749 return 0;
4750 }
4751 for(auto &[node, d]: g[f.node]) {
4752 if(find(f.path.begin(), f.path.end(), node) == f.path.end()) {
4753 //if(shortest[node] == -1 || min_go[node] == -1 || min_back[node] == -1 || fc(frame(vector<unsigned>(), node, min_back[node], shortest[node], min_go[node]), frame(vector<unsigned>(), node, f.bikes + c[node], f.len + d, f.start))) {
4754 vector<unsigned> path = f.path;
4755 path.emplace_back(node);
4756 auto next_f = frame(path, node, f.bikes + c[node], f.len + d, f.start);
4757 pq.push(next_f);
4758 //shortest[node] = next_f.len;
4759 //min_go[node] = next_f.get_go();
4760 //min_back[node] = next_f.get_back();
4761 }
4762 }
4763 }
4764 return 0;
4765 }
bool find(vector< unordered_set< int > > &g, int x, vector< bool > &st, vector< int > &match)
Definition: acwing.cpp:7522

引用了 pat::a::a1018::frame::bikes, acwing::acwing861::find(), pat::a::a1018::frame::get_back(), pat::a::a1018::frame::get_go(), pat::a::a1018::frame::len, pat::a::a1018::frame::node, pat::a::a1018::frame::path , 以及 pat::a::a1018::frame::start.

被这些函数引用 TEST().

◆ TEST() [1/3]

pat::a::a1018::TEST ( a1018  ,
case1   
)

在文件 pat_test.cpp2124 行定义.

2124 {
2125 istringstream in("10 3 3 5\n"
2126 "6 7 0\n"
2127 "0 1 1\n"
2128 "0 2 1\n"
2129 "0 3 3\n"
2130 "1 3 1\n"
2131 "2 3 1");
2132 auto out = ostringstream();
2133 main(in, out);
2134 ASSERT_EQ("3 0->2->3 0", out.str());
2135 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/3]

pat::a::a1018::TEST ( a1018  ,
case2   
)

在文件 pat_test.cpp2137 行定义.

2137 {
2138 istringstream in("10 5 5 7\n"
2139 "4 8 4 9 10\n"
2140 "0 1 1\n"
2141 "0 3 1\n"
2142 "0 5 4\n"
2143 "1 2 1\n"
2144 "3 4 1\n"
2145 "2 5 1\n"
2146 "4 5 1");
2147 auto out = ostringstream();
2148 main(in, out);
2149 ASSERT_EQ("1 0->1->2->5 8", out.str());
2150 }

引用了 main().

◆ TEST() [3/3]

pat::a::a1018::TEST ( a1018  ,
case3   
)

在文件 pat_test.cpp2152 行定义.

2152 {
2153 istringstream in("10 7 7 8\n"
2154 "2 9 3 5 9 1 0\n"
2155 "0 1 1\n"
2156 "1 2 1\n"
2157 "0 3 1\n"
2158 "3 4 1\n"
2159 "2 5 1\n"
2160 "4 5 1\n"
2161 "5 6 1\n"
2162 "6 7 1");
2163 auto out = ostringstream();
2164 main(in, out);
2165 ASSERT_EQ("4 0->1->2->5->6->7 0", out.str());
2166 }

引用了 main().