poj2100 Graveyard Design(尺取法)

tech2023-12-22  72

#include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<set> #include<stack> #include<map> #include<cmath> using namespace std; const int N = 10003, inf = 0x3f3f3f3f; typedef pair<int, int> PIR; typedef long long ll; vector<int>num; vector<ll>ans; int main() { ll n; cin >> n; int res = 0; ll l = 1, r = 1, sum = 1; while (l <= r && r * r <= n) { if (sum == n) { num.push_back(r - l + 1); for (ll i = l; i <= r; i++) ans.push_back(i); res++; } if (sum < n) { r++; sum += r * r; } else { sum -= l * l; l++; } } cout << res << endl; int st = 0; for (int i = 0; i < num.size(); i++) { cout << num[i]; for (int j = st; j < st + num[i]; j++) cout <<" " << ans[j]; cout << endl; st += num[i]; } return 0; }

 

最新回复(0)