P8589 『JROI-8』对了,还有花,少女,银河

思路

找规律,所有的合法答案都是\((k\times ^"0110^") + ^"0^"\)
注意不要用\(string\)存否则会\(TLE\)的。。。

代码

#include <iostream>
using namespace std;
int n;
int main () {
	cin >> n;
	if (n % 4 == 1) {
        for (int i = 1;i <= n / 4;i++) cout << "0110";
        cout << 0 << endl;
	}
	else puts ("-1");
	return 0;
}

比赛60分代码

#include <iostream>
using namespace std;
int n;
int main () {
	cin >> n;
	if (n % 4 == 1) {
		string s = "0",t = "0110";
		for (int i = 1;i <= n / 4;i++) s = t + s;
		cout << s << endl;
	}
	else puts ("-1");
	return 0;
}
posted @ 2022-10-23 15:10  incra  阅读(95)  评论(0)    收藏  举报