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 ...
随机推荐
- 堆排序(java实现)
public class Test04 { static int a[] = {9,8,7,6,5,4,3,2,1,11,12,10,19,18,17,16}; public static void ...
- jQuery validate入门
<html> <head> <meta charset="utf8"></meta> </head> <body& ...
- C# 读书笔记之继承与多态
1.1继承与多态的基本概念 1.1.1 继承和多态 继承是面向对象程序设计的主要特征之一,允许重用现有类(基类,亦称超类.父类)去创建新类(子类,亦称派生类)的过程.子类将获取基类的所有非私有数据和行 ...
- net-snmp启用python模块
1. http://blog.jeoygin.org/2011/09/centos-5-install-python-2-6-and-python-setuptools-2-6.html 2. htt ...
- ISO/IEC 14443协议浅谈
一. 非接触IC卡简介 非接触IC卡又称射频卡,是射频识别技术和IC卡技术有机结合的产物.它解决了无源(卡中无电源)和免接触这一难题,具有更加方便.快捷的特点,广泛用于电子支付.通道控制.公交收费.停 ...
- 初次接触VC++载入自己定义LIB 即静态链接
分为两部分 第一部分 LIBproject 用来生成LIB文件 #ifndef _myfun #define _myfun int myfun(int x,int y) { return x+y; ...
- windows 2008 远程端口3389修改小记
修改远程端口使服务器更加安全,win2008上大致与win2003的配置差不多,有些细微的差别,在此小记一下. 简要步骤: 1.打开远程连接功能(默认都是已经打开的) :开始>计算机>属性 ...
- asp.net中 服务器控件中onselectedindexchanged 没有反应的解决方案
最近发现项目中一个BUG就是 DropDownList 中的onselectedindexchanged 没有反应 AutoPostBack="true"和页面中的<%@ P ...
- Aspx 页面生命周期
ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤.这些步骤包括初始化.实例化控件.还原和维护状态.运行事件处理程序代码以及进行 呈现.了解页的生命周期非常重要,这样就 ...
- 【转】KVM/Installation
[转]KVM/Installation Installation Pre-installation checklist Check that your CPU supports hardware vi ...