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. 读配置文件 properties

    /** * */package com.sprucetec.tms.fee.utils;import java.io.IOException;import java.util.ArrayList;im ...

  2. spring的作用及优势---第一个spring示例

    Spring 的作用及优势  * Spring 用于整合,好处是解耦. 解耦,可以降低组件不组件乊间的关联,改善程序结构,便于系统的维护和扩展. 我们在使用 Spring 框架时,主要是使用 Spri ...

  3. 编译时出现clock skew detected, your build may be incompeleted

    错误原因为文件修改时间大于系统时间,这时候如果date输出系统时间,会发现这个时间是错误的.在nachos实习时多次出现这个错误,简单的方法尝试make多次直到有一次出现'nachos' is up ...

  4. 简单实现计算Edit Distance算法

    最近因为工作需要,学习了NLP的相关知识,简单动手实现了一下计算Edit Distance的算法,就是计算一个字符串要变成另一个字符串需要的代价,这其中采用Levenshtein方式,即规定一个插入和 ...

  5. NYOJ306 走迷宫(dfs+二分搜索)

    题目描写叙述 http://acm.nyist.net/JudgeOnline/problem.php?pid=306 Dr.Kong设计的机器人卡多非常爱玩.它经常偷偷跑出实验室,在某个游乐场玩之不 ...

  6. 关于 FPGA 和 外部芯片接口时序设计

    在看这篇文章之前, 建议先好好读下这篇文章.http://download.csdn.net/detail/angelbosj/8013827. 因为我不太会用 VISio.要是哪位网友能告诉我.怎么 ...

  7. Java学习之ThreadLocal

    转自:http://www.cnblogs.com/doit8791/p/4093808.html#3197185 在同步机制中,通过对象的锁机制保证同一时间只有一个线程访问变量.这时该变量是多个线程 ...

  8. MySql级联操作

    转自:http://blog.csdn.net/codeforme/article/details/5539454 外键约束对子表的含义:       如果在父表中找不到候选键,则不允许在子表上进行i ...

  9. 整理部分JS 控件 WEB前端常用的做成Jsp项目,方便今后直接用

    整理部分JS 控件  WEB前端常用的做成Jsp项目,方便今后直接用 最近又没时间了,等用时间了,再加入更多的, 源码下载: http://download.csdn.net/detail/liang ...

  10. html5 input的type属性启动数字输入法

    html5 input的type属性启动数字输入法   当文本框只能输入数字是一个很常见的需求,比如电话号码,身份证号,卡号, 数量....等等只允许数字输入,为了更好的用户体验性,直接写出 启动数字 ...