Description
A crowd of little animals is visiting a mysterious laboratory – The Deep Lab of SYSU.
“Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recognition project of Google and academia? Are you curious about what technology is behind those fantastic demos?” asks the director of the Deep Lab. “Deep learning, deep learning!” Little Tiger raises his hand briskly. “Yes, clever boy, that’s deep learning (深度学习/深度神经网络)”, says the director. “However, they are only ‘a piece of cake’. I won’t tell you a top secret that our lab has invented a Deep Monkey (深猴) with more advanced technology. And that guy is as smart as human!”
“Nani ?!” Little Tiger doubts about that as he is the smartest kid in his kindergarten; even so, he is not as smart as human, “how can a monkey be smarter than me? I will challenge him.”
To verify their research achievement, the researchers of the Deep Lab are going to host an intelligence test for Little Tiger and Deep Monkey.
The test is composed of N binary choice questions. And different questions may have different scores according to their difficulties. One can get the corresponding score for a question if he chooses the correct answer; otherwise, he gets nothing. The overall score is counted as the sum of scores one gets from each question. The one with a larger overall score wins; tie happens when they get the same score.
Little Tiger assumes that Deep Monkey will choose the answer randomly as he doesn’t believe the monkey is smart. Now, Little Tiger is wondering “what score should I get at least so that I will not lose in the contest with probability of at least P? ”. As little tiger is a really smart guy, he can evaluate the answer quickly.
You, Deep Monkey, can you work it out? Show your power!�
Input
The first line of input contains a single integer T (1 ≤ T ≤ 10) indicating the number of test cases. Then T test cases follow.
Each test case is composed of two lines. The first line has two numbers N and P separated by a blank. N is an integer, satisfying 1 ≤ N ≤ 40. P is a floating number with at most 3 digits after the decimal point, and is in the range of [0, 1]. The second line has N numbers separated by blanks, which are the scores of each question. The score of each questions is an integer and in the range of [1, 1000]�
Output
For each test case, output only a single line with the answer.
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<stdio.h>
#include<string.h>
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<n*1000;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;
}
C -
C
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
Input
2
3 1
6 3
Output
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<stdio.h>
#include<string.h>
#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<MAX;i++)
{
if(is[i])
{
prime[p++]=i;
for(int j=2*i;j<MAX;j+=i)
is[j]=0;
}
}
}
int main()
{
seive();
for(int i=2;i<MAX;i++)
{
if(is[i])
{
dp[i]=1;
continue;
}
for(int j=0;j<MAX;j++)
{
if(i%prime[j]==0)
{
dp[i]=dp[i/prime[j]]+1;
break;
}
}
}
for(int i=3;i<MAX;i++)
dp[i]+=dp[i-1];
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%I64d\n",dp[b]-dp[a]);
}
return 0;
}
Description
区间素数概率判定(高精度)
Description
“Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recognition project of Google and academia? Are you curious about what technology is behind those fantastic demos?” asks the director of the Deep Lab. “Deep learning, deep learning!” Little Tiger raises his hand briskly. “Yes, clever boy, that’s deep learning (深度学习/深度神经网络)”, says the director. “However, they are only ‘a piece of cake’. I won’t tell you a top secret that our lab has invented a Deep Monkey (深猴) with more advanced technology. And that guy is as smart as human!”
“Nani ?!” Little Tiger doubts about that as he is the smartest kid in his kindergarten; even so, he is not as smart as human, “how can a monkey be smarter than me? I will challenge him.”
To verify their research achievement, the researchers of the Deep Lab are going to host an intelligence test for Little Tiger and Deep Monkey.
The test is composed of N binary choice questions. And different questions may have different scores according to their difficulties. One can get the corresponding score for a question if he chooses the correct answer; otherwise, he gets nothing. The overall score is counted as the sum of scores one gets from each question. The one with a larger overall score wins; tie happens when they get the same score.
Little Tiger assumes that Deep Monkey will choose the answer randomly as he doesn’t believe the monkey is smart. Now, Little Tiger is wondering “what score should I get at least so that I will not lose in the contest with probability of at least P? ”. As little tiger is a really smart guy, he can evaluate the answer quickly.
You, Deep Monkey, can you work it out? Show your power!�
Input
Each test case is composed of two lines. The first line has two numbers N and P separated by a blank. N is an integer, satisfying 1 ≤ N ≤ 40. P is a floating number with at most 3 digits after the decimal point, and is in the range of [0, 1]. The second line has N numbers separated by blanks, which are the scores of each question. The score of each questions is an integer and in the range of [1, 1000]�
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<stdio.h> #include<string.h> 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<n*1000;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<stdio.h>
#include<string.h>
#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<MAX;i++)
{
if(is[i])
{
prime[p++]=i;
for(int j=2*i;j<MAX;j+=i)
is[j]=0;
}
}
}
int main()
{
seive();
for(int i=2;i<MAX;i++)
{
if(is[i])
{
dp[i]=1;
continue;
}
for(int j=0;j<MAX;j++)
{
if(i%prime[j]==0)
{
dp[i]=dp[i/prime[j]]+1;
break;
}
}
}
for(int i=3;i<MAX;i++)
dp[i]+=dp[i-1];
int t;
scanf("%d",&t);
while(t--)
{
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.
Sample Input
0 39
0 40
39 40
Sample Output
100.00
97.56
50.00
错了好多次,最后发现问题是出在后面的精度问题上了,结果要加上1e-5,四舍五入,为什么是1e-5,因为题目重要保留四位小数
#include<string.h>
#define MAX 100000000+100000
int pri[MAX];
int dp[10010];
void fas()
{
int i,j;
memset(pri,0,sizeof(pri));
pri[1]=1;
for(i=2;i*i<MAX;i++)
{
if(!pri[i])
{
for(j=2*i;j<MAX;j+=i)
pri[j]=1;
}
}
}
void abs()
{
int i,sum;
dp[0]=1;
for(i=1;i<=10000;i++)
{
dp[i]=dp[i-1];
sum=i*i+i+41;
if(!pri[sum])
dp[i]++;
}
}
int main()
{
int a,b;
fas();
abs();
while(~scanf("%d%d",&a,&b))
{
if(a==0)
printf("%.2lf\n",1.0*dp[b]/(b+1)*100+1e-5);
else
printf("%.2lf\n",1.0*(dp[b]-dp[a-1])/(b+1-a)*100+1e-5);
}
return 0;
}
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:
- These k dots are different: if i ≠ j then di is different from dj.
- k is at least 4.
- All dots belong to the same color.
- For all 1 ≤ i ≤ k - 1: di and di + 1 are adjacent. Also, dk and d1 should also be adjacent. Cells x and y are called adjacent if they share an edge.
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
#include<string.h>
int n,m;
int visit[55][55];
char map[55][55];
int yes;
int move[4][2]={0,1,0,-1,1,0,-1,0};
void dfs(int x,int y,int a,int b)
{
if(yes)
return ;
for(int i=0;i<4;i++)
{
int ax=x+move[i][0];
int ay=y+move[i][1];
if(ax>=0&&ax<n&&ay>=0&&ay<m&&map[x][y]==map[ax][ay]&&(ax!=a||ay!=b))
{
if(visit[ax][ay])
{
yes=1;
return;
}
visit[ax][ay]=1;
dfs(ax,ay,x,y);
}
}
}
int main()
{
int i,j;
while(~scanf("%d%d",&n,&m))
{
for(i=0;i<n;i++)
scanf("%s",map[i]);
yes=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
memset(visit,0,sizeof(visit));
visit[i][j]=1;
dfs(i,j,i,j);
if(yes)
break;
}
if(yes)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
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
#include<stdio.h>
#include<string.h>
int main()
{
int m,t,r,i,j,ans,need;
int num[1010],a[1010];
while(~scanf("%d%d%d",&m,&t,&r))
{
memset(num,0,sizeof(num));
for(i=1;i<=m;i++)
scanf("%d",&a[i]);
if(r>t)
{
printf("-1\n");
continue;
}
ans=0;
for(i=1;i<=m;i++)
{
need=r-num[a[i]];
if(need>0)
{
ans+=need;
for(j=0;j<=t-need;j++)
num[a[i]+j]+=need;
for(j=1;j<need;j++)
num[a[i]+t-need+j]=need-j;
}
}
printf("%d\n",ans);
}
return 0;
}
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 | ||
FAQ | About | Google Group | Discuss | Author
All Copyright Reserved ©2010-2016 HUST ACM/ICPC TEAM
Server Time: