http://codeforces.com/problemset/problem/599/D

题目大意:给你一个数k  让你求一个n*m的矩形里面包含k个正方形   输出有几个这样的矩形  分别是什么

可以推出一个数学公式

我们枚举i*i的正方形  这个正方形里面的包含的正方形是有(i*i)+(i-1) *( i-1)+(i-2)*(i-2)+...+(1*1)   就等于b=i*(i-1)*(2*i-1)/6;

如果k>b  说明这个正方形里面的正方形是不够的  我们需要再添加n个(1*i)的列

如果添加一列能增加的小正方形是(从0加到i)i*(i+1)/2

所以如果说(k-b)%(i*(i+1)/2)==0   说明正好有(k-b)/(i*(i+1)/2)这么多列   然后就保存下来就行了

i最多也就2000000的样子   可以直接暴力

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <math.h>
#include <ctype.h> using namespace std;
#define memset(a,b) memset(a,b,sizeof(a))
#define N 5001000
typedef long long ll;
const double ESP = 1e-;
#define INF 0xfffffff struct node
{
ll x,y;
}a[N]; int main()
{
ll k;
while(scanf("%lld",&k)!=EOF)
{ ll sum=;
ll i;
int flag=;
ll p=(ll)sqrt(k);
for(i=;;i++)
{
if(i> || i>p)
break;
ll b=(i*(i+)*(*i+)/);
ll c=i*(i+)/;
if(k>=b&&(k-b)%c==)
{
a[sum].x=i;
a[sum++].y=(k-b)/c+i;
}
}
if(a[sum-].y==a[sum-].x && a[sum-].x==a[sum-].y)
{
printf("%lld\n",(sum-)*);
for(i=;i<sum;i++)
printf("%lld %lld\n",a[i].x,a[i].y);
for(i=sum-;i>=;i--)
printf("%lld %lld\n",a[i].y,a[i].x);
}
else
{
if(a[sum-].x==a[sum-].y)
{
printf("%d\n",sum*-);
for(i=;i<sum-;i++)
printf("%lld %lld\n",a[i].x,a[i].y);
for(i=sum-;i>=;i--)
printf("%lld %lld\n",a[i].y,a[i].x);
}
else
{
printf("%lld\n",sum*);
for(i=;i<sum;i++)
printf("%lld %lld\n",a[i].x,a[i].y);
for(i=sum-;i>=;i--)
printf("%lld %lld\n",a[i].y,a[i].x);
}
}
}
return ;
}

D. Spongebob and Squares--cf599D(数学)的更多相关文章

  1. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

  2. CF 599D Spongebob and Squares(数学)

    题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x ...

  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 Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举

    D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  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. 【27.40%】【codeforces 599D】Spongebob and Squares

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. NYOJ 141 Squares (数学)

    题目链接 描述 A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degre ...

  9. Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

    http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...

  10. codeforces 599D Spongebob and Squares

    很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...

随机推荐

  1. zabbix显示中文

  2. oss图片上传失败

    在生产上跑的正常代码,新搭了个测试环境,发现oss上传失败! 开始分析oss是否有以各种类似于白名单的功能,不认识测试域名导致的...结果不是! 改变访问类型 因为oss节点Endpoint是在杭州, ...

  3. ML-学习提纲1

    http://www.sohu.com/a/130379077_468714 本文用一系列「思维导图」由浅入深的总结了「统计学」领域的基础知识,是对之前系列文章做的一次完整的梳理,也是我至今为止所有与 ...

  4. 使用python书写的小说爬虫

    1.写了一个简单的网络爬虫 初期1 (后期将会继续完善) #小说的爬取 import requests import random from bs4 import BeautifulSoup base ...

  5. chart 图片组件 生成后不能动态更新,需要销毁dom,从新载入 用 v-if 和 this.$nextTick(() => {

    <chart-box v-if="cbData1Bool" cb-text="基本概况" chartBoxSele="饼状图" :cb ...

  6. html自动刷新

    头部<meta http-equiv="refresh" content="10"> 或者js实现 <script language=&quo ...

  7. web中的$多种意思

    $符号在php中是表示变量的特征字符, 在js中它也有很多作用, 一般我们用来命名一个函数名称,获取id的1.首先可以用来表示变量, 比如变量 var s='asdsd'或var $s='asdasd ...

  8. jQuery闪烁提示,让新消息在网页标题显示

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head& ...

  9. 什么是PHP中的heredoc和nowdoc

    heredoc结构类似于双引号字符串,nowdoc结构是类似于单引号字符串的.nowdoc结构很像heredoc结构,但是 nowdoc不进行解析操作. 这种结构很适合用在不需要进行转义的PHP代码和 ...

  10. K8S部署

    k8S部署 柯穴上网 安装openvpn来获取docker镜像(不是本文重点不做详述) 软件包安装 1 关闭iptables,禁用firewalld,关闭selinux 2 配置yum仓库(使用阿里云 ...