题目链接:http://codeforces.com/problemset/problem/599/D

题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个、2x2的方阵有8个、1X1的方阵有15个,所以F(3,5)=3+8+15=26。现在告诉你F(a,b)=x中的x,要你求出所有满足要求的a,b,并按a递增的顺序输出。

思路:找出n行m列的矩阵中方阵数量的表达式即可,有些小细节需要注意。。。

code:

 #include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = ; struct node {
LL n;
LL m;
}; node ans[MAXN]; bool cmp(node a, node b)
{
return a.n < b.n;
} int main()
{
LL x;
while (cin >> x) {
int k = ;
LL t = ;
LL p = (LL)sqrt(x);
while (true) {
if (t > || t > p) break;
LL a = *x - t + t*t*t;
LL b = *t*(t+);
if (a%b == && t<=a/b) {
ans[k].n = t;
ans[k++].m = a/b;
}
++t;
}
int L = k;
for (int i = k-; i >= ; --i) {
if (ans[i].m == ans[i].n) continue;
ans[L].n = ans[i].m;
ans[L++].m = ans[i].n;
}
sort(ans, ans + L, cmp);
cout << L << endl;
for (int i = ; i < L; ++i) {
cout << ans[i].n << " " << ans[i].m << endl;
}
}
return ;
}

CF 599D Spongebob and Squares(数学)的更多相关文章

  1. [cf 599D] Spongebob and Squares

    据题意: $K=\sum\limits_{i=0}^{n-1}(n-i)*(m-i)$ $K=n^2m-(n+m)\sum{i}+\sum{i^2}$ 展开化简 $m=(6k-n+n^3)/(3n^2 ...

  2. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

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

    D. Spongebob and Squares   Spongebob is already tired trying to reason his weird actions and calcula ...

  4. codeforces 599D Spongebob and Squares

    很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...

  5. Codeforces 599D:Spongebob and Squares

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

  6. codeforces #332 div 2 D. Spongebob and Squares

    http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...

  7. Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举

    D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  8. 【27.40%】【codeforces 599D】Spongebob and Squares

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. CF 990A. Commentary Boxes【数学/模拟】

    [链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...

随机推荐

  1. ASP.NET MVC 中将FormCollection与实体间转换方法【转】

    将Action动作中传递的FormCollection转变成对应的实体,可以使用Controller的TryUpdateModel()方法. 示例如下: [HttpPost] public Actio ...

  2. python代码中pass的用法

    我们有时会在方法中写一些注释代码,用来提示这个方法是干嘛的之类,看下面代码: class Game_object: def __init__(self, name): self.name = name ...

  3. C语言中的回调函数

    C语言中通过函数指针实现回调函数(Callback Function) ====== 首先使用typedef定义回调函数类型 ======  typedef void (*event_cb_t)(co ...

  4. .net通用权限框架B/S (五)--WEB(1)首页

    通用权限框架--web 首页 1.首页截图 2.首页views 布局分为三部分top,left,main 引入easyui和jquery的js以及相关的css 使用easyui进行布局,分区代码bod ...

  5. Nutch的发展历程

    Nutch的创始人是Doug Cutting,他同时也是Lucene.Hadoop和Avro开源项目的创始人 下面是Nutch的发展历程: 月由Doug Cutting发起,托管于Sourceforg ...

  6. VB.NET函数——数学函数/字母串函数

    一.数学函数 函数 说明 Abs (num) 取绝对值. Exp (num) 返回以e为底.以num为指数的值,如Exp(2)返回e^2值. Log (num) 返回参数num的自然对数值,为Doub ...

  7. Mysql Cluster 集群 windows版本

    VM1:192.168.220.102 管理节点(MGM) VM2:192.168.220.103 数据节点(NDBD1),SQL节点(SQL1) VM3:192.168.220.104 数据节点(N ...

  8. U盘安装ubuntu14.10时出现的gfxboot.c32:not a COM32R image问题

    最近ubuntu14.10出来了,因为从ubuntu14.04升级不是很成功,于是就重新下载了14.10的系统镜像(苦逼的无线啊).于是我按照以往的方式用软碟通将镜像解压到U盘里,重启系统,却出现了g ...

  9. hdu 4635 Strongly connected 强连通

    题目链接 给一个有向图, 问你最多可以加多少条边, 使得加完边后的图不是一个强连通图. 只做过加多少条边变成强连通的, 一下子就懵逼了 我们可以反过来想. 最后的图不是强连通, 那么我们一定可以将它分 ...

  10. Visual Studio 2008中控制台程序一闪而过的解决方法

    VS2008中编写C/C++的程序时,调试运行,控制台窗口会在执行完毕后立即关闭,这样就无法看到运行的结果.为了解决这个问题,可以使用①system("pause"); ②getc ...