标签:eve 范围 first algo play cti closed follow ret
Input
Output
Sample Input
2030
Sample Output
2 4 21 22 23 24 3 25 26 27
题意:给你一个数,求连续的整数的平方和为这个整数的个数
题解:尺取
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1) #define ll long long #define mod 1000000007 using namespace std; const int N=20000+5,maxn=10000+5,inf=0x3f3f3f3f; ll ss[N],tt[N]; ll solve(ll x)//对x进行尺取 { ll ans=0,s=1,t=1,sum=0; while((t-2)*(t-2)<=x){//这里的范围一定要取好,刚开始取t<=x,结果tle了,然后取了t*t<=x,又wa了,因为t*t满足提议的时候会少算一种情况 while(sum<x&&(t-2)*(t-2)<=x){ sum+=(t*t); t++; } // cout<<sum<<endl; if(sum<x)break; if(sum==x) { ss[ans]=s; tt[ans]=t; ans++; } sum-=(s*s); s++; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,ans; cin>>n; ans=solve(n); cout<<ans<<endl; for(int i=0;i<ans;i++) { cout<<tt[i]-ss[i]; for(int j=ss[i];j<tt[i];j++) cout<<" "<<j; cout<<endl; } return 0; }
标签:eve 范围 first algo play cti closed follow ret
原文地址:http://www.cnblogs.com/acjiumeng/p/6752815.html