CF 599D Spongebob and Squares(数学)
题目链接: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(数学)的更多相关文章
- [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 ...
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- 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 ...
- codeforces 599D Spongebob and Squares
很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...
- Codeforces 599D:Spongebob and Squares
D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces #332 div 2 D. Spongebob and Squares
http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...
- 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/ ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CF 990A. Commentary Boxes【数学/模拟】
[链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio&g ...
随机推荐
- 使用Cloudsim实现基于多维QoS的资源调度算法之中的一个:配置Cloudsim环境
Cloudsim是一款开源的云计算仿真软件,它继承了网格计算仿真软件Gridsim的编程模型,支持云计算的研究和开发.它是一个自足的支持数据中心.服务代理人.调度和分配策略的平台,支持大型云计算的基础 ...
- oracle 命令创建用户 、授权、数据库导入、导出
最近在使用oracle,经常要导入导出数据,命令很简单,却经常忘记,所以记下来.. drop user yfplss cascade;--登录system用户删除已存在的用户名,该用户下的所有东西都被 ...
- 动画原理——脉动(膨胀缩小)&&无规则运动
书籍名称:HTML5-Animation-with-JavaScript 书籍源码:https://github.com/lamberta/html5-animation 1.脉动是一种半径r来回反复 ...
- Adroid: getExternalStorageDirectory 不一定是你想要的外部存储SdCard
前情提要:我的测试机是华为荣耀6,我装过一个16G的内存卡 因为要面试的需要,我的一个演示项目用的是android本地的WebService.然而写好的webService部署到本地上,应用怎么获取数 ...
- 获取iOS应用的版本号和app名称
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary]; NSString* versionNum =[infoDict obje ...
- mysql-5.7.10-winx64 MySQL服务无法启动,服务没有报告任何错误的解决办法
总结报错原因:在my.init文件下新增data目录(datadir = F:\mysqldata ) 最新解压版本的mysql 解压安装的时候报错D:\mysql\mysql-5.7.10-wi ...
- C++ 获取UUID
#include <string> #include <stdio.h> #if defined(WIN32)||defined(WINCE)||defined(WIN64) ...
- 超快速使用docker在本地搭建hadoop分布式集群
超快速使用docker在本地搭建hadoop分布式集群 超快速使用docker在本地搭建hadoop分布式集群 学习hadoop集群环境搭建是hadoop入门的必经之路.搭建分布式集群通常有两个办法: ...
- CSS3盒模型display:-webkit-box;的使用
box-flex是css3新添加的盒子模型属性,它的出现可以解决我们通过N多结构.css实现的布局方式.经典的一个布局应用就是布局的垂直等高.水平均分.按比例划分. 目前box-flex属性还没有得到 ...
- C#BASE64 UTF8字符串加密解密
base 64 解码 base64 bb = new base64(); string orgStr= Encoding.Default.GetString(bb.GetDecoded("b ...