USACO Arithmetic Progressions 【构造等差数列】
USER: Jeremy Wu [wushuai2]
TASK: ariprog
LANG: C++ Compiling...
Compile: OK Executing...
Test 1: TEST OK [0.005 secs, 11880 KB]
Test 2: TEST OK [0.008 secs, 11880 KB]
Test 3: TEST OK [0.008 secs, 11876 KB]
Test 4: TEST OK [0.014 secs, 11880 KB]
Test 5: TEST OK [0.016 secs, 11880 KB]
Test 6: TEST OK [0.065 secs, 11880 KB]
Test 7: TEST OK [0.378 secs, 11880 KB]
Test 8: TEST OK [0.818 secs, 11880 KB]
Test 9: TEST OK [0.802 secs, 11876 KB] All tests OK.
Your program ('ariprog') produced all correct answers! This is your submission #5 for this problem. Congratulations!
还是算蛮简单的一道构造题目= = 差点以为是要去搜索了...
/*
ID: wushuai2
PROG: ariprog
LANG: C++
*/
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ; int n, m;
bool status[M];
int a[M], len;
int llen; struct sc{
int a, b;
}ans[M]; bool cmp(struct sc a, struct sc b){
if(a.b == b.b) return a.a < b.a;
return a.b < b.b;
} void init(){
int i, j;
memset(a, , sizeof(a));
len = ;
memset(status, , sizeof(status));
for(i = ; i <= m; ++i){
for(j = ; j <= m; ++j){
int num = i * i + j * j;
if(status[num]) continue;
status[num] = true;
a[len++] = num;
}
}
a[len] = '\0';
llen = ;
} int main() {
ofstream fout ("ariprog.out");
ifstream fin ("ariprog.in");
int i, j, k, t, s, c, w, q;
fin >> n >> m;
init();
sort(a, a + len);
for(i = ; i < len; ++i){
int num = a[i];
for(j = ; j < len; ++j){
int cur = a[j]; //fisrt a + b
int b = cur - num;
if(b * (n - ) + num > a[len - ]) break;
if(b < ) continue;
for(k = ; k < n; ++k){
if(!status[num + k * b]){
break;
}
}
if(n == k){
ans[llen].a = num;
ans[llen++].b = b;
}
} } if(!llen){
fout << "NONE" << endl;
return ;
}
sort(ans, ans + llen, cmp);
for(i = ; i < llen; ++i){
cout << ans[i].a << ' ' << ans[i].b << endl;
fout << ans[i].a << ' ' << ans[i].b << endl;
}
fin.close();
fout.close();
return ;
}
USACO Arithmetic Progressions 【构造等差数列】的更多相关文章
- USACO Arithmetic Progressions(暴力)
题目请点我 题解: 这道题的题意是找出集合里全部固定长度为N的等差数列.集合内的元素均为P^2+q^2的形式(0<=p,q<=M).时间要求5s内.本着KISS,直接暴力. 可是后来竟超时 ...
- 洛谷P1214 [USACO1.4]等差数列 Arithmetic Progressions
P1214 [USACO1.4]等差数列 Arithmetic Progressions• o 156通过o 463提交• 题目提供者该用户不存在• 标签USACO• 难度普及+/提高 提交 讨论 题 ...
- USACO 1.4 Arithmetic Progressions
Arithmetic Progressions An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+nb ...
- 等差数列Arithmetic Progressions题解(USACO1.4)
Arithmetic Progressions USACO1.4 An arithmetic progression is a sequence of the form a, a+b, a+2b, . ...
- poj 3006 Dirichlet's Theorem on Arithmetic Progressions【素数问题】
题目地址:http://poj.org/problem?id=3006 刷了好多水题,来找回状态...... Dirichlet's Theorem on Arithmetic Progression ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- Dirichlet's Theorem on Arithmetic Progressions 分类: POJ 2015-06-12 21:07 7人阅读 评论(0) 收藏
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- (素数求解)I - Dirichlet's Theorem on Arithmetic Progressions(1.5.5)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...
随机推荐
- 【零基础学习iOS开发】【01-前言】01-开篇
本文目录 一.什么是iOS 二.主流手机操作系统 三.什么是iOS开发 四.学习iOS开发的目的 五.学习iOS开发的前提 从今天开始,我就开始更新[零基础学习iOS开发]这个专题.不管你是否涉足过I ...
- Spring 面试复习
1 singleton 和 prototype singleton作用域:当把一个Bean定义设置为singleton作用域是,Spring IoC容器中只会存在一个共享的Bean实例,并且所有对 ...
- JAVA GUI学习 - 窗口【x】按钮关闭事件触发器:重写processWindowEvent(WindowEvent e)方法
public class WindowListenerKnow extends JFrame { public WindowListenerKnow() { this.setBounds(300, 1 ...
- 带你走进EJB--MDB
在之前的文章中我们介绍了带你走进EJB--JMS 和 带你走进EJB--JMS编程模型 对JMS有了初步的了解, 作为EJB系列的文章我们会继续对EJB相关的内容做进一步深的学习和了解.而此次需要进行 ...
- software quality assurance 常见问题收录
1. What is Quality? Quality means, “meeting requirements.” ..Whether or not the product or service d ...
- SharePoint 2010 用Event Receiver将文件夹自动变成approved状态 (1)
当开发一个sharepoint门户网站,或者是一个内容管理的网站的时候,站点的模板通常会选用publish portal,或者是开启了publishing feature来对内容进行版本控制和流程控制 ...
- 查找jar包的站点
1.findJAR.com: http://www.findjar.com/index.x 2.jarfire: https://cn.jarfire.org/
- MVC设计模式JavaWeb实现
JSP开发模式 jsp开发模式的发展 1.模式1:(适合小型项目的技术的开发) a.第一版本号.纯jsp(封装数据.处理数据,显示数据) b.第二版本号,Jsp+JavaBean. ...
- java之内存可见型
1.可见性的概念 一个线程对于共享变量的修改,能够及时被其他的线程看到. 2.什么是共享变量 一个变量在多个线程中的工作内存中都存在变量副本,那么这个变量在这几个线程之间共享. 3.Java线程的工作 ...
- Java 取得当前日期之后N天的日期 zz
链接地址:http://blog.sina.com.cn/s/blog_483486840100vrjn.html public static String afterNDay(int n){ ...