problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
acwing::acwing1934类 参考

AcWing 1934. 贝茜放慢脚步 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 

详细描述

AcWing 1934. 贝茜放慢脚步

在文件 acwing.h519 行定义.

成员函数说明

◆ main()

int acwing::acwing1934::main ( istream &  cin,
ostream &  cout 
)
static

在文件 acwing.cpp1481 行定义.

1481 {
1482 int n;
1483 cin >> n;
1484 auto t = vector<int>();
1485 auto d = vector<int>();
1486 for(int i = 0; i < n; i++) {
1487 char op;
1488 int x;
1489 cin >> op >> x;
1490 if(op == 'T') {
1491 t.push_back(x);
1492 } else {
1493 d.push_back(x);
1494 }
1495 }
1496 sort(t.begin(), t.end());
1497 sort(d.begin(), d.end());
1498 double current_d = 0;
1499 double current_t = 0;
1500 double decelerations = 1;
1501 auto it_d = d.begin();
1502 auto it_t = t.begin();
1503 while(true) {
1504 int next_d = 1000;
1505 if(it_d != d.end()) {
1506 next_d = *it_d;
1507 }
1508 const auto t_for_next_d = (next_d - current_d) * decelerations;//到下一个D的时间
1509 bool next_is_d = true;
1510 if(it_t != t.end()) {
1511 next_is_d = t_for_next_d < *it_t - current_t;
1512 }
1513 if(next_is_d) {
1514 //先到D
1515 current_d = next_d;
1516 ++it_d;
1517 current_t += t_for_next_d;
1518 } else if(it_t != t.end()) {
1519 //先到T
1520 current_d += (*it_t - current_t) * (1.0 / decelerations);
1521 current_t = *it_t;
1522 ++it_t;
1523 }
1524 decelerations++;
1525 if(it_d == d.end() && it_t == t.end()) {
1526 current_t += (1000 - current_d) * decelerations;
1527 break;
1528 }
1529 }
1530 cout << lround(current_t);
1531 return 0;
1532 }

被这些函数引用 acwing::TEST().


该类的文档由以下文件生成: