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 ...
随机推荐
- Oracle 经常使用命令小结
1.当前数据库中查看建表语句 select dbms_metadata.get_ddl('TABLE','表名') from dual; 2.当前数据库中查看视图创建Sql select text f ...
- 9大理由告诉你为什么应该学习HTML跟CSS
你是不是听过太多人告诉你:「人人都应该要会 coding!」都快要不耐烦了对吧? 究竟为什么身为一个行销专业者.作家.金融巨擘--,整个世界还要你学会 coding? 事实上仅仅要对 HTML.CSS ...
- 依赖注入及AOP简述(十三)——AOP应用举例(完结) .
2. AOP应用举例 在一般的应用程序开发中,有一些典型的AOP应用,使得开发者可以专注于业务逻辑本身,而不是与之完全无关的一些“方面”. l 首先就是关于前面介绍过的日志输出类 ...
- XML CDATA(Mybatis mapper and XML)
Tip:must be followed by either attribute specifications, ">" or "/>". 所有 X ...
- [springMVC]javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean
问题描述: 页面使用标签<form:form>进行提交时,出现[springMVC]javax.servlet.jsp.JspTagException: Neither BindingRe ...
- Socket 服务器和客户端通信
//服务器端package com.svse.service; import java.io.BufferedReader; import java.io.IOException; import ja ...
- js、css、html判断浏览器的各种版本
利用正则表达式来判断ie浏览器版本 判断是否IE浏览器 if (document.all) { alert("这个是ie浏览器");} 判断是否IE6浏览器 方法一:if ( /M ...
- 如何将js与HTML完全脱离
先举出一个例子: var sound='Roar!'; function myOrneryBeast(){ alert(this); this.style.color='green';//this指代 ...
- log4j.xml 为什么要使用SLF4J而不是Log4J
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SY ...
- [LeetCode][Python]17: Letter Combinations of a Phone Number
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 17: Letter Combinations of a Phone Numb ...