/*
ID:kevin_s1
PROG:ariprog
LANG:C++
*/ #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <cmath> using namespace std; //gobal variable====
int doubleSqure[999999];
int table[999999];
int _index;
int M,N;
int lim; struct node{
int a;
int d; }; vector<node> result;
//================== //function==========
void init(){
memset(table,0,sizeof(table));
_index = 1;
for(int i = 0; i <= M; i++){
for(int j = 0; j <= M; j++){
int num = i * i + j * j;
if(table[num] == 0){
doubleSqure[_index++] = num;
table[num] = 1;
}
}
}
_index--;
} void deal(int x){
int num = doubleSqure[x];
for(int i = x + 1; i <= _index - N + 2; i++){
if(doubleSqure[x] + (doubleSqure[i] - doubleSqure[x])*(N - 1) > lim)
break;
<span style="white-space:pre">		</span>//剪枝。没有这一步的话会第七组数据会超时
int d = doubleSqure[i] - num;
bool flag = true;
int count = doubleSqure[i];
for(int j = 3; j <= N; j++){
count += d;
if(table[count] == 0)
flag = false;
}
if(flag){
node no;
no.a = num;
no.d = d;
result.push_back(no);
}
}
} bool cmp(const node& n1, const node& n2){
if(n1.d == n2.d)
return n1.a < n2.a;
else
return n1.d < n2.d;
} //================== int main(){
freopen("ariprog.in","r",stdin);
freopen("ariprog.out","w",stdout);
cin>>N>>M;
init();
sort(doubleSqure, doubleSqure + _index);
lim = doubleSqure[_index]; for(int i = 1; i <= _index - N + 1; i++){
deal(i);
}
sort(result.begin(), result.end(), cmp);
vector<node>::iterator iter;
if(result.size() == 0)
cout<<"NONE"<<endl;
else{
for(iter = result.begin(); iter != result.end(); iter++){
cout<<iter->a<<" "<<iter->d<<endl;
}
}
return 0;
}

USACO ariprog 暴力枚举+剪枝的更多相关文章

  1. 【poj 3080】Blue Jeans(字符串--KMP+暴力枚举+剪枝)

    题意:求n个串的字典序最小的最长公共子串. 解法:枚举第一个串的子串,与剩下的n-1个串KMP匹配,判断是否有这样的公共子串.从大长度开始枚举,找到了就break挺快的.而且KMP的作用就是匹配子串, ...

  2. POJ 2531 Network Saboteur (枚举+剪枝)

    题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大. 目前我所知道的有四种做法: 方法一:状态压缩 #include <iostream> #inc ...

  3. [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)

    Generalized Palindromic Number Time Limit: 2 Seconds      Memory Limit: 65536 KB A number that will ...

  4. 【暴力枚举&BFS】Flow Free @RMRC2017/upcexam5124

    时间限制: 1 Sec 内存限制: 128 MB 题目描述 Flow Free is a puzzle that is played on a 2D grid of cells, with some ...

  5. [POJ3612] Telephone Wire(暴力dp+剪枝)

    [POJ3612] Telephone Wire(暴力dp+剪枝) 题面 有N根电线杆,初始高度为h[i],要给相邻的两根连线.可以选择拔高其中一部分电线杆,把一根电线杆拔高\(\Delta H\)的 ...

  6. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  7. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  8. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  9. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

随机推荐

  1. loadrunner场景中按scenario和group执行的区别

    group:多个脚本之间按照独立设置模式跑,各个脚本可以单独设置虚拟用户.运行时间等 scenario:多个脚本之间按照相同的模式跑,将总的虚拟用户数按照一定的比例分配给各个脚本

  2. 在kubernetes运行一个容器案例

    1. 检查kubernetes 组件是否正常运行. [root@c720120 ~]# kubectl get cs NAME                 STATUS    MESSAGE    ...

  3. Java List转换为字符串的几种方法

    Java List转换为字符串的几种方法 import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import ...

  4. Nodejs 接收RabbitMQ消息

    参考官方地址:https://www.rabbitmq.com/tutorials/tutorial-one-javascript.html 关于C#消息发送端,请参考<c# RabbitMQ ...

  5. 2017-2018-1 20179202《Linux内核原理与分析》第四周作业

    一.跟踪分析内核的启动过程实验 : 1.启动Menuos: qemu仿真kernel: qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd ...

  6. flutter android沉浸式状态栏

    import 'package:flutter/services.dart'; import 'dart:io'; class _MyAppState extends State<MyApp&g ...

  7. BNUOJ 52509 Borrow Classroom

    最近公共祖先. 如果$A$到$1$的时间小于$B$到$C$再到$1$的时间,那么一定可以拦截. 如果上述时间相等,需要在到达$1$之前,两者相遇才可以拦截. #include<bits/stdc ...

  8. RxSwift 系列(八)

    前言 本篇文章我们将学习RxSwift中的错误处理,包括: catchErrorJustReturn catchError retry retry(_:) catchErrorJustReturn 遇 ...

  9. PHP函数声明(三)

    /** * 一.任何参数的数量 * func_get_args()//接收一个数组,数组里面包含所有参数 * func_num_args()//取得共有几个参数 * func_get_arg(整数)/ ...

  10. GC参数

    串行收集器 串行收集器(Serial),是一个相对比较老的回收器,但是它的效率在回收器中相对较好,并且比较稳定.他在进行垃圾回收的过程中,使得应用暂时被挂起,然后启用单条线程去做垃圾回收,所以在进行垃 ...