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

题意:
给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值。

思路:

易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $

化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$

将n作为小的数,枚举n即可。

 #include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std; typedef long long ll;
typedef pair<ll,ll> pll; ll x;
vector<pll> ans1,ans2; int main()
{
//freopen("in.txt","r",stdin);
ll tot = ;
scanf("%lld",&x);
for(ll n=;;n++)
{
ll a = n*(n+) - n*(n+)/;
ll b = n*(n+)*(*n+)/ - n*n*(n+)/;
if(b > x) break;
if((x - b)%a == )
{
ll m = (x - b)/a;
if(m<n) continue;
ans1.push_back(make_pair(n,m));
tot++;
if(m!=n)
{
ans2.push_back(make_pair(m,n));
tot++;
}
}
}
printf("%lld\n",tot);
for(int i=;i<ans1.size();i++)
{
printf("%lld %lld\n",ans1[i].first,ans1[i].second);
}
for(int i=ans2.size()-;i>=;i--)
{
printf("%lld %lld\n",ans2[i].first,ans2[i].second);
}
return ;
}

Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)的更多相关文章

  1. 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/ ...

  2. 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 ...

  3. Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题

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

  4. Codeforces Round #332 (Div. 二) B. Spongebob and Joke

    Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...

  5. Codeforces Round #332 (Div. 2)_B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #332 (Div. 2)B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟

    B. Spongebob and Joke     While Patrick was gone shopping, Spongebob decided to play a little trick ...

  8. codeforces #332 div 2 D. Spongebob and Squares

    http://codeforces.com/contest/599/problem/D 题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种) 思路:比赛的 ...

  9. Codeforces Round #332 (Div. 2)

    水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...

随机推荐

  1. Presto 学习和使用笔记

    1.presto 表连接查询的连接条件中不支持使用函数 比如下面的脚本在presto中运行会报错 select t1.period_start_date, t2.statistic_date from ...

  2. HDU 3461 Code Lock(并查集+二分求幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3461 A lock you use has a code system to be opened in ...

  3. zabbix实现电话、短信、邮件报警

    该报警方式提前说明:(1)该方式可以实现zabbix免费电话报警以及微信.短信.邮件报警,但有数量限制.详见如下:如数量不能满足需要以及人员需要,可以考虑购买收费版.(2)毕竟是免费版,电话通知要省着 ...

  4. redis 的数据结构

    Redis 数据类型 详解见: http://www.runoob.com/redis/redis-strings.html Redis支持五种数据类型:string(字符串),hash(哈希),li ...

  5. mycat分片操作

    mycat位于应用与数据库的中间层,可以灵活解耦应用与数据库,后端数据库可以位于不同的主机上.在mycat中将表分为两大类:对于数据量小且不需要做数据切片的表,称之为分片表:对于数据量大到单库性能,容 ...

  6. oracle 9i/10gR2所有版本下载地址

    Oracle 9i Oracle9i Database Release 2 Enterprise/Standard/Personal Edition for Windows NT/2000/XP ht ...

  7. Navicat Premium 12.0.18安装与激活(转)

    转载:https://www.jianshu.com/p/42a33b0dda9c 一.Navicat Premium 12下载 Navicat Premium 12是一套数据库开发管理工具,支持连接 ...

  8. Eclipse中在xml文件中,ctrl+左键的快捷键,点击class定位,不生效

    修改方式:   第一种方式:Window -> Preferences -> General -> Editors -> File Associations           ...

  9. HTML DOM open() 方法

    HTML DOM Window 对象 定义和用法 open() 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口. 语法 window.open(URL,name,features,replace ...

  10. python&django 常见问题及解决方法

    0.python-dev安装(ubuntu) apt-get install  python-dev 1.Open(filename,mode) 报错实例: f = open('d:\Users\16 ...