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. git 初识

    现在平时用的都是SVN,感觉还是挺好用的.就是有的时候解决冲突的时候有点麻烦.但这样也是不可避免的. 今天看来下GIT,同样是版本控制,GIT的原理,和SVN还是不一样的.我个人的理解,SVN是对每个 ...

  2. 在Eclipse中通过JDBC连接MySQL步骤,非常详细!

    通过JDBC连接MySQL基本步骤代码讲解步骤可能遇到的Bug基本步骤JDBC访问MySQL 1.加载JDBC驱动器—>哪个project需要,就添加到该project的jdbc文件夹下,我的j ...

  3. uva1228 Integer Transmission

    这道题思维很灵活.也有点套路的意思. 首先规定0,1分别按照原来的顺序接收,只是01换位.这样简化了思维.(否则并不会有更优结果它.,比较好想)最大值和最小值可以贪心得到.那么接下来就是给定一个整数P ...

  4. https://www.runoob.com/python/python-variable-types.html

    https://www.runoob.com/python/python-variable-types.html

  5. 用户交互和if条件判断、嵌套

    #a=input("提示语“)#接受的数据类型是字符串str#提示用户输入姓名 # a=input("请输入姓名") print(a) '''输出结果:请输入姓名小明 姓 ...

  6. MFC (Combo-box control)下拉列表控件的使用

    1.可以选择,但无法编辑状态: 选择下拉框的属性中的类型(Type)参数——Drop List; 2.如何控制Combo Box的下拉长度 1,一.在资源文件中打开对话框,选中Combo Box控件, ...

  7. [SQL]连续三天有销售额

    店铺 销售日期 销售额 A 2017-10-11 300 A 2017-10-12 200 B 2017-10-11 400 B 2017-10-12 200 A 2017-10-13 100 A 2 ...

  8. 数位DP || Gym 101653R Ramp Number

    每一位都大于等于前一位的数叫Ramp Number 给一个数,如果不是Ramp Number输出-1,如果是Ramp Number输出比它小的Ramp Number的个数 只和每一位上的数字有关 #i ...

  9. \p{space}|\p{Hex}|\p{Digit}|转译符|\1|\g{-1}|[^ab]|/([^\d\D]+)/

    小骆驼 第七章 漫游正则表达式王国 #!/usr/bin/perl use strict; use warnings; $_ = 'ab \ cde f ghijk10.x12ln'; if(/d/) ...

  10. Go:json(序列化、反序列化)

    一.示例 package main import ( "encoding/json" "fmt" ) type Person struct { Name str ...