BC #38

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

数组中两个数公约数的最大值 

#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;
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值