poj 3705 Reverse

poj 3705 Reverse,第1张

poj 3705 Reverse
#include <iostream>using namespace std;void solve(int n) {    int x = (n+1)/2 - 1;    int y = n;    for (int i = 0; i < x; ++i) {        cout << n/2 << " " << 2 << " " << y-2-i << endl;        n -= 2;    }    cout <<"2 " << x << " " << x + 1 << endl;}int main() {    int n;    cin >> n;    if (n == 1) {        cout << 0 <<endl;        return 0;    }    if (n == 2) {        cout << "1" <<endl;        cout << "1 1 1" <<endl;        return 0;    }    if (n % 2 != 0) {        cout << (n+1)/2 <<endl;         solve(n);    }    else {        cout << n/2 + 1 << endl;        solve(n-1);        cout << 1 << " "<< n-1 <<" 1" <<endl;    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4895316.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存