PS:
一些小牢骚---
想搞好ACM---
你不仅要会---数据结构--图论--DP---数论---各种定理----
你还要会各种----DP优化----状态压缩------
你更要精通---数学---物理---英语---
-----要上知天文---下知地理----
要不然,给你个题,你都不知道是让干嘛呢---
啊---好烦好烦-.-我要出去玩-.-
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
打表---
代码:
#include
#include
#include
#include
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[b]);
}
return 0;
}
Description
素数筛法判断素数---
代码:
#include
#include
#include
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);
}
}
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
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).
福克斯在玩一款手机解迷游戏,这个游戏叫做”两点”。基础级别的时候是在一个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 是相邻的当且仅当他们有公共边。
当给出一幅格点时,请确定里面是否有环。
单组测试数据。 第一行包含两个整数n和m (2≤n,m≤50):板子的行和列。 接下来n行,每行包含一个有m个字母的串,表示当前行每一个点的颜色。每一个字母都是大写字母。
如果有环输出Yes,否则输出No。
3 4 AAAA ABCA AAAA 3 4 AAAA ABCA AADA
Yes No
这两题一样---
分方向之搜索--不从出发点回来就行啦
代码:
#include
#include
#include
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][b]==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;
}
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
#include
#include
using namespace std;
struct node{
int x,y;
}dian[1010];
bool cmp(node xx,node yy)
{
if (xx.x!=yy.x)
return xx.x1)
{
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;
}
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
#include
#include
#include
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;
}
Description
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
#include
#include
#include
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;
}