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 ...
随机推荐
- html系列教程--DOCTYPE a area
<!DOCTYPE>标签:<!DOCTYPE> 声明不是 HTML 标签:它是指示 web 浏览器关于页面使用哪个 HTML 版本进行编写的指令.在 HTML 4.01 中,& ...
- C#:让控件TextBox的滚动条保持在最下方
//该事件让TextBox控件的滚动条始终保持在最下方 private void TextBox_TextChanged(object sender, EventArgs e) ...
- [C++]unordered_map的使用
unordered_map和map类似,都是存储的key-value的值,可以通过key快速索引到value. 不同的是unordered_map不会根据key的大小进行排序,存储时是根据key的ha ...
- Linux学习netstat
netstat命令用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况.netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP ...
- linux chmod使用说明
chmod是用来改变一个目录的访问权限的,一般的方式是:chmod a+rwx 其中a代表全部,还有u[目录拥有者] ,g[目录拥有组],o[其他用户] r代表读,w代表写,x代表可以执行,对应数字权 ...
- python dbhelper(simple orm)
# coding:utf- import pymysql class Field(object): pass class Expr(object): def __init__(self, model, ...
- jquery的$().each,$.each的区别与应用
在jquery中,遍历对象和数组,经常会用到$().each和$.each(),两个方法.两个方法是有区别的,从而这两个方法在针对不同的操作上,显示了各自的特点. $().each,对于这个方法,在d ...
- php数组array,知道键名如何提取键值
如果是知道键值,需要查找键名,直接使用array_search()即可.现在反过来,如何操作? (1)array_walk_recursive()加自定义函数查找 $arr=array( 'n ...
- IE9下报错,错误: “JSON”未定义
今天在公司运行的代码好好的,但是拿回家里以后就报错了 结果是IE9,没有设为兼容模式,唉,微软导出都是坑啊.
- Android 使用Jsoup解析Html
想要做一个看新闻的应用,类似Cnbeta客户端的东西.大致思路如下:根据链接获取新闻列表页的html代码,然后解析,找到所有的新闻标题和新闻链接用listView显示,当点击ListView的Item ...