记录编号 110518 评测结果 AAAAAAAA
题目名称 等差数列 最终得分 100
用户昵称 Gravatar752199526 是否通过 通过
代码语言 C++ 运行时间 3.774 s
提交时间 2014-07-11 17:52:49 内存使用 1.43 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<fstream>
  3. #include<iomanip>
  4. #include<cstdio>
  5. #include<cmath>
  6. #include<cstring>
  7. #include<cctype>
  8. #include<vector>
  9. #include<queue>
  10. #include<deque>
  11. #include<stack>
  12. #include<cassert>
  13. #include<algorithm>
  14. #include<functional>
  15. #include<ctime>
  16. using namespace std;
  17. ifstream fin("ariprog.in");
  18. ofstream fout("ariprog.out");
  19. class T
  20. {
  21. public:
  22. int a,b;
  23. }t[130000]={0,0};
  24. bool compare(class T A,class T B)
  25. {
  26. if(A.b<B.b||(A.b==B.b&&A.a<B.a))return 1;
  27. return 0;
  28. }
  29. bool square[130000]={false},ok=false,mark=true;
  30. int N,M,k=0,p,q;
  31. int main()
  32. {
  33. //Init
  34. fin>>N>>M;
  35. //生成双平方数列
  36. for(p=0;p<=M;p++)
  37. {
  38. for(q=0;q<=M;q++)square[p*p+q*q]=true;
  39. }
  40. //Search
  41. for(int b=1;b<=M*M;b++)//筛查次数:N*N
  42. {
  43. for(int a=0;a<=M*M;a++)
  44. {
  45. int i=0;
  46. for(int n=0;n<=N;n++)
  47. {
  48. if((a+n*b)>(p*p+q*q)){mark=false;break;}//超出双平方数的范围,退出
  49. if(square[a+n*b]==true)i++;
  50. else break;//严格等差数列,不可有空隙
  51. if(i==N){t[k].a=a;t[k].b=b;k++;ok=true;break;}//保存可行解
  52. }
  53. if(mark==false)break;
  54. }
  55. }
  56. sort(t,t+k,compare);//排序
  57. for(int i=0;i<k;i++)fout<<t[i].a<<" "<<t[i].b<<endl;//打印可行解
  58. if(ok==false)fout<<"NONE"<<endl;
  59. return 0;
  60. }