BestCoder Round #38 (2/4)

A

Four Inages Strategy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 352    Accepted Submission(s): 142


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
 

Source
BestCoder Round #38 ($)
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5209  5208  5205  5204  5203 
题目大意是求空间四个点是否能构成正方形  数据都是int型的
解题思路:求六条边的长度,排序 满足前4条边相等,后2条边相等,且为前面4条边的2倍。(这里取得都是平方)

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

ll x1,y1,z1;
ll x2,y2,z2;
ll x3,y3,z3;
ll x4,y4,z4;
ll getlen(ll a,ll b){
return (a-b)*(a-b);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t;
cin>>t;
int cnt=0;
int mark=0;
while(t--){
cnt++;
cin>>x1>>y1>>z1>>x2>>y2>>z2>>x3>>y3>>z3>>x4>>y4>>z4;
ll d1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
ll d2=(x2-x4)*(x2-x4)+(y2-y4)*(y2-y4)+(z2-z4)*(z2-z4);
ll d3=(x4-x3)*(x4-x3)+(y4-y3)*(y4-y3)+(z4-z3)*(z4-z3);
ll d4=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)+(z1-z3)*(z1-z3);
ll d5=getlen(x1,x4)+getlen(y1,y4)+getlen(z1,z4);
ll d6=getlen(x2,x3)+getlen(y2,y3)+getlen(z2,z3);
vector<ll>V;
V.push_back(d1);
V.push_back(d2);
V.push_back(d3);
V.push_back(d4);
V.push_back(d5);
V.push_back(d6);
sort(V.begin(),V.end());
if(V[0]==V[1]&&V[1]==V[2]&&V[2]==V[3]&&V[4]==V[5]&&V[5]==2*V[0])
{
printf("Case #%d: Yes\n",cnt);
}
else
{
printf("Case #%d: No\n",cnt);
}
}
return 0;
}


B

Greatest Greatest Common Divisor

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 386    Accepted Submission(s): 168


Problem Description
Pick two numbers  ai,aj(ij)  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 1T100,2n105,1ai105 . The case for  n104  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
 

Source
BestCoder Round #38 ($)
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5209  5208  5205  5204  5203 
题目大意求数组中两个数的最大公约数的最大值
暴力枚举公约数

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 100000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b)
{
return a>b;
}
int v[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int t,n,m,a;
cin>>t;
int cnt=0;
while(t--){
cnt++;
cle(v);
m=-INF;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a);
v[a]++;
m=max(a,m);
}
for(int i=1;i<=m;i++)//枚举公约数
for(int j=i+i;j<=m;j+=i){
v[i]+=v[j]; //记录公约数为i的个数
}
for(int i=m;i>=1;i--){
if(v[i]>=2){
printf("Case #%d: %d\n",cnt,i);break;
}
}
}
return 0;
}


你可能感兴趣的:(BestCoder Round #38 (2/4))