首页 > 其他 > 详细

HDU 7105 Power Sum

时间:2021-09-01 13:38:20      阅读:27      评论:0      收藏:0      [点我收藏+]

题目链接:HDU 7105 Power Sum

题目大意:
技术分享图片

题解:
易知\((x+1)^2-(x+2)^2-(x+3)^2+(x+4)^2=4\),所以可以令\(n\)\(4\)取模,根据余数\(0,1,2,3\)取不同的\(01\)序列,后面加上\(\frac{n}{4}\)个“\(1001\)”即可。

#include <iostream>
#include <string>
using namespace std;

int t, n;
const int ki[] = {0, 1, 4, 2};
const string ti[] = {"", "1", "0001", "01"};

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n;
        string ans = ti[n % 4];
        int k = ki[n % 4];
        while (n >= 4) {
            ans += "1001";
            k += 4;
            n -= 4;
        }
        cout << k << endl << ans << endl;
    }
    return 0;
}

HDU 7105 Power Sum

原文:https://www.cnblogs.com/IzumiSagiri/p/15203231.html

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