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. tomcat oracle 连接池配置

    <?xml version='1.0' encoding='utf-8'?> <Context displayName="zcgl" docBase=" ...

  2. mongoose的populate的使用方法;

    LotteryReceiveRecord.find({"lottery":req.params.id}).populate("user lottery").ex ...

  3. openstack之neutron linuxbridge + vlan组网

    linuxbridge是和linuxbridge plugin匹配的core agent,主要实现L2层的功能和security group的功能.security group的功能逐渐会被neutr ...

  4. Qt(QML)本地化

    Internationalization and Localization with Qt Quick 程序国际化 1) Use qsTr() for all  Literial UI strings ...

  5. [C#参考]细说进程、应用程序域与上下文之间的关系

    原文转载链接:http://www.cnblogs.com/leslies2/archive/2012/03/06/2379235.html Written by:风尘浪子 引言 本文主要是介绍进程( ...

  6. leetcode String to Integer (atoi) python

    class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int "& ...

  7. HBase API详解

    一.Java API和HBase数据模型的关系 在Java中,与HBase数据库存储管理相关的类包括HBaseAdmin.HBaseConfiguration.HTable.HTableDescrip ...

  8. 查看SQLServer数据库信息的SQL语句

    --查看数据库中的表信息, --包括(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_MSForEachTable @precommand=N'create table # ...

  9. The following classes could not be found: - android.support.v7.internal.widget.ActionBarOverlayLayou解决方案

    如图出现如下的错误的时候,一般都是升级Androdi Studio 后导致的,引入库不全,或者其他 东西缺少,可以如下解决方案: 或者如下的解决方案: 在布局文件的Design界面中,修改原来的App ...

  10. cpan安装及其使用

    cpan安装及其使用 Perl是一种相当灵活的程序编程语言,现有的许有程序都是使用它进行编程的.它的优点之一就是无需自己编写编码,你就能利用许多增加的模块,创建新的功能. 程序利用这些模块的编码,而程 ...