SPOJ:NPC2016A(数学)】的更多相关文章

题目链接:点击传送 INTSUB - Interesting Subset no tags  You are given a set X = {1, 2, 3, 4, … , 2n-1, 2n} where n is an integer. You have to find the number of interesting subsets of this set X. A subset of set X is interesting if there are at least two inte…
题目大意: 一个有n面的色子抛掷多少次能使所有面都能被抛到过,求期望值 总面数为n,当已经抛到过 i 个不同面时,我们抛出下一个不同面的概率为 (n-i)/n,那么抛的次数为 n/(n-i) 将所有抛出下个面的次数累加起来就好了 #include <cstdio> int main(){ int kase,n; scanf("%d",&kase); while(kase--){ scanf("%d",&n); ; ;i <= n;i…
A(SPOJ NPC2016A) 题意:给一个正方形和内部一个点,要求从这个点向四边反射形成的路线的长度 分析:不断做对称,最后等价于求两个点之间的距离 B(CF480E) 题意:求01矩阵内由0组成的最大正方形,但这里有修改操作,每次操作把一个0位置修改成1.矩阵大小<=2000*2000,操作次数<=2000 分析:离线倒序+悬线法+单调队列维护 首先离线,倒着从前往后做 先预处理每个0位置向上.向下最多能延展多少 对于修改就暴力修改,时间复杂度是O(kn)的 问题是如何维护询问的结果 注…
http://www.spoj.com/problems/NPC2016A/en/ 题意:在一个n*n的平面里面,初始在(x,y)需要碰到每条边一次,然后返回(x,y),问最短路径是多长. 思路:像样例中给出的,假设一开始是在(x,y),那么走一个斜率为1和-1的路径,因为两边对称,所以ans = 2 * x * sin(45°) + 2 * (n - x) * sin(45°) = 2 * n * sqrt(2). 就是每次走的都是对角线的长度. #include <bits/stdc++.h…
http://www.spoj.com/problems/INTSUB/en/ 题意:给定一个集合,该集合由1,2,3....2n组成,n是一个整数.问该集合中有趣子集的数目,答案mod1e9+7. x的子集合有趣定义为,该子集中至少有两个数,a和b,b是a的倍数且a是集合中最小的元素. 思路:考虑集合中最小的元素a,对于每个a,使得可以构成子集的元素(即b)有beishu = 2 * n / a - 1个,那么这里只考虑这些有2^beishu - 1个.那么还剩下other = 2 * n -…
BuggyD loves to carry his favorite die around. Perhaps you wonder why it's his favorite? Well, his die is magical and can be transformed into an N-sided unbiased die with the push of a button. Now BuggyD wants to learn more about his die, so he raise…
There is a robot on the 2D plane. Robot initially standing on the position (0, 0). Robot can make a 4 different moves: Up (from (x, y) to (x, y + 1)) with probability U. Right (from (x, y) to (x + 1, y)) with probability R. Down (from (x, y) to (x, y…
Given an array of N integers A1, A2, A3…AN. If you randomly choose two indexes i ,j such that 1 ≤ i < j ≤ N, what is the expected value of Ai | Aj? Input First line contains an integer T, the number of test cases. Each test case consists of two lines…
题意: 给出一个数N,问所有满足n/x=y(此处为整除)的所有x*y的总和是多少.对答案mod(1e9+7). 1 <= T <= 500. 1 <= N <= 1e9. 分析: 可以枚举x得到y,但是这样是O(n)的会TLE 当x<=sqrt(n)的时候,我们可以暴力枚举 当x>sqrt(n)的时候,我们发现很多x对应的y值都相等,这些组成一个等差序列,实际上,这时候的(x,y)就是我们之前暴力过的(y,x),等差数列求和即可…
Part 1:杜教筛进阶在了解了杜教筛基本应用,如$\sum_{i=1}^n\varphi(i)$的求法后,我们看一些杜教筛较难的应用.求$\sum_{i=1}^n\varphi(i)*i$考虑把它与$id$函数狄利克雷卷积后的前缀和.$$\sum_{i=1}^n\sum_{d|i}\varphi(d)*d*\frac id=\sum_{i=1}^ni^2$$枚举$T=\frac id$,原式化为$$\sum_{T=1}^nT\sum_{d=1}^{\lfloor\frac nT\rfloor}…