CF 599D 思维
来源:互联网 发布:4万亿救市的后果知乎 编辑:程序博客网 时间:2024/04/30 05:36
Codeforces 559D
题目链接:
http://codeforces.com/problemset/problem/599/D
题意:
问有几种n*m的矩形方案,使得在里面放置1*1,2*2…矩形的方案由x种。输出方案。
思路:
现场的时候太困先睡,早上测单杠等的时候顺便想了下……好简单啊……
很容易知道对于合法的(n,m),(m,n)也是合法的。故假设n <= m。那么对于极端情况n=m,这时面积应该是n^2 + (n-1)^2+…1^2。怎么想的话画一画就知道对于2*2的矩形在n*n的矩形中有几种放法,和1*1的矩形在(n-1)*(n-1)的矩形中有几种方法是一样的(用边界来考虑)
那么一个面积x,它至少要大于等于n^2 + (n-1)^2+…1^2。也就是rest = 面积x减去n^2 + (n-1)^2+…1^2这个基础值。这时,若面积不够(rest > 0),则每次至少增加一列,一列中有n个格子。根据之前的换算可以类似的得出,每增加一列,面积增加d=(n+1)*n/2。判断一下rest是不是d的整数倍就可以。
源码:
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <cmath>#include <iostream>#include <string>#include <queue>#include <vector>using namespace std;#define LL long longconst int MAXN = 1e6 + 5;struct D{ LL u, v;}ans[MAXN];LL cal3(LL a){ return a * (a + 1) * (2 * a + 1) / 6;}bool cmp(D a, D b){return a.u < b.u;}int main(){ LL a; while(scanf("%I64d", &a) != EOF){ int cnt = 0; for(LL i = 1 ; cal3(i) <= a ; i++){ LL rest = a - cal3(i); LL d = (i + 1) * i / 2; if(rest % d == 0){// printf("cal3(i) = %I64d\n", cal3(i));// printf("i = %I64d, rest = %I64d, d = %I64d\n", i, rest, d); ans[cnt].u = i, ans[cnt++].v = i + rest / d; if(rest != 0) ans[cnt].u = i + rest / d, ans[cnt++].v = i; } } sort(ans, ans + cnt, cmp); printf("%d\n", cnt); for(int i = 0 ; i < cnt ; i++) printf("%I64d %I64d\n", ans[i].u, ans[i].v); } return 0;}
0 0
- CF 599D 思维
- CF - 463D LIS + 思维
- cf 808D Array Division(二分思维)@
- CF #890 D 题 【图论 + 思维】
- CF 475D CGCDSSQ 枚举,思维+gcd
- CF 899D Shovel Sell 思维.
- CF:3D City Model(小思维)
- CF --- 832D Misha, Grisha and Underground 【LCA + 思维】
- CF 219D Choosing Capital for Treeland 【树形dp + 思维】
- CF 870D. Something with XOR Queries 交互,思维
- Bear and Blocks CF-574D(类似dp+思维)
- CF 782D. Innokenty and a Football League 贪心,思维,模拟
- CF Round #423 Div. 2 C. String Reconstruction D. High Load 【思维】
- CF 863D. Yet Another Array Queries Problem 逆向思维,递归
- cf(思维题)
- cf(思维,数学)
- CF Watchmen 【思维+数学】
- CF#119 Permutations(思维)
- effective c++避免返回handles指向对象内部成分(2)
- 【Leetcode】Symmetric Tree
- DataGrid 合并单元格
- unknown host specified问题的解决
- Java8のStream学习
- CF 599D 思维
- 四大组件基本用法与介绍(1)--activity
- oracle decode函数,取两个日期中的较大值
- Delphi自带的的Zip比较好用简单
- 怎样实现一个潮流的开关按钮
- truncate与delete的区别
- 【PA2014】【BZOJ3713】Iloczyn
- C++ 面向对象程序设计
- iOS之拼图小游戏