题目链接: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. Matrix(类似kruskal)

    Matrix Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  2. Oracle方向

    从毕业到现在工作已经4年了,入职前去过私企,干过外企,当前到了国企,各有各的不同,对于不同的人,有不同的适合的选择. 这几年的工作中也积累了不少知识,业务上的.技术上的,但始终觉得没有掌握一门核心,没 ...

  3. apache pk nginx pk Lighttpd

    apache: 历史: APACHE:于1994年发布,是apache软件基金会的一个开放源码的网页服务器,可以在多平台下运行,由于其多平台和安全性被广泛使用,是最流行的web服务器端软件之一:特点是 ...

  4. javascript 全选与反选

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  5. MongoDB无法启动的解决方法

    http://dmyz.org/archives/423 遇到MongoDB突然无法启动,第一反应是删除mongod.lock.这个文件在MongoDB的数据库目录下,默认是/data/db.这是最常 ...

  6. JAVA 年轻代收集器 第九节

    JAVA 年轻代收集器  第九节 继续上一章所讲的,STW即GC时候的停顿时间,他会暂停我们程序中的所有线程.如果STW所用的时间长而且次数多的话,那么我们整个系统稳定性以及可用性将大大降低. 因此我 ...

  7. PHP 提交checkbox表单时 判断复选框是否被选中

    function GetTitleImgPath(){ $titleImgPath = ""; if (isset($_POST["titlecheckbox" ...

  8. javascript 数组的常用操作函数

    join() Array.join(/* optional */ separator) 将数组转换为字符串,可带一个参数 separator (分隔符,默认为“,”). 与之相反的一个方法是:Stri ...

  9. 加载loading的ajax写法

    ajaxStart()与ajaxStop():当Ajax请求开始时,会触发ajaxStart()方法的回调函数.当Ajax请求结束时,会触发ajaxStop()方法的回调函数.这些方法都是全局的方法, ...

  10. 基本数据结构简介--ath9k网卡驱动开发总结(二)

    ath9k驱动代码主要数据结构概览. (1)在ath9k的驱动中,几乎是最顶层的数据结构是ath_softc,这个数据结构几乎随处可见.ath_softc是硬件与MAC层进行交互的中间载体,很多有用的 ...