[hackerrank]Manasa and Stones

https://www.hackerrank.com/contests/w2/challenges/manasa-and-stones

简单题。

#include<iostream>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n, a, b;
        cin >> n >> a >> b;
        // a < b
        if ( a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        int last = 0;
        for (int i = 0; i < n; i++) {
            int x = i * b + (n - i - 1) * a;
            if (x != last) {
                last = x;
                cout << x << " ";
            }
        }
        cout << endl;
    }
    return 0;
}

  

posted @ 2014-08-15 20:22  阿牧遥  阅读(179)  评论(0编辑  收藏  举报