CF 599D Spongebob and Squares(数学)】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/599/D 题意:定义F(n,m)为n行m列的矩阵中方阵的个数,比如3行5列的矩阵,3x3的方阵有3个.2x2的方阵有8个.1X1的方阵有15个,所以F(3,5)=3+8+15=26.现在告诉你F(a,b)=x中的x,要你求出所有满足要求的a,b,并按a递增的顺序输出. 思路:找出n行m列的矩阵中方阵数量的表达式即可,有些小细节需要注意... code: #include <iostream> #inc…
据题意: $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 <cstri…
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m colum…
D. Spongebob and Squares   Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m col…
很容易得到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() { #i…
D. Spongebob and Squares time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all…
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 另一个是…
D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/problem/D Description Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that t…
[链接]:CF [题意]:对于一个数n,每次加一的代价是a,每次减一的代价是b,求被m整除时的最小代价. [分析]:分情况讨论,自己多举几个栗子. [代码]: #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<qu…
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $ 化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$ 将n作为小的数,枚举n即可. #include<iostream> #i…
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to…
B. Continued Fractions time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A continued fraction of height n is a fraction of form . You are given two rational numbers, one is represented as  a…
题意:给n个元素,从n中选两个非空集合A和B.问有多少中选法? 递推: dp[n]表示元素个数为n的方案数,对于新来的一个元素,要么加入集合,要么不加入集合自成一个集合.加入集合有三种选择,A,B,E(可空的集合),或者自成集合,作为A或B,然后在选一个n-1个元素的非空子集(2^n-1 - 1). #include<cstdio> ; typedef unsigned long long ll; int main() { int n; scanf("%d",&n)…
http://codeforces.com/contest/602/problem/D 这题需要注意到的是,对于三个点(x1, y1)和(x2, y2)和(x3, y3).如果要算出区间[1, 3]的L(h)函数的最大值,则一定不会是 通过(y3 - y1) / (x3 - x1)算出.因为很简单,通过(x2, y2)作为辅助点,数值将会更加大. 然后设dis[i]表示abs(a[i + 1] - a[i]).那么区间[L, R]的最大值就是在dis[]中,[L, R - 1]数值的最大值. 因…
http://codeforces.com/problemset/problem/599/D 题目大意:给你一个数k  让你求一个n*m的矩形里面包含k个正方形   输出有几个这样的矩形  分别是什么 可以推出一个数学公式 我们枚举i*i的正方形  这个正方形里面的包含的正方形是有(i*i)+(i-1) *( i-1)+(i-2)*(i-2)+...+(1*1)   就等于b=i*(i-1)*(2*i-1)/6; 如果k>b  说明这个正方形里面的正方形是不够的  我们需要再添加n个(1*i)的…
http://poj.org/problem?id=2002 只能说hash比二分快很多.随便一个hash函数都可以完爆二分. 判断是否存在正方形思路如下: 1.枚举任意两个点,作为正方形的一条边,那么,整个正方形就确定了,有两个方向. 因为, 设枚举的坐标为(x1, y1) & (x2, y2),所求的坐标是和x1,y1这个点相连,那么有方程如下. 1.垂直,向量积是0 2.边长相等,然后距离公式化简. 即可解出剩下的两个点. 然后要注意两个点要在正方形的同一侧,不然变了平行四边形了. 唤醒了…
C. Sequence Transformation:http://codeforces.com/contest/1059/problem/C 题意 给你一个n,第一次输出1-n个数的gcd,然后你可以任意删除1-n中的数字,然后输出剩下n-1个数的gcd,再删一个数...,最后就是输出n个gcd值对吧. 要求输出的数列字典序最大. 思路 首先对于一个n,为了使得数列字典序最大,肯定是越早输出2越好,所以前面先把所有的奇数去掉,前(n+1)/2 个数肯定也就是1,那么剩下的偶数呢,可以先对这些偶…
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to…
水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int d1, d2, d3; scanf ("%d%d%d", &d1, &d2, &d3); printf ("%d\n", min (min (2 * (min (d1, d2) + d3), 2 * (d1 + d2)), d1 + d2 + d…
题目链接 描述 A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degree angles. It is also a polygon such that rotating about its centre by 90 degrees gives the same polygon. It is not the only polygon with the latter pr…
E. Sereja and Squares http://codeforces.com/contest/314/problem/E 题意: 给你一个擦去了部分左括号和全部右括号的括号序列,括号有25种,用除x之外的小写字母a~z表示.在擦去的地方填入一括号,求有多少种合法的括号序列.答案对4294967296取模. 分析: 首先dp的时候如果前面的一个左括号确定了,右边也就确定了(和它一样就行了).左边不确定的时候'?',假设随便填入一个,最后乘以25就行了.所以状态只与左括号的个数有关.所以可…
近期在看CF的相关论文,<Collaborative Filtering for Implicit Feedback Datasets>思想非常好,非常easy理解.可是从目标函数 是怎样推导出Xu和Yi的更新公式的推导过程却没有非常好的描写叙述.所以以下写一下 推导: 首先对Xu求导: 当中Y是item矩阵,n*f维,每一行是一个item_vec,C^u是n*n维的对角矩阵. 对角线上的每个元素是c_ui,P(u)是n*1的列向量,它的第i个元素为p_ui. 然后令导数=0,可得: 因为x_…
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are…
DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a…
Amr and Pins time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r and center in point (x, y).…
Polycarpus' Dice time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of n…
 Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspect…
A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. An important part of preparing for a competition is shar…
Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has n…