B - B 圆周率用acos(-1.0) 使用longlong


Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu


Submit  ​​Status​​​  ​​​Practice​​​  ​​​LightOJ 1305​​​  ​​​uDebug​


Description



A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:

Fig: a parallelogram

Now you are given the co ordinates of A, B and C, you have to find the coordinates of D and the area of the parallelogram. The orientation of ABCDshould be same as in the picture.



Input



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

Each case starts with a line containing six integers Ax, Ay, Bx, By, Cx, Cy where (Ax, Ay) denotes the coordinate of A(Bx, By) denotes the coordinate of B and (Cx, Cy) denotes the coordinate of C. Value of any coordinate lies in the range [-1000, 1000]. And you can assume that A, B andC will not be collinear.



Output



For each case, print the case number and three integers where the first two should be the coordinate of D and the third one should be the area of the parallelogram.



Sample Input



3

0 0 10 0 10 10

0 0 10 0 10 -20

-12 -10 21 21 1 40



Sample Output



Case 1: 0 10 100

Case 2: 0 -20 200

Case 3: -32 9 1247



向量叉积求平行四边形的面积---


代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int x[10],y[10];
int inin()
{
x[6]=x[1]-x[0];y[6]=y[1]-y[0];
x[7]=x[2]-x[1];y[7]=y[2]-y[1];
int lp=x[6]*y[7]-x[7]*y[6];
if (lp<0)
lp=-lp;
return lp;
}
int main()
{
int n;scanf("%d",&n);
for (int ca=1;ca<=n;ca++)
{
for (int i=0;i<3;i++)
scanf("%d%d",&x[i],&y[i]);
x[3]=x[0]-x[1]+x[2];
y[3]=y[0]-y[1]+y[2];
int ans=0;
ans=inin();
printf("Case %d: %d %d %d\n",ca,x[3],y[3],ans);
}
return 0;
}



F - F 圆周率用acos(-1.0) 使用longlong


Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu


Submit  ​​Status​​​  ​​​Practice​​​  ​​​LightOJ 1331​​​  ​​​uDebug​


Description



Agent J is preparing to steal an antique diamond piece from a museum. As it is fully guarded and they are guarding it using high technologies, it's not easy to steal the piece. There are three circular laser scanners in the museum which are the main headache for Agent J. The scanners are centered in a certain position, and they keep rotating maintaining a certain radius. And they are placed such that their coverage areas touch each other as shown in the picture below:

Here R1R2 and R3 are the radii of the coverage areas of the three laser scanners. The diamond is placed in the place blue shaded region as in the picture. Now your task is to find the area of this region for Agent J, as he needs to know where he should land to steal the diamond.



Input



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

Each case starts with a line containing three real numbers denoting R1, R2 and R3 (0 < R1, R2, R3 ≤ 100). And no number contains more than two digits after the decimal point.



Output



For each case, print the case number and the area of the place where the diamond piece is located. Error less than 10-6 will be ignored.



Sample Input



3

1.0 1.0 1.0

2 2 2

3 3 3



Sample Output



Case 1: 0.16125448

Case 2: 0.645017923

Case 3: 1.4512903270



三角形的三边求面积---然后根据面积和边求角----

阴影面积=三角形面积-三个扇形面积


代码:

#include<cstdio>
#include<cmath>
#include<cstring>
double pi;
double inin(double aa,double bb,double cc)
{
double s,ans;
s=(aa+bb+cc)/2;
ans=sqrt(s*(s-aa)*(s-bb)*(s-cc));
return ans;
}
double jiao(double aa,double x,double y,double zs)
{
double lp=fabs(asin(2*zs/x/y));
if (aa*aa<=x*x+y*y)
return lp;
else
return pi-lp;
}
/*double ji(double a,double b,double c)
{
printf("%lf 89\n",acos((b*b+c*c-a*a)/2*b*c));
return acos((b*b+c*c-a*a)/2*b*c);
}*/
int main()
{
pi=2.0*acos (0.0);
int t;scanf("%d",&t);
double a,b,c,ans,a1,a2,a3;
for (int ca=1;ca<=t;ca++)
{
scanf("%lf%lf%lf",&a1,&a2,&a3);
a=a2+a3;b=a1+a3;c=a1+a2;
double ss=inin(a,b,c);
double A=jiao(a,b,c,ss);
double B=jiao(b,a,c,ss);
double C=jiao(c,a,b,ss);
/* double A=ji(a,b,c);
double B=ji(b,a,c);
double C=ji(c,b,a);
printf("%lf %lf %lf 666\n",A,B,C);*/
ans=A*a1*a1/2.0+B*a2*a2/2.0+C*a3*a3/2.0;
ans=ss-ans;
printf("Case %d: %.8lf\n",ca,ans);
}
return 0;
}



