Problem A
题意:开局:1A 两种操作: 1A->xA,yA->1B,问最少多少次操作能获得kA和kB
思路:1A->xA这个操作增加了x-1 A
要获得kB,那肯定需要y* kA + k个操作
所以总共需要(y+1) * k个A,这些需要 ceiling(((y + 1) * k - 1) / (x - 1))个操作
总共 ceiling(((y + 1) * k - 1) / (x - 1)) + k个操作
#include <iostream> using namespace std; int main(){ int t; long long x, y, z; cin >> t; while(t--){ cin>>x>>y>>z; long long swap = z; auto x1 = x-1; swap += (z + (z * y) + x1-2)/x1; cout<<swap<<endl;} return 0;}
Problem B
题意:使前缀和为负的最大序号尽可能小
思路:很简单,能排序的位置按照值大优先排序
#include <iostream> #include <algorithm> using namespace std; int a[100]; bool lk[100]; int b[100]; int main() { int t, n; cin >> t; while (t--) { cin >> n; int m = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> lk[i]; if (!lk[i]) b[m++] = a[i]; } sort(b, b + m); for (int i = 0; i < n; i++) { if (!lk[i]) a[i] = b[--m]; cout << a[i] << ((i == n - 1) ? ‘\n‘ : ‘ ‘); } } return 0; }
Educational Codeforces Round 95 (Rated for Div. 2)
原文:https://www.cnblogs.com/xuesu/p/13688125.html