1. 程式人生 > 實用技巧 >Callable and Future How many Callable objects are there?

Callable and Future How many Callable objects are there?

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;}
View Code

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; }
View Code