Description
Input
Output
Sample Input
1 3 0.5 1 2 3
01背包;有n道题,每道题可能答对,也有可能答错,问得多少分它不输的可能性至少P,即赢得可能性大于1-p
dp[i][j]表示第i道题得j分的可能性,dp[0][0]的可能性为1,第i道题答错dp[i][j]+=dp[i-1][j]*0.5;答对
dp[i][j+a[i]+=dp[i-1][j]*0.5;
#include#include double dp[45][41000]; int a[45]; int main() { int t,n,i,j,sum; double p; scanf("%d",&t); while(t--) { scanf("%d%lf",&n,&p); for(i=1;i<=n;i++) scanf("%d",&a[i]); memset(dp,0,sizeof(dp)); dp[0][0]=1; for(i=1;i<=n;i++) for(j=0;j { dp[i][j]+=dp[i-1][j]*0.5; dp[i][j+a[i]]+=dp[i-1][j]*0.5; } double s=0; int sum=0; for(i=n*1000;i>=0;i--) { s+=dp[n][i]; if(s>1-p) { sum=i; break; } } printf("%d\n",sum); } return 0; }
Description
Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed.
To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a ≥ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k.
What is the maximum possible score of the second soldier?
Input
First line of input consists of single integer t (1 ≤ t ≤ 1 000 000) denoting number of games soldiers play.
Then follow t lines, each contains pair of integers a and b (1 ≤ b ≤ a ≤ 5 000 000) defining the value of n for a game.
Output
For each game output a maximum score that the second soldier can get.
Sample Input
2 3 1 6 3
2 5
a!/b!的最大的因子个数,即质因数的个数,即为a*(a-1)*(a-2)*...*(b+1)的质因数的个数,dp[i]表示i能分成的质因数的个数,:如果这个数是素数,则有dp[i] = 1.否则dp[i] = dp[i / j] + 1;(i % j == 0 && j为素数)因为实质上,dp[i]和dp[i / j] 就是多了个素数j;dp[i]再做一下处理,表示为前i个数的质因数和,最终结果极为dp[a]-ap[b];
#include#include { if(is[i]) { prime[p++]=i; for(int j=2*i;j#define MAX 5000005 __int64 dp[MAX]; int is[MAX]; int prime[MAX]; int p; void seive() { memset(is,1,sizeof(is)); for(int i=2;i is[j]=0; } } } int main() { seive(); for(int i=2;i { if(is[i]) { dp[i]=1; continue; } for(int j=0;j { if(i%prime[j]==0) { dp[i]=dp[i/prime[j]]+1; break; } } } for(int i=3;i int a,b; scanf("%d%d",&a,&b); printf("%I64d\n",dp[b]-dp[a]); } return 0; }
Description
区间素数概率判定(高精度)
标签:
Euler is a well-known matematician, and, among many other things, he discovered that the formula n 2 + n + 41 produces a prime for 0 ≤ n < 40. For n = 40, the formula produces 1681, which is 41 ∗ 41. Even though this formula doesn’t always produce a prime, it still produces a lot of primes. It’s known that for n ≤ 10000000, there are 47,5% of primes produced by the formula! So, you’ll write a program that will output how many primes does the formula output for a certain interval. Input Each line of input will be given two positive integer a and b such that 0 ≤ a ≤ b ≤ 10000. You must read until the end of the file. Output For each pair a, b read, you must output the percentage of prime numbers produced by the formula in this interval (a ≤ n ≤ b) rounded to two decimal digits.
0 39
0 40
39 40
100.00
97.56
50.00
错了好多次,最后发现问题是出在后面的精度问题上了,结果要加上1e-5,四舍五入,为什么是1e-5,因为题目重要保留四位小数
}
Description
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size n × m cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots of same color. Consider 4 blue dots on the picture forming a circle as an example. Formally, we call a sequence of dots d1, d2, ..., dk a cycle if and only if it meets the following condition:
Determine if there exists a cycle on the field.
Input
The first line contains two integers n and m (2 ≤ n, m ≤ 50): the number of rows and columns of the board.
Then n lines follow, each line contains a string consisting of m characters, expressing colors of dots in each line. Each character is an uppercase Latin letter.
Output
Output "Yes" if there exists a cycle, and "No" otherwise.
Sample Input
3 4 AAAA ABCA AAAA
Yes
3 4 AAAA ABCA AADA
No
4 4 YYYR BYBY BBBY BBBY
Yes
7 6 AAAAAB ABBBAB ABAAAB ABABBB ABAAAB ABBBAB AAAAAB
Yes
2 13 ABCDEFGHIJKLM NOPQRSTUVWXYZ
No
Description
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.
For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.
What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
Input
The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.
The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
Output
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.
If that is impossible, print - 1.
Sample Input
1 8 3 10
3
2 10 1 5 8
1
1 1 3 10
-1
Description
There are n distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of 4-element subsets of these points that can be written as {A, B, C, D} such that AB || CD, and BC || AD. No four points are in a straight line.
Input
Input starts with an integer T (≤ 15), denoting the number of test cases.
The first line of each test case contains an integer n (1 ≤ n ≤ 1000). Each of the next n lines, contains 2 space-separated integers x and y (the coordinates of a point) with magnitude (absolute value) of no more than 1000000000.
Output
For each case, print the case number and the number of parallelograms that can be formed.
Sample Input
2
6
0 0
2 0
4 0
1 1
3 1
5 1
7
-2 -1
8 9
5 7
1 1
4 8
2 0
9 8
Sample Output
Case 1: 5
Case 2: 6
Memory: 17036 KB | Time: 904 MS | |
Language: C++ | Result: Accepted | |
VJ RunId: 6886582 | ||
Private Public |