题目:给定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. Delphi XE5 for Android (七)

    Delphi XE5下,TMainMenu和TPopupMenu不可用,那么如何支持Android的菜单呢? 查看了一些资料,不得要领,只是摸索着先模拟一下吧. 首先在窗体上放置一个TPanel,在其 ...

  2. POJ 3630 Phone List(字符串前缀重复)题解

    Description Given a list of phone numbers, determine if it is consistent in the sense that no number ...

  3. 用 SwitchHosts设置hotst, 用法示例

    涉及到本地默认ip(localhost,127.0.0.1)设置关联地址时,使用XAMPP本地服务器时避免自动跳转设置的域名的一些处理方法 打开此文件,把内容修改如下 # Virtual Hosts# ...

  4. CSS3屏幕密集媒体查询

    html { font-size: 50px; } body { font-size: 24px; } @media screen and (max-width: 359px) { html { fo ...

  5. Unity3D学习笔记(十六):Animator新动画

    新动画系统: 给模型选择动画类型 普通动画:Generic 人形动画:Humanoid 建立动画控制器 - 在Project右击 - 选择Create-AnimatorContorller 将对应动画 ...

  6. UVa 10970 大块巧克力

    https://vjudge.net/problem/UVA-10970 题意: 把一个m行n列的矩形巧克力切成mn个1×1的方块,需要切几刀. 思路: 可以考虑用动态规划的方法去做,当然,最简单的是 ...

  7. spring boot 无法读取application.properties问题

    spring boot 无法读取application.properties问题 https://bbs.csdn.net/topics/392374488 Spring Boot 之注解@Compo ...

  8. MVC ---- EF的安装于卸载

    先卸载EF:Uninstall-Package EntityFramework -Force 在安装EF5.0:Install-Package EntityFramework –Version 5.0 ...

  9. Ubuntu14.04 server (amd64)修改源

    1.备份原来的源文件 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 2.修改源 sudo vi /etc/apt/sources.li ...

  10. 学霸网站之NABC

    1.Need 本次学霸系统的设计是基于学长的版本,在此基础上,我们准备进一步完善已有版块,在用户信息管理.提问.搜索.分类.评论.个性化界面.用户反馈.娱乐.积分获取等方面加入新的功能. 一.用户信息 ...