快速切题 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, ...
随机推荐
- CodeForces 76A Gift - 最小生成树
The kingdom of Olympia consists of N cities and M bidirectional roads. Each road connects exactly tw ...
- SpringBoot添加自定义消息转换器
首先我们需要明白一个概念:springboot中很多配置都是使用了条件注解进行判断一个配置或者引入的类是否在容器中存在,如果存在会如何,如果不存在会如何. 也就是说,有些配置会在springboot中 ...
- MIMO雷达比幅单脉冲测角精度分析(系统工程与电子技术)
MIMO雷达比幅单脉冲测角精度分析(系统工程与电子技术)
- 从nodejs到在线商城
nodejs安装express开发框架 (开发环境:mkdir nodeshop && cd nodeshop > npm init > npm install expre ...
- $.cookie()取值设置
本文为博主原创,未经允许不得转载: 使用jquery.cookie.js中的cookie做了一个折叠式菜单栏,用cookie保存会话的值,其中的值为点击菜单栏时,即在cookie中 保存对应的值,保证 ...
- Android广播接收器里弹出对话框
不多说,直接上车... public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(fina ...
- Linux - 命令重定向
命令重定向, 就是将目前得到的数据转移到指定的地方.分为以下几种: >>>1>2>1>>2>>< 1. > 与 >>先看一 ...
- TypeScript 小记
1. 对比JavaScript TypeScript是JavaScript的超集,可编译为JavaScript,主要提供类型系统等增强代码的可读性和可维护性,适合中大型项目多人协作: TypeScri ...
- PHP消息队列之Beanstalk
Beanstalk,一个高性能.轻量级的分布式内存队列
- jsp/servlet区别
简介: JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Microsystems公司倡导.许多公司参与一起建立的一种动态 ...