题目:给定3<=n<=25,m<250,求m及以内的两两平方和能否构成为n的等差数列

1 WA 没有注意到应该按照公差-首项的顺序排序

2 MLE 尝试使用桶,但是实际上那可能是分散的,也即首项不一样

3 TLE 统计过多了,总之姿势不好

4 WA 当d=250*250*2时越界导致一直输出,实际上因为没打括号

应用时: 15min

实际用时:用了整整两天又1小时20分钟

思路: 先预处理出所有的平方和和平方和之差,对每个平方和都看看能否形成等差即可

思路误区: 因为 有重复统计的部分,因此陷入了“要把这部分除掉”的思路沼泽,而且还用桶装

/*
ID: 53543391
PROG: ariprog
LANG: C++
*/
#include <cstring>
#include <cstdio>
using namespace std;
const int maxsum=250*250*2+1;
const int maxhlen=250*250;
bool vis[maxsum];
int len[maxsum];
int use[maxhlen];
int heap[maxhlen];
int e[maxhlen];
int findd(int s,int d,int l){
for(int k=heap[s]+d;l>0&&k<maxsum;k+=d,l--){
if(!vis[k])return false;
}
return true;
}
int main(){
#define ONHOST
#ifndef ONHOST
freopen("ariprog.in","r",stdin);
freopen("ariprog.out","w",stdout);
#endif // ONHOST
int l,m;
scanf("%d%d",&l,&m);
for(int i=0;i<=m;i++){
for(int j=0;j<=i;j++){
vis[i*i+j*j]=true;
}
}
int mm=m*m*2;
int hlen=0;
int dhlen=0;
bool fl=false;
for(int i=0;i<=mm;i++){
if(vis[i]){
heap[hlen++]=i;
}
}
int limit=l>1?mm/(l-1):mm;
for(int i=0;i<hlen;i++){
for(int j=i+1;j<hlen;j++){
int d=heap[j]-heap[i];
if(d>limit)break;
if(len[d]==0)use[d]=i;
len[d]++;
}
}
for(int d=0;d<=limit;d++){
if(len[d]>l-2){
for(int i=use[d];i<hlen;i++){
if(heap[i]+l-2*d>mm)break;
if(findd(i,d,l-1)){
printf("%d %d\n",heap[i],d);
fl=true;
}
}
}
}
if(!fl)printf("NONE\n");
return 0;
}

快速切题 usaco ariprog的更多相关文章

  1. USACO ariprog 暴力枚举+剪枝

    /* ID:kevin_s1 PROG:ariprog LANG:C++ */ #include <iostream> #include <cstdio> #include & ...

  2. 快速切题sgu127. Telephone directory

    127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...

  3. 快速切题sgu126. Boxes

    126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...

  4. 快速切题 sgu123. The sum

    123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...

  5. 快速切题 sgu120. Archipelago 计算几何

    120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...

  6. 快速切题 sgu119. Magic Pairs

    119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...

  7. 快速切题 sgu118. Digital Root 秦九韶公式

    118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...

  8. 快速切题 sgu117. Counting 分解质因数

    117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...

  9. 快速切题 sgu116. Index of super-prime bfs+树思想

    116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...

随机推荐

  1. 按时间间隔生成cron表达式

    cron表达式是使用任务调度经常使用的表达式了.对于通常的简单任务,我们只需要一条cron表达式就能满足.但是有的时候任务也可以很复杂. 最近我遇到了一个问题,一条任务在开始的时候要触发A方法,在结束 ...

  2. Pycharm 2017 激活码

    Pycharm 2017 激活码 server选项里边输入:  http://idea.liyang.io 我是通过这个成功的

  3. TCP 的连接建立:采用三报文握手

  4. Linux内核同步机制--自旋锁【转】

    本文转载自:http://www.cppblog.com/aaxron/archive/2013/04/12/199386.html 自旋锁与互斥锁有点类似,只是自旋锁不会引起调用者睡眠,如果自旋锁已 ...

  5. linux内核启动参数解析及添加

    1.环境: ubuntu16.04 Linux jello 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_64 x ...

  6. SQL NULL

    表 select CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name= 'Alliance' selec ...

  7. Maven profile 打包分环境加载不同的资源文件

    在实际开发项目中,常常有几种环境,一般情况下最少有三种环境:开发.测试.正式. 各个环境之间的参数各不相同,比如mysql.等不同环境的host不一样,若每个环境都手动替换环境很容易出错,这里我们利用 ...

  8. 常见文档一览表 -httpclient

    httpclient http://www.yeetrack.com/?p=779 虫师『性能测试』文章大汇总 https://www.cnblogs.com/fnng/archive/2012/08 ...

  9. c++ primer plus 第七章 课后题答案

    #include <iostream> using namespace std; double HAR_AVG(double, double); void TEST(bool); int ...

  10. 一个很棒的Flutter学习资源列表

    目录 文章 一开始 HOWTO文档 网站/博客 高级 视频 组件 演示 UI 材料设计 图片 地图 图表 导航 验证 文字和富文本 分析.流量统计 自动构建 风格样式 媒体 音频 视频 语音 存储 获 ...