这道题用了记录一个数末尾零的板子(敲重点)!!!
再说一遍,简单博弈论就是贪心!
1 void solve() { 2 cin >> n >> m; 3 vector<int> a(n), b(n); 4 for (int i = 0; i < n; i++) cin >> a[i]; 5 int len = 0; //这组数字总共有几位,总长度 6 for (int i = 0; i < n; i++) { 7 int zhi = a[i], res = 0, shu = 0; 8 bool ok = false; 9 while (zhi) { 10 if (zhi % 10 == 0) { 11 if (ok == false) res++; //当前有几个末尾0 12 } else 13 ok = true; 14 zhi /= 10; 15 shu++; //当前数字有几位 16 } 17 len += shu; 18 b.pb(res); 19 } 20 sort(all(b)); 21 int k = b.size(); 22 int cnt = 0, shan = 0; 23 for (int i = k - 1; i >= 0; i--) { 24 if (cnt == 0) { 25 shan += b[i]; 26 cnt = 1; 27 } else 28 cnt = 0; 29 } 30 if (len - shan <= m) { 31 cout << "Anna" << endl; 32 } else 33 cout << "Sasha" << endl; 34 }code
标签:cnt,int,shan,笔记,++,len,zhi,div3 From: https://www.cnblogs.com/rw666/p/18047699