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 ...
随机推荐
- 20165305 苏振龙《Java程序设计》第四周学习总结
第五章 继承: 面向对象中,为避免多个类间重复定义共同行为.(简单说就是将相同的程序代码提升为父类.) 特点: 这里接触到了新的关键词,extends,在java语言中用estends来继承父类的行为 ...
- android Observable api请求参数设置注解问题
android Observable api请求参数设置注解问题 2018-10-29 20:05:24.919 11786-11786/xxx E/wxh: getQuote=USD getBase ...
- 阿里巴巴json fastjson String转javaBean
private Entity getEntity(String resp){ JSONObject jsonObj = (JSONObject) JSON.parse(resp); ...
- Javascript深入理解构造函数和原型对象
1.在典型的oop的语言中,如java,都存在类的概念,类就是对象的模板,对象就是类的实例.但在js中不存在类的概念,js不是基于类,而是通过构造函数(constructor)和原型链(propoty ...
- WordConuts
import java.io.File; import java.io.FileNotFoundException; import java.util.HashMap; import java.uti ...
- 配置方案:Redis持久化RDB和AOF
Redis持久化方案 Redis是内存数据库,数据都是存储在内存中,为了避免进程退出导致数据的永久丢失,需要定期将Redis中的数据以某种形式(数据或命令)从内存保存到硬盘.当下次Redis重启时,利 ...
- IE haslayout的属性及其值
haslayout是IE 渲染引擎的一个内部组成部分.在IE 中,一个元素要么自己对自身的内容进行计算大小和组织,要么依赖于父元素来计算尺寸和组织内容.为了调节这两个不同的概念,渲染引擎采用了hasl ...
- The Little Prince-12/15
The Little Prince-12/15 明天四六级考试了呢!!!喵喵喵,愿大家都能取得好成绩. 星星美丽,因为里面有一朵看不见的花. 沙漠美丽,因为沙漠的某处隐藏着一口井. ————生活美好, ...
- OCR技术初识
一.什么是OCR OCR英文全称是Optical Character Recognition,中文叫做光学字符识别.它是利用光学技术和计算机技术把印在或写在纸上的文字读取出来,并转换成一种计算机能够接 ...
- Nginx和PHP上传文件大小的限制
Nginx client_max_body_size 80m; PHP php.ini file_uploads = on ; 是否允许通过HTTP上传文件的开关.默认为ON即是开 upload_tm ...