您的位置:首页 > 其它

河南多校--可怜张继科没夺冠【打表--素数筛法--搜索--数学---物理】

2016-08-13 18:46 537 查看
PS:

一些小牢骚---

想搞好ACM---

你不仅要会---数据结构--图论--DP---数论---各种定理----

你还要会各种----DP优化----状态压缩------

你更要精通---数学---物理---英语---

-----要上知天文---下知地理----

要不然,给你个题,你都不知道是让干嘛呢---

啊---好烦好烦-.-我要出去玩-.-

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


打表---

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<algorithm>
using namespace std;
#define LL long long
int shu[6000000];
LL he[6000000];
int main()
{
memset(shu,0,sizeof(shu));
for (int i=2;i<5000100;i++)
{
if (!shu[i])
{
for (LL k=i;k<5000100;k*=i)
{
for (int j=k;j<5000100;j+=k)
shu[j]++;
}
}
}
he[0]=0;he[1]=0;
for (int i=2;i<5000100;i++)
he[i]=he[i-1]+shu[i];
int t;scanf("%d",&t);
while (t--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%lld\n",he[a]-he);
}
return 0;
}


D - D
[b]Time Limit:
3000MS     Memory Limit:0KB     64bit IO Format:%lld
& %llu
Submit Status Practice UVA
10200 

uDebug


Description



素数筛法判断素数---

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int fafe[20200];
int  shu[10100];
int zhao(int xx)
{
for (int i=0;shu[i]*shu[i]<=xx;i++)
if (xx%shu[i]==0)
return false;
return true;
}
int main()
{
int a,b;int kp=0;
memset(fafe,true,sizeof(fafe));
for (int i=2;i<=20000;i++)
{
if (fafe[i])
{
shu[kp++]=i;
for (int j=i*i;j<=20000;j+=i)
fafe[j]=false;
}
}
while (~scanf("%d%d",&a,&b))
{
int s=0;
for (int i=a;i<=b;i++)
if (zhao(i*i+i+41))
s++;
double aa=(b-a+1),bb=s*10000,ans;
ans=bb/aa;
int op=int(ans+0.5);
ans=double(op)/100;
printf("%.2lf\n",ans);

}
}


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:
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

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


Hint

In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red).

51nod oj 1416 两点


题目来源: CodeForces

基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题


 收藏


 关注

福克斯在玩一款手机解迷游戏,这个游戏叫做”两点”。基础级别的时候是在一个n×m单元上玩的。像这样:



 

每一个单元有包含一个有色点。我们将用不同的大写字母来表示不同的颜色。

这个游戏的关键是要找出一个包含同一颜色的环。看上图中4个蓝点,形成了一个环。一般的,我们将一个序列 d1,d2,...,dk 看成一个环,当且仅当它符合下列条件时:

1.    这k个点不一样,即当 i≠j时, di 和 dj不同。

2.    k至少是4。

3.    所有的点是同一种颜色。

4.    对于所有的 1≤i≤k-1: di 和 di+1 是相邻的。还有 dk 和 d1 也应该相邻。单元 x 和单元 y 是相邻的当且仅当他们有公共边。

当给出一幅格点时,请确定里面是否有环。

Input
单组测试数据。
第一行包含两个整数n和m (2≤n,m≤50):板子的行和列。
接下来n行,每行包含一个有m个字母的串,表示当前行每一个点的颜色。每一个字母都是大写字母。


Output
如果有环输出Yes,否则输出No。


Input示例
3 4
AAAA
ABCA
AAAA
3 4
AAAA
ABCA
AADA


Output示例
YesNo


这两题一样---

分方向之搜索--不从出发点回来就行啦

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char ma[60][60];
bool fa[60][60];
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
bool opop;
void dfs(int ii,int jj,int x,int y,int ww,int pp,int qx,int qy)
{
//	printf("%d  %d   %c      %d   %d     %c \n",qx,qy,ma[qx][qy],x,y,ma[x][y]);
if (x==ii&&y==jj&&(ww!=qx||pp!=qy))
{
//		printf("%d %d        %d  %d 555555\n",x,y,qx,qy);
opop=true;
return ;
}
if (opop) return ;
if (fa[x][y]) return;
fa[x][y]=true;
for (int i=0;i<4;i++)
{
int a=x+xx[i];
int b=y+yy[i];
if (ma[a]==ma[qx][qy])
dfs(ii,jj,a,b,ww,pp,x,y);
}
}
int zhao(int ii,int jj)
{
int a,b;
for (int i=0;i<4;i++)
{
a=ii+xx[i];
b=jj+yy[i];
if (ma[ii][jj]==ma[a][b])
{
memset(fa,false,sizeof(fa));
opop=false;fa[ii][jj]=true;
dfs(ii,jj,a,b,a,b,a,b);
if (opop)
{
//		printf("%d %d   999\n",a,b);
return true;
}

}
}
return false;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
memset(ma,0,sizeof(ma));
for (int i=1;i<=n;i++)
scanf("%s",ma[i]+1);
bool fafe=false;
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{

if (zhao(i,j))
{
fafe=true;
//		printf("%d  %d  5666\n",i,j);
}
if (fafe) break;
}
if (fafe) break;
}
if (fafe)
printf("Yes\n");
else
printf("No\n");
return 0;
}