I - I 圆周率用acos(-1.0) 使用longlong


Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu


Submit  ​​Status​​​  ​​​Practice​​​  ​​​LightOJ 1189​​​  ​​​uDebug​


Description



Given an integer n, you have to find whether it can be expressed as summation of factorials. For given n, you have to report a solution such that

n = x1! + x2! + ... + xn! (xi < xj for all i < j)



Input



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

Each case starts with a line containing an integer n (1 ≤ n ≤ 1018).



Output



For each case, print the case number and the solution in summation of factorial form. If there is no solution then print 'impossible'. There can be multiple solutions, any valid one will do. See the samples for exact formatting.



Sample Input



4

7

7

9

11



Sample Output



Case 1: 1!+3!

Case 2: 0!+3!

Case 3: 1!+2!+3!

Case 4: impossible



Hint



Be careful about the output format; you may get wrong answer for wrong output format.


Problem Setter: Jane Alam Jan



Developed and Maintained by 
JANE ALAM JAN

Copyright © 2012 
LightOJ, Jane Alam Jan



打个N!的表---打到19就行了

然后能取大的就取打的------因为每项相差几倍----N!>(1!+2!+...+(N-1)!)


代码:

#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
#define LL long long
LL shu[1010],n;
int main()
{
int t,a;scanf("%d",&t);
shu[0]=1;
for (int i=1;i<20;i++)
{
shu[i]=shu[i-1]*i;
}
for (int ca=1;ca<=t;ca++)
{
scanf("%lld",&n);
stack<int > sta;
for (int i=19;i>=0;i--)
if (n>=shu[i])
{
sta.push(i);
n-=shu[i];
}
printf("Case %d: ",ca);
if (n==0)
{
bool fafe=true;
int kk;
while (!sta.empty())
{
kk=sta.top();
sta.pop();
if (fafe)
{
printf("%d!",kk);
fafe=false;
}
else
printf("+%d!",kk);
}
printf("\n");
}
else
printf("impossible\n");
}
return 0;
}



J - J 圆周率用acos(-1.0) 使用longlong


Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu


Submit  ​​Status​​​  ​​​Practice​​​  ​​​LightOJ 1307​​​  ​​​uDebug​


Description



You are given N sticks having distinct lengths; you have to form some triangles using the sticks. A triangle is valid if its area is positive. Your task is to find the number of ways you can form a valid triangle using the sticks.



Input



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

Each case starts with a line containing an integer N (3 ≤ N ≤ 2000). The next line contains N integers denoting the lengths of the sticks. You can assume that the lengths are distinct and each length lies in the range [1, 109].



Output



For each case, print the case number and the total number of ways a valid triangle can be formed.



Sample Input



3

5

3 12 5 4 9

6

1 2 3 4 5 6

4

100 211 212 121



Sample Output



Case 1: 3

Case 2: 7

Case 3: 4



确定两边---然后二分查找两边之和的位置----中间的为第三边的个数(边从小到大----)


代码:

#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
#define LL long long
LL shu[2010],s;
int main()
{
int t;scanf("%d",&t);
for (int ca=1;ca<=t;ca++)
{
int n;scanf("%d",&n);
for (int i=0;i<n;i++)
scanf("%lld",&shu[i]);
sort(shu,shu+n);
shu[n]=1111111111000;
s=0;
for (int i=0;i<n-2;i++)
{
for (int j=i+1;j<n-1;j++)
{
int c=shu[i]+shu[j];
int kk=lower_bound(shu,shu+n+1,c)-shu;
s+=kk-j-1;
}
}
printf("Case %d: %lld\n",ca,s);
}
return 0;
}



K - AK前十道后,AC本题才有积分


Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu


Submit  ​​Status​​​  ​​​Practice​​​  ​​​LightOJ 1047​​​  ​​​uDebug​


Description



The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two neighboring houses will be painted the same color. The neighbors of house i are houses i-1 and i+1. The first and last houses are not neighbors.

You will be given the information of houses. Each house will contain three integers "R G B" (quotes for clarity only), where R, G and B are the costs of painting the corresponding house red, green, and blue, respectively. Return the minimal total cost required to perform the work.



Input



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

Each case begins with a blank line and an integer n (1 ≤ n ≤ 20) denoting the number of houses. Each of the next n lines will contain 3 integers "R G B". These integers will lie in the range [1, 1000].



Output



For each case of input you have to print the case number and the minimal cost.



Sample Input



2

 

4

13 23 12

77 36 64

44 89 76

31 78 45

 

3

26 40 83

49 60 57

13 89 99



Sample Output



Case 1: 137

Case 2: 96




代码:

