Little Tim is now a graduate,and is thinking about higher studies. However, he first needs to appear in anexam whose preparation alone includes memorizing the meanings of over 3500words! After going through the list afew times, however, he sees troub…
#include <iostream> #include <stdio.h> #include <cstring> #include <math.h> #define MAX 100010 using namespace std; int n,k; long double fac[MAX]; void GetFacs() { ;i<MAX;i++) { fac[i] = fac[i-] + log((long double)i); } } double…
题目链接: http://vjudge.net/problem/viewProblem.action?id=42000 该过程为随即过程,因此总期望值等于个单词对应的期望值,即它们wasted的概率 #include <stdio.h> #include <cstring> #include <cstdlib> #include <algorithm> #include <cmath> using namespace std; #define l…
题目大意:给你N个单词,有两种方法随机排列,一种随机排成一行,另一种随机排成一圈,当两个单词之间的距离在两种排列中都严格小于K时,则这两个单词构成无效单词,问无效单词的期望. 解题思路:首先对于一排单词的每个单词,取出距离它为K的单词,然后把取出的单词放到环形序列的这个单词的两边 如果我们能分别算出1-n的有效概率,那么就等于算出了无效概率 其中 x为当前单词的左右距离为k的单词的个数, 分子是把一排单词中一个单词的有效距离的单词取出来全排列到环形的无效距离内,然后剩余的单词全排列: 考虑到排列…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1696 10755 - Garbage Heap Time limit: 3.000 seconds Garbage Heap Time limit: 3.000 seconds Memory limit: 64 megabytes Farmer John has a heap of garb…
Maximum Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83008#problem/J Description Ron likes to play with integers. Recently he is interested in a game where some integers are given and he is…
题意:有个长方体由A*B*C组成,每个废料都有一个价值,要选一个子长方体,使得价值最大. 析:我们暴力枚举上下左右边界,然后用前缀和来快速得到另一个,然后就能得到长方体,每次维护一个最小值,然后差就是最大值. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #incl…
题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是行和列的,然后再算对角线,对角线是从2-min(m, n)的, 然后就能算出来. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <strin…
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <queue> #include <map> #include <set> #include <ctime> #include <cm…
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Example 1: Input: k = 3, n = 7 Output: [[1,2,4]] Example 2: Input: k = 3, n…