题目链接: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:

  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5. typedef long long LL;
  6. const int MAXN = ;
  7.  
  8. struct node {
  9. LL n;
  10. LL m;
  11. };
  12.  
  13. node ans[MAXN];
  14.  
  15. bool cmp(node a, node b)
  16. {
  17. return a.n < b.n;
  18. }
  19.  
  20. int main()
  21. {
  22. LL x;
  23. while (cin >> x) {
  24. int k = ;
  25. LL t = ;
  26. LL p = (LL)sqrt(x);
  27. while (true) {
  28. if (t > || t > p) break;
  29. LL a = *x - t + t*t*t;
  30. LL b = *t*(t+);
  31. if (a%b == && t<=a/b) {
  32. ans[k].n = t;
  33. ans[k++].m = a/b;
  34. }
  35. ++t;
  36. }
  37. int L = k;
  38. for (int i = k-; i >= ; --i) {
  39. if (ans[i].m == ans[i].n) continue;
  40. ans[L].n = ans[i].m;
  41. ans[L++].m = ans[i].n;
  42. }
  43. sort(ans, ans + L, cmp);
  44. cout << L << endl;
  45. for (int i = ; i < L; ++i) {
  46. cout << ans[i].n << " " << ans[i].m << endl;
  47. }
  48. }
  49. return ;
  50. }

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. 使用Cloudsim实现基于多维QoS的资源调度算法之中的一个:配置Cloudsim环境

    Cloudsim是一款开源的云计算仿真软件,它继承了网格计算仿真软件Gridsim的编程模型,支持云计算的研究和开发.它是一个自足的支持数据中心.服务代理人.调度和分配策略的平台,支持大型云计算的基础 ...

  2. oracle 命令创建用户 、授权、数据库导入、导出

    最近在使用oracle,经常要导入导出数据,命令很简单,却经常忘记,所以记下来.. drop user yfplss cascade;--登录system用户删除已存在的用户名,该用户下的所有东西都被 ...

  3. 动画原理——脉动(膨胀缩小)&&无规则运动

    书籍名称:HTML5-Animation-with-JavaScript 书籍源码:https://github.com/lamberta/html5-animation 1.脉动是一种半径r来回反复 ...

  4. Adroid: getExternalStorageDirectory 不一定是你想要的外部存储SdCard

    前情提要:我的测试机是华为荣耀6,我装过一个16G的内存卡 因为要面试的需要,我的一个演示项目用的是android本地的WebService.然而写好的webService部署到本地上,应用怎么获取数 ...

  5. 获取iOS应用的版本号和app名称

    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary]; NSString* versionNum =[infoDict obje ...

  6. mysql-5.7.10-winx64 MySQL服务无法启动,服务没有报告任何错误的解决办法

      总结报错原因:在my.init文件下新增data目录(datadir = F:\mysqldata ) 最新解压版本的mysql 解压安装的时候报错D:\mysql\mysql-5.7.10-wi ...

  7. C++ 获取UUID

    #include <string> #include <stdio.h> #if defined(WIN32)||defined(WINCE)||defined(WIN64) ...

  8. 超快速使用docker在本地搭建hadoop分布式集群

    超快速使用docker在本地搭建hadoop分布式集群 超快速使用docker在本地搭建hadoop分布式集群 学习hadoop集群环境搭建是hadoop入门的必经之路.搭建分布式集群通常有两个办法: ...

  9. CSS3盒模型display:-webkit-box;的使用

    box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典的一个布局应用就是布局的垂直等高.水平均分.按比例划分. 目前box-flex属性还没有得到 ...

  10. C#BASE64 UTF8字符串加密解密

    base 64 解码 base64 bb = new base64(); string orgStr= Encoding.Default.GetString(bb.GetDecoded("b ...