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. set up blog on github

    http://www.ruanyifeng.com/blog/2012/08/blogging_with_jekyll.html

  2. codeforces 622E. Ants in Leaves

    题目链接 给一棵有根树, 每个叶子节点上有一只蚂蚁. 在0时刻蚂蚁开始向上爬, 同一时刻, 除了根节点以外, 一个节点上面不能有2个蚂蚁. 问所有的蚂蚁都爬到根节点需要的最短时间. 因为除了根节点, ...

  3. [LeetCode]题解(python):123-Best Time to Buy and Sell Stock III

    题目来源: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/ 题意分析: 和上题类似,array[i]代表第i天物品 ...

  4. 什么是core dump?(转)

    什么是Core Dump? 今天调试一个程序, 用到了core dump, 于是写出来, 记于此.什么是Core Dump?Core的意思是内存, Dump的意思是扔出来, 堆出来.开 发和使用Uni ...

  5. GraphLab:新的面向机器学习的并行框架

    大规模图数据计算引起了许多知名公司的关注,微软提出了用于图数据匹配的Horton - Querying Large Distributed Graphs(Link:http://research.mi ...

  6. ASP.NET MVC进阶之路:深入理解依赖注入(DI)和控制反转(IOC)

    0X1 什么是依赖注入 依赖注入(Dependency Injection),是这样一个过程:某客户类只依赖于服务类的一个接口,而不依赖于具体服务类,所以客户类只定义一个注入点.在程序运行过程中,客户 ...

  7. js大小写锁判断

    <html> <head> <title>CapsLock Demo</title> <script src="http://ajax. ...

  8. The Longest Straight(二分,离散化)

     Problem 2216 The Longest Straight Accept: 7    Submit: 14 Time Limit: 1000 mSec    Memory Limit : 3 ...

  9. VPN连接在遇到飞鱼星设备时可能出现的疑难问题

    在连接VPN设备时,设置都是正常的.在

  10. 关于Repeater中使用DorpWownList的问题

    关于Repeater中使用DorpWownList的问题 前台: <asp:Repeater ID="Repeater1" runat="server" ...