Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)
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(枚举)的更多相关文章
- 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/ ...
- 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 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 ...
- Codeforces Round #332 (Div. 二) B. Spongebob and Joke
Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...
- 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 ...
- 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 ...
- 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 ...
- 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)
水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...
随机推荐
- Spring SpringBoot和SpringCloud的关系
Spring SpringBoot和SpringCloud的关系 Spring Cloud 是完全基于 Spring Boot 而开发,Spring Cloud 利用 Spring Boot 特性整合 ...
- vue-router基本使用
路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击页面上的about 按钮,页面中就要显示about 的内容.Home按钮 => home 内容, ...
- 安装DotNetCore.1.0.0-VS2015Tools.Preview2一直失败,如何解?
首先要说明的一点是,本地的VS2015的环境已经安装完成,而且vs2015.3也已经更新完成了,这个环境应该是没啥问题.但是安装.DotNetCore.1.0.0-VS2015Tools.Previe ...
- ubuntu_python_environment
参考:http://blog.csdn.net/kingppy/article/details/13080919 参考:http://blog.csdn.net/zhaobig/article/det ...
- thinkphp 整合微信支付-简单粗暴
<?php//判断是否是微信客户端--该代码只适用于手机微信端--使用方法请看最后面注释if (isset($_SERVER['HTTP_USER_AGENT']) && str ...
- amoeba_mysql 读写分离
环境 amoeba需要java环境,配置:略. MySQL主从配置:略. 基本架构 MySQL主:192.168.31.140 MySQL从:192.168.31.150 MySQL代理:192.16 ...
- oracle 11g AUTO_SAMPLE_SIZE动态采用工作机制
Note that if you're interested in learning about Oracle Database 12c, there's an updated version of ...
- c++ linux下输出中文
同样,使用的是VS FOR LINUX进行测试. converting to execution character set: Invalid or incomplete multibyte or w ...
- 2、pandas的value_counts()和describe()
一.value_counts pandas 的value_counts()函数可以对Series里面的每个值进行计数并且排序. value_counts是计数,统计所有非零元素的个数,默认以降序的方式 ...
- ACM札记
1. 逗号表达式 在“计蒜客“的ACM教程中,看到这样一段很好的代码: int n; while (scanf("%d", &n), n) { //do something ...