Four Inages Strategy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 89 Accepted Submission(s): 28
Problem Description
Young F found a secret record which inherited from ancient times in ancestral home by accident, which named "Four Inages Strategy". He couldn't restrain inner exciting, open the record, and read it carefully. " Place four magic stones at four points as array element in space, if four magic stones form a square, then strategy activates, destroying enemy around". Young F traveled to all corners of the country, and have collected four magic stones finally. He placed four magic stones at four points, but didn't know whether strategy could active successfully. So, could you help him?
Input
Multiple test cases, the first line contains an integer
T
(no more than
10000
), indicating the number of cases. Each test case contains twelve integers
x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,|x|,|y|,|z|≤100000
,representing coordinate of four points. Any pair of points are distinct.
Output
For each case, the output should occupies exactly one line. The output format is Case #
x
:
ans
, here
x
is the data number begins at
1
, if your answer is yes,
ans
is Yes, otherwise
ans
is No.
Sample Input
2 0 0 0 0 1 0 1 0 0 1 1 0 1 1 1 2 2 2 3 3 3 4 4 4
Sample Output
Case #1: Yes Case #2: No
题意就是判断空间中四个点是否能组成一个正方形
注意由于乘法 数据类型要为long long
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>
#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
ll x[4],y[4],z[4];
ll len[10];
ll l(int a,int b)
{
ll ans=(x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])+(z[a]-z[b])*(z[a]-z[b]);
return ans;
}
int main()
{
//fread;
int tc;
scanf("%d",&tc);
int cs=1;
while(tc--)
{
// int x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4;
// scanf("%d%d%d%d%d%d%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2,&x3,&y3,&z3,&x4,&y4,&z4);
for(int i=0;i<4;i++)
scanf("%I64d%I64d%I64d",&x[i],&y[i],&z[i]);
int num=0;
for(int i=0;i<4;i++)
for(int j=i+1;j<4;j++)
{
len[num++]=l(i,j);
}
// cout<<num<<endl;
sort(len,len+num);
printf("Case #%d: ",cs++);
if(len[0]==len[1]&&len[1]==len[2]&&len[2]==len[3]&&len[4]==len[5]&&len[4]==(2*len[0]))
puts("Yes");
else puts("No");
}
return 0;
}
Greatest Greatest Common Divisor
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 191 Accepted Submission(s): 82
Problem Description
Pick two numbers
ai,aj(i≠j)
from a sequence to maximize the value of their greatest common divisor.
Input
Multiple test cases. In the first line there is an integer
T
, indicating the number of test cases. For each test cases, the first line contains an integer
n
, the size of the sequence. Next line contains
n
numbers, from
a1
to
an
.
1≤T≤100,2≤n≤105,1≤ai≤105
. The case for
n≥104
is no more than
10
.
Output
For each test case, output one line. The output format is Case #
x
:
ans
,
x
is the case number, starting from
1
,
ans
is the maximum value of greatest common divisor.
Sample Input
2 4 1 2 3 4 3 3 6 9
Sample Output
Case #1: 2 Case #2: 3
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>
#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 100010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int a[MAXN];
int b[MAXN];
int main()
{
// fread;
int tc;
scanf("%d",&tc);
int cs=1;
while(tc--)
{
int n;
scanf("%d",&n);
int mx=-1;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
mx=max(mx,a[i]);
}
MEM(b,0);
for(int i=0;i<n;i++)
{
for(int j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
b[j]++;
if(j!=(a[i]/j))
b[a[i]/j]++;
}
}
}
// for(int i=1;i<=mx;i++)
// cout<<b[i]<<endl;
int ans;
for(int i=mx;i>=1;i--)
if(b[i]>=2)
{
ans=i;break;
}
printf("Case #%d: %d\n",cs++,ans);
}
return 0;
}