[cf 599D] Spongebob and Squares
据题意:
$K=\sum\limits_{i=0}^{n-1}(n-i)*(m-i)$
$K=n^2m-(n+m)\sum{i}+\sum{i^2}$
展开化简
$m=(6k-n+n^3)/(3n^2+3n)$
枚举n,验证整除,只做n<=m,其余反过来输出即可
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <cmath>
- #include <ctime>
- #include <vector>
- using namespace std;
- vector<pair<long long,long long> >S;
- int main()
- {
- long long x,i,Ans=;
- scanf("%lld",&x);
- for(i=;;++i)
- {
- long long n=i,m=(6LL*x-n+n*n*n)/(*n*n+*n);
- if(n>m)break;
- if((6LL*x-n+n*n*n)%(*n*n+*n)==)
- {
- S.push_back(make_pair(n,m));
- }
- }
- if(S.back().first==S.back().second)
- {
- Ans=-;
- }
- Ans+=(int)S.size()<<;
- printf("%lld\n",Ans);
- for(i=;i<(int)S.size();++i)
- {
- printf("%lld %lld\n",S[i].first,S[i].second);
- }
- if(S.back().first==S.back().second)
- {
- S.pop_back();
- }
- while(!S.empty())
- {
- printf("%lld %lld\n",S.back().second,S.back().first);
- S.pop_back();
- }
- return ;
- }
[cf 599D] Spongebob and Squares的更多相关文章
- CF 599D Spongebob and Squares(数学)
题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x ...
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- codeforces 599D Spongebob and Squares
很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...
- Codeforces 599D:Spongebob and Squares
D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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) 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 ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...
随机推荐
- Flink编程练习
目录 1.wordcount 2.双流警报EventTime 3.持续计数stateful + timer + SideOutputs 4.一定时间范围内的极值windowfunction + che ...
- 浅谈IO优化
三层结构 磁盘(存储).VM(卷管理)和文件系统.专有名词不好理解,打个比方说:磁盘就相当于一块待用的空地:LVM相当于空地上的围墙(把空地划分成多个部分):文件系统则相当于每块空地上建的楼房(决定了 ...
- Linux分区方式 及 Xshell远程连接排错
第1章 远程连接 1.1 Linux远程连接软件 Windows: Xshell/SecureCRT/Putty mac: 终端ssh命令或iterm2 Android: ...
- E20171015-hm
quirk n. 怪癖; 奇事,巧合; 突然的弯曲; propagation n. 宣传; 传播,传输,蔓延,扩展,波及深度; [生]繁殖法,[地]传导; 培养; immediate adj. ...
- Django基于JWT实现微信小程序的登录和鉴权
什么是JWT? JWT,全称Json Web Token,用于作为JSON对象在各方之间安全地传输信息.该信息可以被验证和信任,因为它是数字签名的. 与Session的区别 一.Session是在服务 ...
- linux 查看内存和cpu
Linux查看CPU和内存使用情况 在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 ...
- JavaScript--认识DOM
文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树). 先来看看下面代码: 将HTM ...
- Java常用集合类
上述类图中,实线边框的是实现类,比如ArrayList,LinkedList,HashMap等,折线边框的是抽象类,比如AbstractCollection,AbstractList,Abstract ...
- ANDROID 开发之 SQLite
SQLite简介 Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级 使用 SQLit ...
- c# regex Match Matches MatchCollection 用法
string text = "1A 2B 3C 4D 5E 6F 7G 8H 9I 10J 11Q 12J 13K 14L 15M 16N ffee80 #800080"; Reg ...