题目请点我

题解:

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

可是后来竟超时了。检查后发现是map的问题,本想利用map实现常数级的查找。可是显然map内部不是这种。所以对于普通的数据类型。数据量不大(250^2+250^2)的情况下还是利用数组标记查找好一点,get。

代码实现:

/*
ID: eashion
LANG: C++
TASK: ariprog
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <algorithm>
#define MAX 125000 using namespace std; int N,M;
bool flag;
int num[MAX];
int mm[MAX];
bool test(int start,int len);
int main()
{
freopen("ariprog.in","r",stdin);
freopen("ariprog.out","w",stdout);
while( scanf("%d%d",&N,&M) != EOF ){
int pos = 0;
flag = false;
memset(mm,0,sizeof(mm));
for( int i = 0; i <= M; i++ ){
for( int j = 0; j <= M; j++ ){
int tmp = i*i+j*j;
if( mm[tmp] != 1 ){
num[pos] = tmp;
mm[tmp] = 1;
pos++;
}
}
}
sort(num,num+pos);
int up_B = (num[pos-1]-num[0])/(N-1);
for( int i = 1; i <= up_B; i++ ){
for( int j = 0; j < pos; j++ ){
if( test(num[j],i) ){
flag = true;
printf("%d %d\n",num[j],i);
}
if( num[j]+(N-1)*i > num[pos-1] ){
break;
}
}
}
if( flag == false ){
printf("NONE\n");
}
}
return 0;
} bool test(int start,int len){
int tmp = start;
for( int i = 0; i < N; i++ ){
if( mm[tmp] != 1 ){
return false;
}
tmp += len;
}
return true;
}

USACO Arithmetic Progressions(暴力)的更多相关文章

  1. USACO Arithmetic Progressions 【构造等差数列】

    USER: Jeremy Wu [wushuai2] TASK: ariprog LANG: C++ Compiling... Compile: OK Executing... Test 1: TES ...

  2. USACO 1.4 Arithmetic Progressions

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

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

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

  4. E - Two Arithmetic Progressions(CodeForces - 710D)(拓展中国剩余定理)

    You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such ...

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

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

  6. 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 ...

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

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

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

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

  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. J-Link Version

    "J-Link / Flasher Portable V1 " "J-Link ARM / Flasher ARM V2 " "J-Link ARM ...

  2. javaDoc 注释规范

    Javadoc虽然是Sun公司为Java文档自动生成设计的,可以从程序源代码中抽取类.方法.成员等注释形成一个和源代码配套的API帮助文档.但是Javadoc的注释也符合C的注释格式,而且doxyen ...

  3. [Go] 反射 - reflect.ValueOf()

    类型 和 接口 由于反射是基于类型系统(type system)的,所以先简单了解一下类型系统. 首先 Golang 是一种静态类型的语言,在编译时每一个变量都有一个类型对应,例如:int, floa ...

  4. 记录Linux启动流程的工具bootchart

    /*********************************************************************  * Author  : Samson  * Date   ...

  5. DNS服务器

    DNS服务器是指“域名解析服务器”,而域名就是我们通常所说的“网址”.在互联网中识别和寻找不同的计算机,实际上是需要知道该计算机的IP地址才能进行访问.比如220.181.38.4,这个IP就是百度的 ...

  6. Xamarin.iOS,AOT,JIT,Limitations

    Since applications on the iPhone using Xamarin.iOS are compiled to static code, it is not possible t ...

  7. 使用Axure RP原型设计实践01,使用概述

    首先认识Axure RP Pro 7.0软件的默认界面布局.最上面的是工具栏区域,左侧上方的是网站地图区域(sitemap),左侧中部的是部件区域(Widgets),左侧下方的是模板区域(Master ...

  8. spring-boot项目在eclipse中指定配置文件启动

    原文:https://blog.csdn.net/ztx114/article/details/80076339 如下图我的项目有三个配置文件,假如我向指定用application-test.yml启 ...

  9. spring 4.1.4 发布

    Spring 框架今天发布了三个更新版本,分别是 4.1.4.4.0.9 和 3.2.13 版本. 这三个版本都是新年的维护版本,修复了各种小 bug,小改进等. via spring blog De ...

  10. 部署包含水晶报表Crystal Reports 的VS.NET2005应用程序[原创]

    要部署包含水晶报表Crystal Reports 的应用程序,您需要在生成解决方案之前创建一个安装项目,并且向应用程序中添加必要的合并模块. 1.打开 VS.NET2005 编程IDE. 2.在解决方 ...