codeforces #332 div 2 D. Spongebob and Squares
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;
}
真诚赞赏,手留余香
5元
10元
50元
100元
任意金额
使用微信扫描二维码完成支付
Please enable JavaScript to view the comments powered by Disqus.
comments powered by Disqus
codeforces #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) D. Spongebob and Squares(枚举)
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...
- 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 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
随机推荐
- typescript-学习使用ts-2
解构赋值 数组解构 let input = [1, 2]; let [first, second] = input; console.log(first); // outputs 1 console. ...
- UG NX7.5 采用VS2008调试方法
1.安装NX7.5(x64),这是废话 2.安装visual studio 2008,推荐安装2008,如果是2010应该也可以用,(没有测试,不清楚) 3.复制 UGS\NX 7.5\UGOPEN\ ...
- webfrom 控件
服务器基本控件: button: text属性 linkbutton:text属性,它是一个超链接模样的普通button hyperlink: navigateurl:链接地址,相当于<a> ...
- ElasticSearch 分组查询
curl -XPOST 'localhost:9200/bank/_search?pretty' -d ' { "size": 0, "aggs": { &qu ...
- apache启动失败,提示80端口被占用
首先检查80端口被什么程序占用,方法:cmd进DOS,输入netstat -ano 80端口被为4的进程占用,有两种可能:一种情况是本机中安装了sqlserver 2008,80端口被SqlServe ...
- spring02-组件注册-@ComponentScan-自动扫描组件&指定扫描规则
上一篇我们讲到,讲@Bean注解标在某个方法上,那么ioc容器启动的时候就会将方法返回值放到ioc容器中 在开发中,实际上包扫描用的比较多,接下来我们会介绍两种方式一种是基于xml,一种是基于注解. ...
- Linux Centos下MySQL主从Replication同步配置(一主一从)
MySQL 主从复制概念MySQL 主从复制是指数据可以从一个MySQL数据库服务器主节点复制到一个或多个从节点.MySQL 默认采用异步复制方式,这样从节点不用一直访问主服务器来更新自己的数据,数据 ...
- OAuth 2.0安全案例回顾
转载自:http://www.360doc.com/content/14/0311/22/834950_359713295.shtml 0x00 背景 纵观账号互通发展史,可以发现OAuth比起其它协 ...
- iOS 有关二维码
一.把相应的URL生成二维码 利用有关图像变成的框架 #import <CoreImage/CoreImage.h> 步骤:实例化二维码滤镜---->恢复滤镜属性---->将字 ...
- [APIO2009-C]抢掠计划
题:https://www.cometoj.com/problem/0461 分析:求边双,最后求多汇点最长路 #include<iostream> #include<cstring ...