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 ...
随机推荐
- tornado模板的自动编码问题(autoescape )
tornado新版(具体版本未知)支持自动转义,比如{{ "<div>" }}不会输出html标签,而是进行转义. {{ module.test(10) }} 也会进行 ...
- appium 学习各种小功能总结--功能有《滑动图片、保存截图、验证元素是否存在、》---新手总结(大牛勿喷,新手互相交流)
1.首页滑动图片点击 /** * This Method for swipe Left * 大距离滑动 width/6 除数越大向左滑动距离也越大. * width:720 *height:1280 ...
- [C++ Basic] Const 用法
定义: const 主要用于声明常量.当常量为对象时,对象值不可改变:当常量为指针时,该指针不可移动或重新赋值,但我们可以通过它去修改该指针的指向对象的值(前提是无需移动指针的修改).所谓的形参.返回 ...
- Jedis中的一致性hash
Jedis中的一致性hash 本文仅供大家参考,不保证正确性,有问题请及时指出 一致性hash就不多说了,网上有很多说的很好的文章,这里说说Jedis中的Shard是如何使用一致性hash的,也为大家 ...
- ORACLE 使用RMAN管理归档日志 archived log
oracle 归档日志通常使用rman进行管理,作为备份集的一部分 正常情况下,可以根据方法删除 1 过期策略 crosscheck archivelog all; delete expired ar ...
- 深入理解java嵌套类和内部类
一.什么是嵌套类及内部类 能够在一个类的内部定义还有一个类.这样的类称为嵌套类(nested classes),它有两种类型:静态嵌套类和非静态嵌套类.静态嵌套类使用非常少,最重要的是非静态嵌套类,也 ...
- 专门针对初学者的Node.js教程
转载原文:http://www.csdn.net/article/2013-08-28/2816731-absolute-beginners-guide-to-nodejs Node.js的教程并不缺 ...
- 【转】KVM/Installation
[转]KVM/Installation Installation Pre-installation checklist Check that your CPU supports hardware vi ...
- Orchard 添加搜索栏
Orchard 提供索引和搜索的功能. 索引功能需要开启 Indexing 模块, 同时我们要开启Lucene 模块(做实际检索工作的东西). 然后还要开启Search模块(调用Lucene 查询然后 ...
- MySQL支持emoji
方案1: 应用层支持 MySQL默认的数据库编码是utf8,对于emoji文字是不能直接存储的,要想存储emoji,有许多库支持对emoji的转换,例如将