codeforces 599D Spongebob and Squares
很容易得到n × m的方块数是
然后就是个求和的问题了,枚举两者中小的那个n ≤ m。
然后就是转化成a*m + c = x了。a,m≥0,x ≥ c。最坏是n^3 ≤ x,至于中间会不会爆,测下1e18就好。
#include<bits/stdc++.h>
using namespace std; typedef long long ull; vector<ull> ns;
vector<ull> ms; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
ull x, t, c, a, n, m; cin>>x;
int k = ;
//ns.push_back(1); ms.push_back(x);
int equ = ;
for(n = ; ; n++){
t = n*(n+)/;
c = (n)*(n+)*(*n+)/ - n*t;
if(c > x) break;
a = n*(n+) - t;
if((x - c) % a == ) {
m = (x-c)/a;
if(m < n) break;
ns.push_back(n);
ms.push_back(m);
k++;
if(m == n){
equ = ; break;
}
}
} if(equ){
k = *k-;
printf("%d\n", k);
int sz = ns.size();
for(int i = ; i < sz; i++){
printf("%I64d %I64d\n", ns[i], ms[i]);
}
for(int i = sz-; i >= ; i--){
printf("%I64d %I64d\n", ms[i], ns[i]);
}
}
else {
k = *k;
printf("%d\n", k);
int sz = ns.size();
for(int i = ; i < sz; i++){
printf("%I64d %I64d\n", ns[i], ms[i]);
}
for(int i = sz-; i >= ; i--){
printf("%I64d %I64d\n", ms[i], ns[i]);
}
} return ;
}
codeforces 599D Spongebob and Squares的更多相关文章
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- CF 599D Spongebob and Squares(数学)
题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x ...
- [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 ...
- Codeforces 599D:Spongebob and Squares
D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 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 #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 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 ...
随机推荐
- rowid去重(转)
实际应用场景:数据去重--当多条记录主键相同或者多条记录完全一致时,只需要留下一条记录 delete from bal_acctbook_info where rowid not in (select ...
- 虚拟机上安装Cell节点(12.1.2.3.3)
安装介质下载 打开firefox,输入:https://edelivery.oracle.com 点击"Sign In",输入帐号.密码,登陆edelivery网站. ...
- JPA教程
http://www.yiibai.com/jpa/jpa_criteria_api.html
- 【ACM】棋盘覆盖 - 大数除
棋盘覆盖 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在一个2k×2k(1<=k<=100)的棋盘中恰有一方格被覆盖,如图1(k=2时),现用一缺角的 ...
- Repair 暴力
Description standard input/outputStatements Alex is repairing his country house. He has a rectangula ...
- Java面向对象_常用类库api——二分查找算法
概念:又称为折半查找,优点是比较次数少,查找速度快,平均性能好:缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表. 例: public class Bi ...
- 影子内存(Shadow RAM)介绍_4
影子内存(Shadow RAM,或称ROM shadow)是为了提高系统效率而采用的一种专门技术.它把系统主板上的系统ROM BIOS和适配器卡上的视频ROM BIOS等拷贝到系统RAM内存中去运行, ...
- android 开发-文件存储之读写sdcard
android提供对可移除的外部存储进行文件存储.在对外部sdcard进行调用的时候首先要调用Environment.getExternalStorageState()检查sdcard的可用状态.通过 ...
- Cucumber 场景大纲 Scenario Outlines
引用链接:https://github.com/cucumber/cucumber/wiki/Scenario-Outlines script/cucumber --i18n zh-CN | feat ...
- C#中接口的深入浅出【转】
C#中接口的深入浅出 假设我们公司有两种程序员:VB程序员,指的是用VB写程序的程序员,用clsVBProgramer这个类表示:Delphi程序员指的是用Delphi写程序的程序员,用clsDelp ...