USACO Arithmetic Progressions(暴力)
题目请点我
题解:
这道题的题意是找出集合里全部固定长度为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(暴力)的更多相关文章
- USACO Arithmetic Progressions 【构造等差数列】
USER: Jeremy Wu [wushuai2] TASK: ariprog LANG: C++ Compiling... Compile: OK Executing... Test 1: TES ...
- USACO 1.4 Arithmetic Progressions
Arithmetic Progressions An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+nb ...
- 洛谷P1214 [USACO1.4]等差数列 Arithmetic Progressions
P1214 [USACO1.4]等差数列 Arithmetic Progressions• o 156通过o 463提交• 题目提供者该用户不存在• 标签USACO• 难度普及+/提高 提交 讨论 题 ...
- E - Two Arithmetic Progressions(CodeForces - 710D)(拓展中国剩余定理)
You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- 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 ...
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- poj 3006 Dirichlet's Theorem on Arithmetic Progressions【素数问题】
题目地址:http://poj.org/problem?id=3006 刷了好多水题,来找回状态...... Dirichlet's Theorem on Arithmetic Progression ...
- (素数求解)I - Dirichlet's Theorem on Arithmetic Progressions(1.5.5)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...
随机推荐
- Android app开发中用户协议(使用条款)文字自己主动换行
用户协议(使用条款)文字自己主动换行处理 转载请注明出处:http://blog.csdn.net/u012301841/article/details/46648821 我们在开发app的时候.常常 ...
- 【Go命令教程】命令汇总
[Go命令教程]1. 标准命令详解 [Go命令教程]2. go build [Go命令教程]3. go install [Go命令教程]4. go get [Go命令教程]5. go clean [G ...
- IIS日志文件清理
如何清除IIS日志以释放空间 打开“我的电脑”发现10GB容量的C盘只剩余355MB“可用空间”,已经严重不够用.如下图: 如果服务器的管理员并没有在C盘存储大容量文件,而IIS中站点的访问量又非常大 ...
- wp使用上下文菜单
功能的实现需要toolkit中的MenuItem对象,具体实现方法有两种:XAML编程实现和.CS中代码实现: 1,XAML实现: 首先,在页面的xaml中加入引用: xmlns:toolkit=&q ...
- lua(wax框架) 适配 64位操作系统
======================使wax框架真正兼容64位系统========================== 苹果强制要求所有新提交的应用必须兼容64位,但原来使用lua的框架wax ...
- JAVA Iterator 转成 List
List转到Iterator容易,JDK本身就支持,反过来的实现方式如下:1.使用Apache Common Collections 2.自己实现的方法转换3.Guaa实现转换 方式1: #Apach ...
- 邪恶力量第一至九季/全集Supernatural迅雷下载
邪恶力量 第一季 Supernatural Season 1 (2005) 本季看点:一部充满吸引力的系列剧,超自然现象题材中的亲情与正义.迪恩(简森·阿克斯 Jensen Ackles 饰)和萨姆( ...
- WebView入门
webview是Android展示网页信息的控件,本文就来简要讲解这个控件的用法.关于webview我找到了一些很不错的文章,我就直接贴上连接,自己就不重复造轮子了.本文仅写出我本人目前使用过的东西, ...
- 简单实用UML关系图解
一句话UML,再记不住就要DPP了: 关系 图解 代码 备注 1:继承关系(Generalization) 2:实现关系(Realization) 3:依赖关系(Dependency) ...
- 对Java通配符的个人理解(以集合为例)
对Java通配符的个人理解(以集合为例) 前言:最近在学习Java,当学到了泛型的通配符时,不是很理解PECS(Producer Extends Consumer Super)原则,以及<? e ...