题目:给定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. CreateDirectory 创建文件夹 C\C++

    函数原型: CreateDirectory( LPCTSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ); 简介: CreateD ...

  2. TeeChart入门

    此链接可以作为参考http://tech.sina.com.cn/s/2008-07-07/1612722495.shtml 需要添加引用 using Steema.TeeChart;//tchart ...

  3. 【第三十二章】 elk(3)- broker架构 + 引入logback

    实际中最好用的日志框架是logback,我们现在会直接使用logback通过tcp协议向logstash-shipper输入日志数据.在上一节的基础上修改!!! 一.代码 1.pom.xml 1 &l ...

  4. 启动Sql server的服务CMD命令

    启动:net start mssqlserver 停止:net stop mssqlserver

  5. java 正则表达式验证邮箱格式是否合规 以及 正则表达式元字符

    package com.ykmimi.testtest; /** * 测试邮箱地址是否合规 * @author ukyor * */ public class EmailTest { public s ...

  6. [Err] 1111 - Invalid use of group function

    本文为博主原创,未经允许不得转载: 初衷,本想通过group by sql语句查询出不同id下总数在一定范围内的数据,所以产生如下的sql,及错误sql AND STATDATE < ' GRO ...

  7. EasyUI ---- draggable可拖动的用法

    <link href="~/Scripts/easyui1.5/themes/default/easyui.css" rel="stylesheet" / ...

  8. python 日期输出附带毫秒

    def get_time_stamp(ct): local_time = time.localtime(ct) data_head = time.strftime( time_stamp = &quo ...

  9. python 阶乘

    product= i= : product=i*product print('i=%d' %i,end='') print('\tproduct=%d' %product) i+= print('\n ...

  10. Codeforces 525A - Vitaliy and Pie

    525A - Vitaliy and Pie 思路:贪心+hashing. 代码: #include<bits/stdc++.h> using namespace std; string ...