Codeforces 599D Spongebob and Squares(枚举 + 数学)

原创 2015年11月21日 18:56:25

@(K ACMer)


题意:给你一个数k,(k<1e18),表示矩形不同的正方形的个数,求满足k的所有矩形.


分析:求出公式,枚举实现即可.
这个题,比赛的时候错误的认知了复杂度,以为1e18必须要logn的算法才行,其实开次3根号也好的.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <string>
#include <queue>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
#define xx first
#define yy second
const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 41;
ull k;
vector<pair<ull, ull> > v;
pair<ull, ull> temp;
int main(void) {
    cin >> k;
    ull a = 1, b = 0;
    ull i = 0;
    while (++i) {
        a = i * (i + 1) / 2;
        b = b + (i - 1) * i / 2;
        temp.xx = i, temp.yy = (k + b) / a;
        if (temp.xx > temp.yy) break;
        if ((k + b) % a == 0) v.push_back(temp);
    }
    int ans = (int)v.size() * 2;
    if (v[v.size() - 1].yy == v[v.size() - 1].xx) ans--;
    cout << ans << endl;
    for (int i = 0; i < v.size(); i++) {
        cout << v[i].xx << " " << v[i].yy << endl;
    }
    for (int i = (int)v.size() - 1; i >= 0; i--) {
        if (v[i].yy == v[i].xx) continue;
        cout << v[i].yy << " " << v[i].xx << endl;
    }
    return 0;
}



版权声明:本文为博主原创文章,转载请注明作者:jibancanyang。

相关文章推荐

Codeforces 599D Spongebob and Squares【思维枚举+数学方程】

D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes ...

codeforces 599D. Spongebob and Squares【推公式+暴力枚举】

D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabyt...

Codeforces 599 D Spongebob and Squares

传送门: http://codeforces.com/problemset/problem/599/D题意: 求出所有的n和m,使得在n*m的矩形里恰有k个不同的正方形和明显的数学公式题嘛!! ...

CodeForces 599D Spongebob and Squares(DP+math)

Spongebob and Squares Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u...

【Codeforces Round 332 (Div 2)D】【数学 公式推导】Spongebob and Squares 正方形数量恰好为x个的所有大矩形

D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabyt...

Codeforces Round #332 (Div. 2) D. Spongebob and Squares

Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked y...

Codeforces Round #332 (Div. 2) D. Spongebob and Squares详解

Codeforces Round #332 (Div. 2) D. Spongebob and Squares

codeforces 599B Spongebob and Joke

B. Spongebob and Joketime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard ...

Codeforces 599 B Spongebob and Joke

传送门: http://codeforces.com/problemset/problem/599/B 题意: 给出序列f[i]和f[a[i]],要求还原序列a[i]不就是记录一下ans[f[i...

Codeforces 599B: Spongebob and Joke(技巧,规律)

B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)