http://codeforces.com/contest/599/problem/D
题意:给出总的方格数x,问有多少种不同尺寸的矩形满足题意,输出方案数和长宽(3,5和5,3算两种)
思路:比赛的时候gg了。。其实稍微在纸上推一下。就会得到对于n,m的矩形,一共会有-n*n*n+3*n*n*m+n+3*n*m的方格。数量级是n3。
我们可以实际跑一遍。发现对于x1E18的数量级,n不会超过1442550,1E6,可以搞。

需要注意的是,一个是会爆int,所以记得用long long

另一个是如果两个数相等,记得只输入一组,并且方案数-1

我是用set +pair存的答案。。反向遍历set的时候要用reserve_iterator…

/* ***********************************************
Author :111qqz
Created Time :2015年12月23日 星期三 15时54分37秒
File Name :code/cf/#332/D.cpp
************************************************ */ #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < LL ,LL >
#define MP make_pair using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
LL x;
LL cur;
const LL MAXN = 1442550;
set<pi>se;
LL cal( LL n,LL m)
{
LL res = -n*n*n+3*n*n*m+3*n*m+n;
return res;
}
int square = -1;
int main()
{
#ifndef ONLINE_JUDGE
freopen("code/in.txt","r",stdin);
#endif
// for ( LL i = 1 ; ; i++)
// {
// cur = cal(i,i);
// // cout<<"i:"<<i<<" cur:"<<cur<<endl;
// if (cur>1E18)
// {
// cout<<i<<endl;
// break;
// }
//
// }
cin>>x;
x = x*6;
for ( LL i = 1 ; cal(i,i)<=x ; i++)
{
LL tmp = (x-i+i*i*i)%(3*i*i+3*i);
// cout<<"i:"<<i<<" tmp:"<<tmp<<endl;
if (tmp==0)
{
se.insert(make_pair(i,(x-i+i*i*i)/(3*i*i+3*i)));
if (i==(x-i+i*i*i)/(3*i*i+3*i)) square = 1; }
}
if (square==1)
cout<<se.size()*2-1<<endl;
else cout<<se.size()*2<<endl;
set<pi>::iterator it;
for (it = se.begin(); it!=se.end() ;it++)
{ cout<<(*it).fst<<" "<<(*it).sec<<endl;
}
set<pi>::reverse_iterator it2; //反向遍 大专栏  codeforces #332 div 2 D. Spongebob and Squares历要用反向迭代器。。。右忘记了。。。。
for ( it2 =se.rbegin() ;it2 !=se.rend() ; it2 ++)
{
if (square==1)
{
square = 2;
continue;
} cout<<(*it2).sec<<" "<<(*it2).fst<<endl;
} #ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
×

真诚赞赏,手留余香

2元
5元
10元
50元
100元
任意金额
2元

使用微信扫描二维码完成支付



Please enable JavaScript to view the comments powered by Disqus.
comments powered by Disqus

codeforces #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) D. Spongebob and Squares(枚举)

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

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

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

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

  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 time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

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

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

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

随机推荐

  1. 蓝屏(BSOD)转储设置,看本文就够了!

    原总结注册表debug调试dump转储文件蓝屏BSODprocess monitor 前言 我们在 内核转储,开抓啦! 这篇文章里介绍了一个关键的系统设置.设置好后可以让系统在蓝屏(Blue Scre ...

  2. [HAOI2018]苹果树(组合数学)

    首先有个很奇妙而且很有用的性质:每个二叉树对应唯一的中序遍历,然后每个二叉树出现概率相同.所以n个节点的二叉树形态是n!种(题目中说了*n!已经是提示了),对每种方案求和即可得到期望.令f[i]表示i ...

  3. 微信小程序裁剪图片后上传

    上传图片的时候调起裁剪页面,裁剪后再回调完成上传; 图片裁剪直接用we-cropper   https://github.com/we-plugin/we-cropper we-cropper使用详细 ...

  4. Python——气象数据分析

    将对意大利北部沿海地区的气象数据进行分析与可视化.我们在实验过程中先会运用 Python 中 matplotlib 库的对数据进行图表化处理,然后调用 scikit-learn 库当中的的 SVM 库 ...

  5. Windows安装使用Jenkins

    #前提条件是要把JDK安装好 1.下载jenkins:https://jenkins.io/download/ 选择windows版本 2.安装成功过后自己会启动 如果想自己启动(这两个需要以管理员方 ...

  6. kotlin 单例模式

    class Single{ companion object { val instance:Single by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZE ...

  7. JavaMail读取收件箱退信邮件/分析邮件附件获取Message_Id

    需求描述:公司最近有个项目邮件通知功能,但是客户上传的邮件地址并不一定存在,以及其他的各种问题.所有希望发送通知后有个回执,及时发现地址存在问题的邮箱. 需求分析:经过分析JavaMail可以读取收件 ...

  8. ionic 打包时所遇问题记录

    问题1 ----------------------- Error occurred during initialization of VM Could not reserve enough spac ...

  9. LoggingService

    package me.zhengjie.common.aop.log; import java.lang.annotation.ElementType; import java.lang.annota ...

  10. ORs-3-OR Gene Family Phylogeny

    OR Gene Family Phylogeny 1.之前关于ORs基因构建系统生发树的研究中的不足:bootstrap support values在有些family中高,bootstrap sup ...