#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
#define LL long long
int shu[25][5],dp[25][5],s;
int main()
{
int t;scanf("%d",&t);
for (int ca=1;ca<=t;ca++)
{
int n;scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d%d%d",&shu[i][1],&shu[i][2],&shu[i][3]);
dp[0][0]=dp[0][1]=dp[0][2]=dp[0][3]=0;
for (int i=1;i<=n;i++)
{
dp[i][1]=min(dp[i-1][2],dp[i-1][3])+shu[i][1];
dp[i][2]=min(dp[i-1][1],dp[i-1][3])+shu[i][2];
dp[i][3]=min(dp[i-1][2],dp[i-1][1])+shu[i][3];
}
printf("Case %d: %d\n",ca,min(min(dp[n][1],dp[n][2]),dp[n][3]));
}
return 0;
}




M - AK前十道后,AC本题才有积分


Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu


Submit  ​​Status​​​  ​​​Practice​​​  ​​​LightOJ 1064​​​  ​​​uDebug​


Description



n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x?



Input



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

Each test case contains two integers n (1 ≤ n < 25) and x (0 ≤ x < 150). The meanings of n and x are given in the problem statement.



Output



For each case, output the case number and the probability in 'p/q' form where p and q are relatively prime. If q equals 1 then print p only.



Sample Input



7

3 9

1 7

24 24

15 76

24 143

23 81

7 38



Sample Output



Case 1: 20/27

Case 2: 0

Case 3: 1

Case 4: 11703055/78364164096

Case 5: 25/4738381338321616896

Case 6: 1/2

Case 7: 55/46656





代码:


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL mu,zi,a,b;
LL dp[30][160];
LL gcd(LL a,LL b)
{
if (b==0)
return a;
return gcd(b,a%b);
}
int main()
{
int t;scanf("%d",&t);
int n,k;
memset(dp,0,sizeof(dp));
dp[1][1]=dp[1][2]=dp[1][3]=dp[1][4]=dp[1][5]=dp[1][6]=1;
for (int i=2;i<=25;i++)
{
for (int j=i;j<=150;j++)
{
for (int k=1;k<=6;k++)
{
if (j-k>0)
dp[i][j]+=dp[i-1][j-k];
}
// printf("%d %d %lld 66\n",i,j,dp[i][j]);
}
}
for (int ca=1;ca<=t;ca++)
{
scanf("%d%d",&n,&k);
mu=1;
for (int i=0;i<n;i++)
mu*=6;
zi=0;
for (int i=1;i<k;i++)
zi+=dp[n][i];
zi=mu-zi;
a=gcd(mu,zi);
mu/=a;
zi/=a;
if (mu==1)
printf("Case %d: %lld\n",ca,zi);
else
printf("Case %d: %lld/%lld\n",ca,zi,mu);
}
return 0;
}




N - AK前十道后,AC本题才有积分


Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu


Submit  ​​Status​​​  ​​​Practice​​​  ​​​LightOJ 1122​​​  ​​​uDebug​


Description



Given a set of digits S, and an integer n, you have to find how many n-digit integers are there, which contain digits that belong to S and the difference between any two adjacent digits is not more than two.



Input



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

Each case contains two integers, m (1 ≤ m < 10) and n (1 ≤ n ≤ 10). The next line will contain m integers (from 1 to 9) separated by spaces. These integers form the set S as described above. These integers will be distinct and given in ascending order.



Output



For each case, print the case number and the number of valid n-digit integers in a single line.



Sample Input



3

3 2

1 3 6

3 2

1 2 3

3 3

1 4 6



Sample Output



Case 1: 5

Case 2: 9

Case 3: 9



Hint



For the first case the valid integers are

11

13

31

33

66


Problem Setter: Jane Alam Jan



Developed and Maintained by 
JANE ALAM JAN

Copyright © 2012 
LightOJ, Jane Alam Jan





代码:

#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
#define LL long long
bool fafe[12];
LL dp[12][12],ans;
int main()
{
int t;scanf("%d",&t);
for (int ca=1;ca<=t;ca++)
{
int n,m,a;scanf("%d%d",&m,&n);
memset(fafe,false,sizeof(fafe));
for (int i=0;i<m;i++)
{
scanf("%d",&a);
fafe[a]=true;
}
memset(dp,0,sizeof(dp));
for (int i=1;i<=9;i++)
if (fafe[i])
dp[1][i]=1;
for (int i=2;i<=n;i++)
{
for (int j=1;j<=9;j++)
{
if (fafe[j])
{
dp[i][j]=0;
for (int k=1;k<=9;k++)
{
if (fafe[k]&&abs(j-k)<=2)
dp[i][j]+=dp[i-1][k];
}
}
}
}
ans=0;
for (int i=1;i<=9;i++)
ans+=dp[n][i];
printf("Case %d: %lld\n",ca,ans);
}
return 0;
}