可怜张继科没夺冠

B - B
Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  HDU 4815

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
#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;
}

C -  C
Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  CodeForces 546D

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
#include
#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	{
		if(is[i])
		{
			prime[p++]=i;
			for(int j=2*i;j			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;
}
D - D
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit  Status  Practice  UVA 10200  uDebug

Description

区间素数概率判定(高精度)

时间: 2016-08-14 16:16:31      阅读: 12      评论: 0      收藏: 0       [点我收藏+]

标签:

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
#include
#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 {
if(!pri[i])
{
for(j=2*i;j 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;

}

E - E
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  CodeForces 510B

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:

  1. These k dots are different: if i ≠ j then di is different from dj.
  2. k is at least 4.
  3. All dots belong to the same color.
  4. For all 1 ≤ i ≤ k - 1di 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

Input
3 4
AAAA
ABCA
AAAA
Output
Yes
Input
3 4
AAAA
ABCA
AADA
Output
No
Input
4 4
YYYR
BYBY
BBBY
BBBY
Output
Yes
Input
7 6
AAAAAB
ABBBAB
ABAAAB
ABABBB
ABAAAB
ABBBAB
AAAAAB
Output
Yes
Input
2 13
ABCDEFGHIJKLM
NOPQRSTUVWXYZ
Output
No
#include
#include
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=0&&ay {
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 scanf("%s",map[i]);

yes=0;
for(i=0;i for(j=0;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;
}


G - G
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  CodeForces 508C

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 mtr (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 ≤ m1 ≤ 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

Input
1 8 3
10
Output
3
Input
2 10 1
5 8
Output
1
Input
1 1 3
10
Output
-1
num[i]记录i时刻亮着的蜡烛数,如果小于i时刻需要的蜡烛r,则需要点燃need=r-num[i]个蜡烛,对于新点燃的这些蜡烛,在i时刻时最初点燃的已经亮了need时间,还能再亮t-need时间,所以在[i,i+t-need]时刻都在亮,对应时刻num加need,在继续往后每秒就会有一个蜡烛熄灭,从j=1开始,每次还有need-j个蜡烛亮
#include
#include
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 num[a[i]+t-need+j]=need-j;
}
}
printf("%d\n",ans);
}
return 0;
}

                                                                                                                                H - H
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit  Status  Practice  LightOJ 1058  uDebug

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

中点相同的两条线段可以组成一个平行四边形,所以记录每条边的中点,中点相同的可以互相组成平行四边形


Select Al1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include
#include
using namespace std;
struct node{
	double x,y;
}num[1010*1010];
int a[1010],b[1010];
bool cmp(node a,node b)
{
	if(a.x==b.x)
	return a.y>b.y;
	return a.x>b.x;
}
int main()
{
	int t,n,i,j,ans,sum,ant;
	scanf("%d",&t);
	int l=1;
	while(t--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]);
		ans=0;
		for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		{
			num[ans].x=(a[i]+a[j])*1.0/2;
			num[ans++].y=(b[i]+b[j])*1.0/2;
		}
		sort(num,num+ans,cmp);
		sum=0;
		ant=1;
		for(i=0;i<ans;i++)
		{
			if(num[i].x==num[i+1].x&&num[i].y==num[i+1].y)
			{
				ant++;
			}
			else
			{
				sum+=ant*(ant-1)/2;
				ant=1;
			}
		}
		printf("Case %d: %d\n",l++,sum);
	}
	return 0;


    
    
      
      
      
      
I - I
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu
Submit  Status  Practice  LightOJ 1104  uDebug

Description

Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two people in the party have same birthday? Surprisingly the result is more than 0.5. Now here you have to do the opposite. You have given the number of days in a year. Remember that you can be in a different planet, for example, in Mars, a year is 669 days long. You have to find the minimum number of people you have to invite in a party such that the probability of at least two people in the party have same birthday is at least 0.5.

Input

Input starts with an integer T (≤ 20000), denoting the number of test cases.

Each case contains an integer n (1 ≤ n ≤ 105) in a single line, denoting the number of days in a year in the planet.

Output

For each case, print the case number and the desired result.

Sample Input

2

365

669

Sample Output

Case 1: 22

Case 2: 30

求任何两个人生日都不相同的概率

#include
int main()
{
	int t,n,m,sum;
	scanf("%d",&t);
	int l=1;
	while(t--)
	{
		scanf("%d",&n);
		double s=1.0;
		sum=0;
		for(int i=1;i<=n;i++)
		{
			s*=1.0*(n-i)/n;
			sum++;
			if(s<=0.5)
			break;
		}
		printf("Case %d: %d\n",l++,sum-1);
	}
	return 0;
}

  • LOGOUT
  • 2664836046
    • UP

