BestCoder Round #38
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的更多相关文章
- hdu 5207 BestCoder Round #38 ($) Greatest Greatest Common Divisor
#include<stdio.h> #include<string.h> #include<math.h> ]; ]; int main() { int sb; s ...
- BestCoder Round #14
Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- BestCoder Round #89 02单调队列优化dp
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01 HDU 5944 水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
- bestcoder Round #7 前三题题解
BestCoder Round #7 Start Time : 2014-08-31 19:00:00 End Time : 2014-08-31 21:00:00Contest Type : ...
- 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 ...
- Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
随机推荐
- 运行预构建 Linux 映像的 Windows Azure 虚拟机中的交换空间 – 第 1 部分
本文章由 Azure CAT 团队的 Piyush Ranjan (MSFT) 撰写. 随着基础结构服务(虚拟机和虚拟网络)近期在 Windows Azure 上正式发布,越来越多的企业工作负荷正在向 ...
- [置顶] C# WINCE调节屏幕亮度
在wince里面保存屏幕亮度的值保存在注册表HKEY_CURRENT_USER\ControlPanel\\Backlight\Brightness里面,值的范围是0-100,所以要改变屏幕的亮度,只 ...
- 解决cookie无法删除的问题
今天遇到一个cookie无法删除的问题,退出操作时cookie无法删除,必须在首页先进行退出操作,后来发现一个网友的博客,介绍了无法删除Cookie的原因,原来是我关于cookie的基础知识没搞清楚. ...
- Error pulling origin: error: The following untracked working tree files would be overwritten by...
git在pull时,出现这样的错误的时候,可能非常多人进进行stash.相关stash的请看:Error pulling origin: error: Your local changes to th ...
- C++面试题一大波
//打印1到最大的n位数. //题目:输入数字n.按顺序打印出从1到最大的n位十进制数.比方: //输入3.则打印出1.2.3一直到最大的3位数999. //[陷阱]:这个题目非常easy想到的办法就 ...
- WebConfig特殊字符的转义!
Web.Config默认编码格式为UTF-8,对于XML文件,要用到实体转义码来替换.对应关系如下: 字符 转义码 & 符号 & & 单引号 ' ' 双引号 ...
- BZOJ 3533: [Sdoi2014]向量集( 线段树 + 三分 )
答案一定是在凸壳上的(y>0上凸壳, y<0下凸壳). 线段树维护, 至多N次询问, 每次询问影响O(logN)数量级的线段树结点, 每个结点O(logN)暴力建凸壳, 然后O(logN) ...
- 常用的Linux操作命令(一)
ls 目录 mkdir 创建文件夹 vi 新建文件 :w filename 将文章存入指定的文件名filename :wq 保存并退出编辑文件 :q! 强制离开并放弃编辑的文件 cd 切换到目录/ro ...
- POJ1323-Game Prediction
描述: Suppose there are M people, including you, playing a special card game. At the beginning, each p ...
- delphi R3下 跨进程获取DLL信息 NtQueryInformationProcess
unit APIUnit; { GetProcessModuleHandle API Unit Ring3调用NtQueryInformationProcess实现跨进程获取DLL句柄 } inter ...