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 ...
随机推荐
- 中山纪念中学20170310洗衣服(贪心,优先队列升序【pair】)
#include<bits/stdc++.h>using namespace std;typedef pair<long long,int>clot;priority_queu ...
- 洛谷P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a u ...
- [转]AFNetworking 3.0迁移指南
http://www.jianshu.com/p/047463a7ce9b?utm_campaign=hugo&utm_medium=reader_share&utm_content= ...
- MySQL常用配置和性能压力测试:MySQL系列之十五
一.MySQL常用配置 以下所有配置参数以32G内存的服务器为基 1.打开独立的表空间 innodb_file_per_table = 1 2.MySQL服务所允许的同时会话数的上限,默认为151,经 ...
- 谈缓存数据库在web开发中的重要性
1.开局先抛出如下问题: ①当关系型数据库存放的数据量很大时,每次查询耗时明显变长,那么如何解决该问题? ②当业务要求单用户登录(即同一个账户有一个用户登录后,第二个用户再登录该账户要么挤出之前的登录 ...
- HTTP的一些理解
URI是Uniform Resource Identifier的缩写,统一资源标识符.URI用字符串标识某一互联网资源,而URL标识资源的地点(互联网上所处的位置).可见URL是URI的子集. 典型的 ...
- PHP异步任务worker
1.概述 异步任务框架主要包含两个角色: WorkerServer主要负责管理(启动,重启,监控等)worker工作进程. Worker负责从指定消息队列获取任务消息并执行任务. 为了提高worker ...
- 牛客网练习赛26B(简单的dp)
题目链接:https://www.nowcoder.com/acm/contest/180/B 链接:https://www.nowcoder.com/acm/contest/180/B来源:牛客网 ...
- js车牌号校验
function cpyz(str) { var newcarnum= str.value.toUpperCase(); var regExp = /(^[\u4E00-\u9FA ...
- MyEclipse8.5配置struts等框架
开发环境:MyEclipse8.5+Tomcat6.5+MySql5.5配置环境:Struts2+Spring2+Hibernate3.1 1.首先创建Java-Web Project工程,选择J2E ...