problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing3426 命名空间参考

  1. 糖果分享游戏
更多...

函数

bool ended (vector< int > &candy)
 
int main (istream &cin, ostream &cout)
 
 TEST (acwing3426, case1)
 

详细描述

  1. 糖果分享游戏

函数说明

◆ ended()

bool acwing::acwing3426::ended ( vector< int > &  candy)

在文件 acwing408.cpp1145 行定义.

1145 {
1146 for(int i = 1; i < candy.size(); i++) {
1147 if(candy[i] != candy[i - 1]) {
1148 return false;
1149 }
1150 }
1151 return true;
1152 }

被这些函数引用 main().

◆ main()

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

在文件 acwing408.cpp1154 行定义.

1154 {
1155 int n;
1156 while(cin >> n) {
1157 if(n == 0)
1158 continue;
1159 vector<int> candy = vector<int>(n);
1160 for(int i = 0; i < n; i++) {
1161 cin >> candy[i];
1162 }
1163 int count = 0;
1164 while(!ended(candy)) {
1165 vector<int> next_candy = vector<int>(n);
1166 for(int i = 0; i < n; i++) {
1167 int next = (i + 1) % n;
1168 next_candy[next] = candy[next] / 2 + candy[i] / 2;
1169 if(next_candy[next] % 2) {
1170 next_candy[next]++;
1171 }
1172 }
1173 candy = next_candy;
1174 count++;
1175 }
1176 cout << count << ' ' << candy[0] << endl;
1177 }
1178 return 0;
1179 }
bool ended(vector< int > &candy)
Definition: acwing408.cpp:1145

引用了 ended().

被这些函数引用 TEST().

◆ TEST()

acwing::acwing3426::TEST ( acwing3426  ,
case1   
)

在文件 acwing408_test.cpp1390 行定义.

1390 {
1391 istringstream in("6\n"
1392 "36\n"
1393 "2\n"
1394 "2\n"
1395 "2\n"
1396 "2\n"
1397 "2\n"
1398 "11\n"
1399 "22\n"
1400 "20\n"
1401 "18\n"
1402 "16\n"
1403 "14\n"
1404 "12\n"
1405 "10\n"
1406 "8\n"
1407 "6\n"
1408 "4\n"
1409 "2\n"
1410 "4\n"
1411 "2\n"
1412 "4\n"
1413 "6\n"
1414 "8\n"
1415 "0");
1416 auto out = ostringstream();
1417 main(in, out);
1418 const auto ans = out.str();
1419 ASSERT_EQ("15 14\n"
1420 "17 22\n"
1421 "4 8\n",
1422 ans);
1423 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().