首页 > 其他 > 详细

7-7宝石合成

时间:2019-04-15 19:14:15      阅读:138      评论:0      收藏:0      [点我收藏+]
#include <iostream>
#include <cstring>
using namespace std;
int baoshi[10500]; //数组要开的大一点儿不然一直wa;
int main(){
    int t, n, a, b, i, cnt, count, k = 1;
    cin >> t;
    while (t--){
        count = 0;
        memset(baoshi, 0, sizeof(baoshi));
        cin >> n;
        for (int j = 0; j < n; j++){
            cin >> a >> b;
            baoshi[a] += b;
        }
        for (i = 1; i <= 10500; i++){   // 巧妙合成
            baoshi[i + 1] = baoshi[i + 1] + baoshi[i] / 3;  
            baoshi[i] %= 3;
            cnt = i + 1;
            while (baoshi[cnt] >= 3){。 
                baoshi[cnt + 1] = baoshi[cnt + 1] + baoshi[cnt] / 3;
                baoshi[cnt] %= 3;
                cnt++;
            }
            if (baoshi[i] != 0)
                count += baoshi[i];
        }
        cout << "Case #" << k << ":" << endl << count << endl;
        k++;
    }
    return 0;
}

 

7-7宝石合成

原文:https://www.cnblogs.com/Hk456/p/10712270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!