快速切题 usaco ariprog
题目:给定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的更多相关文章
- USACO ariprog 暴力枚举+剪枝
/* ID:kevin_s1 PROG:ariprog LANG:C++ */ #include <iostream> #include <cstdio> #include & ...
- 快速切题sgu127. Telephone directory
127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 快速切题 sgu123. The sum
123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...
- 快速切题 sgu120. Archipelago 计算几何
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...
- 快速切题 sgu119. Magic Pairs
119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...
- 快速切题 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 ...
- 快速切题 sgu117. Counting 分解质因数
117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...
- 快速切题 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, ...
随机推荐
- Android widget
1,TextView :走马灯效果 2,EditText ,AutoCompleteText MutiAutoCompleteTextView 3,Button,ImageButton,RadioBu ...
- 理解 python 中__name__ = '__main__' 的作用
很多新手刚开始学习python的时候经常会看到python 中__name__ = \'__main__\' 这样的代码,可能很多新手一开始学习的时候都比较疑惑,python 中__name__ = ...
- 用Python为iOS和Android写跨平台的应用
首先保证安装了最新的python(当前安装的是python3.6) 一.安装Kivy :python -m pip install --upgrade pip wheel setuptools pyt ...
- ubuntu下桌面假死处理方法(非重启)
一.背景 2018/05/22,就在这一天,进入ubuntu的桌面后随便点击任何位置均无法响应,此时又不想重启,遂出此文 二.解决方案 2.1 关掉Xorg进程 2.1.1按下ctrl+alt+F1进 ...
- P3709 大爷的字符串题
题意 询问区间众数出现的次数 思路 唯有水题快人心 离散化+莫队 莫队一定要先加后减,有事会出错的 莫队维护区间众数: 维护两个数组,一个数组记录权值为x的出现次数,一个记录出现次数为x的数的个数 a ...
- C# 用Linq查询DataGridView行中的数据是否包含(各种操作)
http://blog.csdn.net/xht555/article/details/38685845 https://www.cnblogs.com/wuchao/archive/2012/12/ ...
- 初识C++继承
先是自己凭借自己在课堂上的记忆打了一遍.自然出了错误. //编译错误 #include <iostream> #include <cstdlib> using namespac ...
- 转载: 几个主流的Java连接池整理
https://www.cnblogs.com/linjian/p/4831088.html 池(Pool)技术在一定程度上可以明显优化服务器应用程序的性能,提高程序执行效率和降低系统资源开销.这里所 ...
- 直接通过OptionalAttribute, DefaultParameterValueAttribute定义缺省参数
- WZY社区
WZY社区是我自己做的一个网站,后面会详细更新,敬请关注!