H - H
[b]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

平行四边形的数量---

求平行边的对数---再/2---

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
int x,y;
}dian[1010];
bool cmp(node xx,node yy)
{
if (xx.x!=yy.x)
return xx.x<yy.x;
return xx.y<yy.y;
}
struct nn{
int gx,gy;
int a,b;
}lu[600000];
bool cmp1(nn xx,nn yy)
{
if (xx.gx!=yy.gx)
return xx.gx<yy.gx;
return xx.gy<yy.gy;
}
void s(int ca)
{
int n,kp;
scanf("%d",&n);
for (int i=0;i<n;i++)
scanf("%d%d",&dian[i].x,&dian[i].y);
sort(dian,dian+n,cmp);
kp=0;
for (int i=0;i<n-1;i++)
for (int j=i+1;j<n;j++)
{
lu[kp].a=i;lu[kp].b=j;
lu[kp].gx=dian[i].x-dian[j].x;
lu[kp++].gy=dian[i].y-dian[j].y;
}
sort(lu,lu+kp,cmp1);
long long s=0;
for (int i=0;i<kp;i++)
{
for (int j=i+1;j<kp;j++)
{
if (lu[i].gx!=lu[j].gx||lu[i].gy!=lu[j].gy)
break;
if (lu[i].a!=lu[j].a&&lu[i].a!=lu[j].b&&lu[i].b!=lu[j].a&&lu[i].b!=lu[j].b)
s++;
}
}
/*int kai=0;
lu[kp].gx=0;lu[kp].gy=0;
for (int i=1;i<=kp;i++)
{
if (lu[i].gx!=lu[i-1].gx||lu[i].gy!=lu[i-1].gy)
{
if (i-kai>1)
{
s+=(i-kai)*(i-kai-1)/2;
}
kai=i;
}
}*/
s/=2;
printf("Case %d: %lld\n",ca,s);
}
int main()
{
int t;scanf("%d",&t);
for (int i=1;i<=t;i++)
s(i);
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 than0.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<cstdio>
#include<cstring>
#include<algorithm>
#include<algorithm>
using namespace std;
int main()
{
int t;scanf("%d",&t);
for (int ca=1;ca<=t;ca++)
{
int n;scanf("%d",&n);
/*if (n==1||n==2)
{
printf("Case %d: 2\n",ca);
continue;
}*/
double i,s=1.0;
int ans=0;
for (i=1.0;i;i=i+1.0)
{
s=s*double(n-i)/(double)n;
if (s<=0.5)
{
ans=int(i);
break;
}
}
printf("Case %d: %d\n",ca,ans);
}
return 0;
}


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.


Sample 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


Sample 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.


物理之动能定理----

应该会吧???

不会看看高中的书--

代码”:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
using namespace std;
int main()
{
double k,l,s,w,g=9.81,v,vv;
while (~scanf("%lf%lf%lf%lf",&k,&l,&s,&w),k+l+s+w)
{
if (s<=l)
{
v=sqrt(2*g*s);
if (v<=10.0)
printf("James Bond survives.\n");
else
printf("Killed by the impact.\n");
}
else
{
v=sqrt(2*l*g);
s=s-l;
double mgh=w*g*s;
double ll=0.5*k*s*s;
if (ll>mgh)
{

double kpkp=0.5*w*v*v;
if (ll-mgh>kpkp)
printf("Stuck in the air.\n");
else
{
vv=sqrt(v*v-(ll-mgh)*2.0/w);
//	printf("%lf   66\n",vv);
if (vv>10.0)
printf("Killed by the impact.\n");
else
printf("James Bond survives.\n");
}
}
else
{
vv=sqrt(v*v+(mgh-ll)*2.0/w);
if (vv>10.0)
printf("Killed by the impact.\n");
else
printf("James Bond survives.\n");
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: