记录编号 |
110518 |
评测结果 |
AAAAAAAA |
题目名称 |
等差数列 |
最终得分 |
100 |
用户昵称 |
752199526 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
3.774 s |
提交时间 |
2014-07-11 17:52:49 |
内存使用 |
1.43 MiB |
显示代码纯文本
- #include<iostream>
- #include<fstream>
- #include<iomanip>
- #include<cstdio>
- #include<cmath>
- #include<cstring>
- #include<cctype>
- #include<vector>
- #include<queue>
- #include<deque>
- #include<stack>
- #include<cassert>
- #include<algorithm>
- #include<functional>
- #include<ctime>
- using namespace std;
- ifstream fin("ariprog.in");
- ofstream fout("ariprog.out");
- class T
- {
- public:
- int a,b;
- }t[130000]={0,0};
- bool compare(class T A,class T B)
- {
- if(A.b<B.b||(A.b==B.b&&A.a<B.a))return 1;
- return 0;
- }
- bool square[130000]={false},ok=false,mark=true;
- int N,M,k=0,p,q;
- int main()
- {
- //Init
- fin>>N>>M;
- //生成双平方数列
- for(p=0;p<=M;p++)
- {
- for(q=0;q<=M;q++)square[p*p+q*q]=true;
- }
- //Search
- for(int b=1;b<=M*M;b++)//筛查次数:N*N
- {
- for(int a=0;a<=M*M;a++)
- {
- int i=0;
- for(int n=0;n<=N;n++)
- {
- if((a+n*b)>(p*p+q*q)){mark=false;break;}//超出双平方数的范围,退出
- if(square[a+n*b]==true)i++;
- else break;//严格等差数列,不可有空隙
- if(i==N){t[k].a=a;t[k].b=b;k++;ok=true;break;}//保存可行解
- }
- if(mark==false)break;
- }
- }
- sort(t,t+k,compare);//排序
- for(int i=0;i<k;i++)fout<<t[i].a<<" "<<t[i].b<<endl;//打印可行解
- if(ok==false)fout<<"NONE"<<endl;
- return 0;
- }