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

  1. 银行排队
更多...

struct  customer
 
struct  customer_comp_p
 

函数

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

详细描述

  1. 银行排队

函数说明

◆ main()

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

在文件 pat.cpp4517 行定义.

4517 {
4518 unsigned n;
4519 unsigned k;
4520 cin >> n >> k;
4521 unsigned next = 0;
4522 unsigned current = 0;
4523 priority_queue<unsigned, vector<unsigned>, greater<unsigned>> pq;
4524 vector<customer> customers(n);
4525 for(unsigned i = 0; i < n; i++) {
4526 string time;
4527 unsigned p;
4528 cin >> time >> p;
4529 customers[i] = customer(i, time, min(60U, p) * 60);
4530 }
4531 sort(customers.begin(), customers.end());
4532 for(unsigned i = 0; i < k; i++) {
4533 pq.push(8 * 60 * 60);
4534 }
4535 unsigned total = 0;
4536 unsigned cnt = 0;
4537 for(auto &c: customers) {
4538 unsigned t = pq.top();
4539 pq.pop();
4540 if(c.arrive_time > 17 * 60 * 60) {
4541 break;
4542 }
4543 const unsigned start_time = max(c.arrive_time, t);
4544 total += start_time - c.arrive_time;
4545 cnt++;
4546 pq.push(start_time + c.p);
4547 }
4548 cout << fixed
4549 << setprecision(1) << static_cast<double>(total) / cnt / 60;
4550 return 0;
4551 }

被这些函数引用 TEST().

◆ TEST() [1/2]

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

在文件 pat_test.cpp2098 行定义.

2098 {
2099 istringstream in("7 3\n07:55:00 16\n17:00:01 2\n07:59:59 15\n08:01:00 60\n08:00:00 30\n08:00:02 2\n08:03:00 10");
2100 auto out = ostringstream();
2101 main(in, out);
2102 ASSERT_EQ("8.2", out.str());
2103 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

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

在文件 pat_test.cpp2105 行定义.

2105 {
2106 istringstream in("2 1\n16:30:00 100\n16:40:00 10");
2107 auto out = ostringstream();
2108 main(in, out);
2109 ASSERT_EQ("25.0", out.str());
2110 }

引用了 main().