USER: Jeremy Wu [wushuai2]
TASK: ariprog
LANG: C++ Compiling...
Compile: OK Executing...
Test 1: TEST OK [0.005 secs, 11880 KB]
Test 2: TEST OK [0.008 secs, 11880 KB]
Test 3: TEST OK [0.008 secs, 11876 KB]
Test 4: TEST OK [0.014 secs, 11880 KB]
Test 5: TEST OK [0.016 secs, 11880 KB]
Test 6: TEST OK [0.065 secs, 11880 KB]
Test 7: TEST OK [0.378 secs, 11880 KB]
Test 8: TEST OK [0.818 secs, 11880 KB]
Test 9: TEST OK [0.802 secs, 11876 KB] All tests OK.

Your program ('ariprog') produced all correct answers! This is your submission #5 for this problem. Congratulations!

还是算蛮简单的一道构造题目= = 差点以为是要去搜索了...

/*
ID: wushuai2
PROG: ariprog
LANG: C++
*/
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ; int n, m;
bool status[M];
int a[M], len;
int llen; struct sc{
int a, b;
}ans[M]; bool cmp(struct sc a, struct sc b){
if(a.b == b.b) return a.a < b.a;
return a.b < b.b;
} void init(){
int i, j;
memset(a, , sizeof(a));
len = ;
memset(status, , sizeof(status));
for(i = ; i <= m; ++i){
for(j = ; j <= m; ++j){
int num = i * i + j * j;
if(status[num]) continue;
status[num] = true;
a[len++] = num;
}
}
a[len] = '\0';
llen = ;
} int main() {
ofstream fout ("ariprog.out");
ifstream fin ("ariprog.in");
int i, j, k, t, s, c, w, q;
fin >> n >> m;
init();
sort(a, a + len);
for(i = ; i < len; ++i){
int num = a[i];
for(j = ; j < len; ++j){
int cur = a[j]; //fisrt a + b
int b = cur - num;
if(b * (n - ) + num > a[len - ]) break;
if(b < ) continue;
for(k = ; k < n; ++k){
if(!status[num + k * b]){
break;
}
}
if(n == k){
ans[llen].a = num;
ans[llen++].b = b;
}
} } if(!llen){
fout << "NONE" << endl;
return ;
}
sort(ans, ans + llen, cmp);
for(i = ; i < llen; ++i){
cout << ans[i].a << ' ' << ans[i].b << endl;
fout << ans[i].a << ' ' << ans[i].b << endl;
}
fin.close();
fout.close();
return ;
}

USACO Arithmetic Progressions 【构造等差数列】的更多相关文章

  1. USACO Arithmetic Progressions(暴力)

    题目请点我 题解: 这道题的题意是找出集合里全部固定长度为N的等差数列.集合内的元素均为P^2+q^2的形式(0<=p,q<=M).时间要求5s内.本着KISS,直接暴力. 可是后来竟超时 ...

  2. 洛谷P1214 [USACO1.4]等差数列 Arithmetic Progressions

    P1214 [USACO1.4]等差数列 Arithmetic Progressions• o 156通过o 463提交• 题目提供者该用户不存在• 标签USACO• 难度普及+/提高 提交 讨论 题 ...

  3. USACO 1.4 Arithmetic Progressions

    Arithmetic Progressions An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+nb ...

  4. 等差数列Arithmetic Progressions题解(USACO1.4)

    Arithmetic Progressions USACO1.4 An arithmetic progression is a sequence of the form a, a+b, a+2b, . ...

  5. poj 3006 Dirichlet's Theorem on Arithmetic Progressions【素数问题】

    题目地址:http://poj.org/problem?id=3006 刷了好多水题,来找回状态...... Dirichlet's Theorem on Arithmetic Progression ...

  6. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  7. Dirichlet's Theorem on Arithmetic Progressions 分类: POJ 2015-06-12 21:07 7人阅读 评论(0) 收藏

    Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  8. POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)

    Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  9. (素数求解)I - Dirichlet&#39;s Theorem on Arithmetic Progressions(1.5.5)

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...

随机推荐

  1. CentOS5.4下安装codeblocks 12.11

    centos6.3下安装codeblock简单多了,这些开源的软件也都在不断进步.原来装过codeblocks10.05,忘了,这次安装又花了我半天时间,最后总算搞定. 先是安装了wxGTK-2.8. ...

  2. Object-c KVC的使用和举例

    如果我们的对象需要使用KVC,必须符合object-c的非正式协议NSKeyValueCoding.我们可以简单的来理解KVC,即所有符合KVC机制的对象都看成一个字典(NSDictionary),对 ...

  3. css 定义hr的几种样式

    <style type="text/css"> <!-- .hr0{ height:1px;border:none;border-top:1px dashed # ...

  4. 基于Visual C++2013拆解世界五百强面试题--题12-进制转换

    编程实现,把十进制数(long型)分别以二进制和十六进制形式输出,不能使用printf系列库函数. 转换成二进制,直接循环移位依次取每一位,判断1或0然后将相应字符放入字符串缓冲区中. 对于十六进制, ...

  5. HDU 1108 最小公倍数

    #include <cstdio> int gcd(int a,int b) { ) return a; else return gcd(b,a%b); } int main() { in ...

  6. TEX Quotes(字符串,水)

    TEX Quotes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9674   Accepted: 5073 Descri ...

  7. C++设计模式之状态模式(四)

    4.状态模式总结 状态模式将一个对象在不同状态下的不同行为封装在一个个状态类中,通过设置不同的状态对象能够让环境对象拥有不同的行为.而状态转换的细节对于client而言是透明的.client不直接操作 ...

  8. C#高级编程零散知识点

    1.206-实现单链表的添加和插入 207-实现单链表的其他功能和 3.209-Lambda表达式 4.301-栈的介绍和BCL中的栈 4.501-进程和线程的概念[00_12_06][2015122 ...

  9. js中的setTimeout和setInterval

    在html页面中要使用自动刷新功能时,可以是使用js中setTimeout和setInterval: 一.使用方法 setTimeout的使用setTimeout('要调用的Js方法', 调用的延迟时 ...

  10. Definitions

    Definitions and ODR Definitions are declarations that fully define the entity introduced by the decl ...