J - J
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  HDU 1155

Description

Once again, James Bond is fleeing from some evil people who want to see him dead. Fortunately, he has left a bungee rope on a nearby highway bridge which he can use to escape from his enemies. His plan is to attach one end of the rope to the bridge, the other end of the rope to his body and jump off the bridge. At the moment he reaches the ground, he will cut the rope, jump into his car and be gone. 

Unfortunately, he had not had enough time to calculate whether the bungee rope has the right length, so it is not clear at all what is going to happen when he jumps off the bridge. There are three possible scenarios: 
The rope is too short (or too strong), and James Bond will never reach the ground. 
The rope is too long (or too weak), and James Bond will be going too fast when he touches the ground. Even for a special agent, this can be very dangerous. You may assume that if he collides at a speed of more than 10 m/s, he will not survive the impact. 
The rope's length and strength are good. James Bond touches the ground at a comfortable speed and can escape. 
As his employer, you would like to know whether James Bond survives or whether you should place a job ad for the soon-to-be vacant position in the local newspaper. Your physicists claim that: 
The force with which James is pulled towards the earth is 
9.81 * w, 
where w is his weight in kilograms and 9.81 is the Earth acceleration in meters over squared seconds. 
Mr. Bond falls freely until the rope tautens. Then the force with which the bungee rope pulls him back into the sky depends on the current length of the rope and is 
k * Δl, 
where Δl is the difference between the rope's current length and its nominal, unexpanded length, and k is a rope-specific constant. 
Given the rope's strength k, the nominal length of the rope l in meters, the height of the bridge s in meters, and James Bond's body weight w, you have to determine what is going to happen to our hero. For all your calculations, you may assume that James Bond is a point at the end of the rope and the rope has no mass. You may further assume that k, l, s, and w are non-negative and that s < 200. 

The input contains several test cases, one test case per line. Each test case consists of four floating-point numbers (k, l, s, and w) that describe the situation. Depending on what is going to happen, your program must print "Stuck in the air.", "Killed by the impact.", or "James Bond survives.". Input is terminated by a line containing four 0s, this line should not be processed.

Input

350 20 30 75
375 20 30 75
400 20 30 75
425 20 30 75
450 20 30 75
400 20 30 50
400 20 30 80
400 20 30 85
0 0 0 0

Output

Killed by the impact.
James Bond survives. 
James Bond survives. 
James Bond survives. 
Stuck in the air.
Stuck in the air.
James Bond survives. 
Killed by the impact.
  • LOGOUT
  • 2664836046
    • UP#include
#include
#include
int main()
{
	double k,l,s,w;
	while(scanf("%lf%lf%lf%lf",&k,&l,&s,&w)&&(k||l||s||w))
	{
		if(l>=s)
		{
			if(9.81*2*s>100.0)
			printf("Killed by the impact.\n");
			else
			printf("James Bond survives.\n");
		}
		else if(9.81*w*s<0.5*k*(s-l)*(s-l))
		printf("Stuck in the air.\n");
		else
		{
			 double v=9.81*2*s*w-k*(s-l)*(s-l);
			if(v>w*100.0)
			printf("Killed by the impact.\n");
			else
			printf("James Bond survives.\n");
		}
	}
	return 0;
}
























  • LOGOUT
  • 2664836046
    • UPDATE
2664836046 's source code for  H
Memory: 17036 KB   Time: 904 MS
Language: C++   Result: Accepted
VJ RunId: 6886582    
     
Private Public
Select All
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include
#include
using namespace std;
struct node{
	double x,y;
}num[1010*1010];
int a[1010],b[1010];
bool cmp(node a,node b)
{
	if(a.x==b.x)
	return a.y>b.y;
	return a.x>b.x;
}
int main()
{
	int t,n,i,j,ans,sum,ant;
	scanf("%d",&t);
	int l=1;
	while(t--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		scanf("%d%d",&a[i],&b[i]);
		ans=0;
		for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		{
			num[ans].x=(a[i]+a[j])*1.0/2;
			num[ans++].y=(b[i]+b[j])*1.0/2;
		}
		sort(num,num+ans,cmp);
		sum=0;
		ant=1;
		for(i=0;i<ans;i++)
		{
			if(num[i].x==num[i+1].x&&num[i].y==num[i+1].y)
			{
				ant++;
			}
			else
			{
				sum+=ant*(ant-1)/2;
				ant=1;
			}
		}
		printf("Case %d: %d\n",l++,sum);
	}
	return 0;
}

FAQ | About |  Google Group |  Discuss |  Author 
All Copyright Reserved ©2010-2016  HUST ACM/ICPC TEAM 
Server Time: 

你可能感兴趣的:(大学刷题)