题目请点我

题解:

这道题的题意是找出集合里全部固定长度为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. 对 Git 分支 master 和 origin/master 的一些认识

    首先要明确一点,对 Git 的操作是围绕 3 个大的步骤来展开的(其实几乎所有的 SCM 都是这样) 从 git 取数据(git clone) 改动代码 将改动传回 git(git push) 这 3 ...

  2. C#网络编程技术SuperSocket实战项目演练

    一.SuperSocket课程介绍 1.1.本期<C#网络编程技术SuperSocket实战项目演练>课程阿笨给大家带来三个基于SuperSocket通讯组件的实战项目演示实例: ● 基于 ...

  3. MySQL查询报错 ERROR: No query specified

    今天1网友,查询报错ERROR: No query specified,随后它发来截图. root case:查询语法错误 \G后面不能再加分号;,由于\G在功能上等同于;,假设加了分号,那么就是;; ...

  4. Unity3D实践系列11, 组件的添加和访问

    当把一个脚本附加到一个GameObject上的时候,这个GameObject就有了脚本组件. 通过GameObject的属性获取组件 比如如下: [RequireComponent(typeof(Ri ...

  5. android编译错误“OnClickListener cannot be resolved to a type”

    在android代码编译时可能会出现如下错误: 部分代码: <span style="font-size:18px;">public void onCreate(Bun ...

  6. SpringBoot中Mybatis打印sql

    原文:https://www.cnblogs.com/expiator/p/8664977.html 如果使用的是application.properties文件,加入如下配置: logging.le ...

  7. C语言控制结构

    C语言流程控制 一.流程控制结构 (1)顺序结构:按书写顺序执行每一条语句. (2)选择结构:对给定的条件进行判断,根据判断结果决定执行哪一段代码. (3)循环结构:在给定条件成立的情况下,反复执行某 ...

  8. C#编程(七十二)----------DynamicObject和ExpandoObject

    DynamicObject和ExpandoObject 1.ExpandoObject表示一个对象,该对象包含可在运行时动态添加和移除的成员.这个类和动态类型有关,这个类能做些什么? 案例: //Ex ...

  9. Work Management Service application in SharePoint 2016

    最近开始弄SharePoint 2016的Workflow,遇到问题发现没有了Work Management Service application,然后用PowerShell命令创建也不行,bing ...

  10. 管理Mysql常用指令

    知识会更新,数据库系统也一样,本文只保证对Mysql 5.7以及MariaDB 10有效. 编码篇 展示当前默认的编码和字符集 SHOW VARIABLES LIKE 'char%'; 修改服务器默认 ...