1001 Four Inages Strategy

题意:给定空间的四个点,判断这四个点是否能形成正方形

思路:判断空间上4个点是否形成一个正方形方法有很多,这里给出一种方法,在p2,p3,p4中枚举两个点作为p1的邻点,

不妨设为pi,pj,然后判断p1pi与p1pj是否相等、互相垂直,然后由向量法,最后一个点坐标应该为pi+pj−p1,判断是否相等就好了。

 #include <cstdio>
using namespace std; struct node
{
__int64 x, y, z;
}; node points[];  // 存放四个点坐标 __int64 dist(node a, node b) // 计算两点之间的距离
{
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z);
} bool isVertical(node a, node b) // 判断两个向量是否垂直
{
if (a.x * b.x + a.y * b.y + a.z * b.z == ) return true;
return false;
} bool isSquare(node a, node b, node c, node& p) // 判断是否为等腰直角(成正方形的必要条件)
{
__int64 len1 = dist(a, b);
__int64 len2 = dist(a, c); node d, e;
d.x = b.x - a.x;
d.y = b.y - a.y;
d.z = b.z - a.z;
e.x = c.x - a.x;
e.y = c.y - a.y;
e.z = c.z - a.z; if (len1 == len2 && isVertical(d, e) && len1 != )
{
p.x = b.x + c.x - a.x;
p.y = b.y + c.y - a.y;
p.z = b.z + c.z - a.z;
return true;
} return false;
} bool isEqual(node a, node b) // 判断两个点是否相等
{
if (a.x == b.x && a.y == b.y && a.z == b.z) return true;
return false;
} int main()
{
int nCase;
scanf("%d", &nCase);
for (int cnt = ; cnt <= nCase; ++cnt)
{
scanf("%I64d %I64d %I64d", &points[].x, &points[].y, &points[].z);
scanf("%I64d %I64d %I64d", &points[].x, &points[].y, &points[].z);
scanf("%I64d %I64d %I64d", &points[].x, &points[].y, &points[].z);
scanf("%I64d %I64d %I64d", &points[].x, &points[].y, &points[].z); printf("Case #%d: ", cnt); node p;
if (isSquare(points[], points[], points[], p))
{
if (isEqual(p, points[])) puts("Yes");
else puts("No");
} else if (isSquare(points[], points[], points[], p))
{
if (isEqual(p, points[])) puts("Yes");
else puts("No");
} else if (isSquare(points[], points[], points[], p))
{
if (isEqual(p, points[])) puts("Yes");
else puts("No");
} else puts("No"); }
return ;
}

1002 Greatest Greatest Common Divisor

题意:给定一组数,取两个数,使得gcd最大,求最大gcd值。

思路:用nVisit数组来记录每个数出现的次数,nCount数组来记录每个因子出现的次数。

枚举1—nMax内所有的因子,对任意一个因子i,存在j = k*i,nVisit[j]不为0,那么因子i存在。

我们从后往前找,当首次遇到nCount的值大于等于2的,就是答案。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = ;
int nVisit[MAXN]; // 记录数出现的次数
int nCount[MAXN]; // nCount[i] = x 表示i这个因子出现了x次
int nMax; // 记录数组中最大的数
void solve()
{
for (int i = ; i <= nMax; ++i)
{
for (int j = i; j <= nMax; j += i)
{
// 判断是否有j这个数
if (nVisit[j])
{
// 此时肯定有i这个因子,并求出几个数有i这个因子
nCount[i] += nVisit[j];
}
}
}
} int main()
{
int nCase;
scanf("%d", &nCase);
for (int cnt = ; cnt <= nCase; ++cnt)
{
int n;
scanf("%d", &n); nMax = ;
memset(nVisit, , sizeof(nVisit));
memset(nCount, , sizeof(nCount)); for (int i = ; i < n; ++i)
{
int t;
scanf("%d", &t);
++nVisit[t];
nMax = max(nMax, t);
}
solve();
printf("Case #%d: ", cnt);
for (int i = nMax; i >= ; --i)
{
if (nCount[i] >= )
{
printf("%d\n", i);
break;
}
}
}
return ;
}

BestCoder Round #38的更多相关文章

  1. hdu 5207 BestCoder Round #38 ($) Greatest Greatest Common Divisor

    #include<stdio.h> #include<string.h> #include<math.h> ]; ]; int main() { int sb; s ...

  2. BestCoder Round #14

    Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  4. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  5. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  6. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  7. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  8. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  9. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

随机推荐

  1. Cppcheck软件使用

    一款开源源码检测工具.简单易用. 官网网址:http://cppcheck.sourceforge.net/ 软件可直接官网下载. [plain] view plaincopy Features Ou ...

  2. android加载更多的图片

    这是昨天改进后的,我测试了下,可以加载图片到5万张,估计5万以上也是没问题的,我只试到5万,其实也没必要这么高,现实中1000左右就差不多了,不过我的应用到100就差不多了, package com. ...

  3. .net 文件下载

    /** 输入参数* _Request: Page.Request 对象* _Response: Page.Response 对象* _fileName: 下载文件名* _fullPath: 带文件名下 ...

  4. 复习一下sql server的inner join left join 和right join

    1.left join sql语句如下: select * from A left join B  on A.aID = B.bID 结果如下:aID               aNum       ...

  5. opacity在IE6~8下无效果,解决的办法

    opacity在IE6~8下无效果,解决的办法 问题出现时rgba()在ie6下不出效果,最后查到是opacity的问题. opacity是css3时出现的,目前主流浏览器都支持.but老IE是个麻烦 ...

  6. JavaScript之<noscript>标签简介

    早期浏览器都面临一个特殊的问题,即当浏览器不支持JavaScript时如何让页面平稳的退化.对这个问题的终极方案就是创造一个<noscript>元素,用以在不支持或支持但禁用了JavaSc ...

  7. visio 2013 破解工具 - KMSpico

    背景:环境是 win7, 64 bit装了 visio 2013 , 可以却不能用它来画图,在网上找了一些破解工具,大都不能解决问题.网上不靠谱的广告型文章太多了,比较头痛. 所幸,终于找到正确的破解 ...

  8. decimal类型不能为空,自定义update更新null值的问题。

    if (!string.IsNullOrEmpty(yt_time_limit_1)) { entity["yt_time_limit_1"] = Convert.ToDecima ...

  9. 【转】SQL Server 2008 新类型介绍之Date和Time

     转自CSDN TJVictor专栏:http://blog.csdn.net/tjvictor/archive/2009/07/13/4344429.aspx   SQL Server 2008除了 ...

  10. 《Effective C++》Item2:尽量以const,enum,inline替换#define

    1. 宏定义 #define ASPECT_RATIO 1.653 该宏定义ASPECT_RATIO也许从来没有被编译器看到,也许在编译器开始处理源码之前就已经被预处理器替换了.所以记号名称ASPEC ...