题目链接: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. Android中对闹钟Alarm的事件处理

    之前的博文一直在持续分享Phone相关的知识也算是知识笔记,但在工作中难免遇到其他模块的一些问题,因此在解决这些问题的时候顺手将这些知识记录并分享出来.有些知识在不知道的时候会觉得非常难,当了解之后便 ...

  2. javascript高级知识分析——函数访问

    代码信息来自于http://ejohn.org/apps/learn/. 可以通过函数的名字在它的内部引用它. function yell(n){ return n > 0 ? yell(n-1 ...

  3. bootstrap-js(4)标签页

    实例 标签页(Tab)在 Bootstrap 导航元素 一章中介绍过.通过结合一些 data 属性,您可以轻松地创建一个标签页界面. 通过这个插件您可以把内容放置在标签页或者是胶囊式标签页甚至是下拉菜 ...

  4. oracle11g+ef+vs2013做的项目在部署的时候碰到的问题

    最近公司做一个项目,用到了ef和oracle11g,开发工具用的是vs2013,开发完成后,在本机上完美运行,但是,当到了要到服务器上部署的时候,就出了问题,服务器环境是server08R2,开发环境 ...

  5. Ant 简易教程

    转载:http://www.cnblogs.com/jingmoxukong/p/4433945.html Ant 简易教程 Apache Ant,是一个将软件编译.测试.部署等步骤联系在一起加以自动 ...

  6. Java异常分类 转载

    Java异常分类 http://blog.csdn.net/woshixuye/article/details/8230407     一.基本概念 看java的异常结构图 Throwable是所有异 ...

  7. list去重 转载

    http://blog.csdn.net/huaishuming/article/details/47778319 1. 单个List 去重: 如果用的是Set集合就不用怕重复的问题了,如果用的Lis ...

  8. poj1323--贪心算法

    题意:一群人打牌包括你,每人出一张牌,谁最大,谁就算赢一局,问你最少能赢几局? 给出人数N,每人的牌数M,及你的牌. 分析:1.这题需比较大小,就像我们打牌时要将牌排序以便出牌,显然要先将手上的牌进行 ...

  9. opcache effect

    with open opcache, the monitor cpu idle log , there are so much curl_exec and gzip in our php logic ...

  10. Java学习之Java实现CallBack功能

    回调函数实际上就是在调用某个函数(通常是API函数)时,将自己的一个函数(这个函数为回调函数)的地址作为参数传递给那个函数.而那个函数在需要的时候,利用传递的地址调用回调函数,这时你可以利用这个机会在 ...