第六周O题(等边三角形个数)
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
Input
The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Output
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
Sample Input
1 1 1 1 1 1
6
1 2 1 2 1 2
13
Hint
This is what Gerald's hexagon looks like in the first sample:
And that's what it looks like in the second sample:
题解;又是一道数学问题,输入六边形的每条边的长度,然后以边长1画等边三角形,统计六边形内部三角形的个数,统计时采用容斥原理即可。
盗图一张。。
这里输入的边长为3 4 2 6 1 5 ,通过填补的到一个正三角形,正三角形的边长len就是前三个边a1+a2+a3=9,这个正三角形中含有边长为1的三角形的个数就是len*len=81,然后减去三个角的三角形个数即可,这三个三角形也是正三角形,所以减去的三角形个数就是3*3+2*2+1*1,所以六边形含有的边长为1的三角形个数为81-(3*3+2*2+1*1)=67
代码:
#include<iostream>
using namespace std;
int main()
{
int a1,a2,a3,a4,a5,a6;
cin>>a1>>a2>>a3>>a4>>a5>>a6;
int len=a1+a2+a3;
cout<<len*len-a1*a1-a3*a3-a5*a5<<endl;
}
第六周O题(等边三角形个数)的更多相关文章
- hdu 4548 第六周H题(美素数)
第六周H题 - 数论,晒素数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)
第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...
- Codeforces 559A 第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 第六周 N题
Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...
- hdu1405 第六周J题(质因数分解)
J - 数论,质因数分解 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
- 集训第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 第六周 E题 期望.....
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- HDU 1465 第六周L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. ...
- HDU 1405 第六周 J题
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all ...
随机推荐
- Entity Framwork db First 中 Model验证解决办法。
由于项目中用到 Entity Framwork db First 每次从数据库生成数据模型之后都会把模型更新. 只要有一个表更新.所有的类都会重新生成. 在网上找了各种例子都是差不多的, 可能 ...
- 如何发送HTML表单数据
多数时候,HTML表单的目的只是为了把数据发给服务器,之后服务器再处理这些数据并发送响应给用户.虽然看起来挺简单的,但我们还是得注意一些事情以确保传送的数据不会破坏服务器.或者给你的用户制造麻烦. 数 ...
- idea mac 快键键
alt + 花 + 左右 上一步下一步 shift + 花 + F 全文检索 花 + O 类查找 alt + 花 ...
- Linux 和 Windows 下对long long的输出
以前一直用__int64来识别windows还是Linux,可是发现HDU好像不认 看到wzy用的UNIX可以. UNIX是Linux下定义的,具体是什么可以去百度. 那么就可以 #ifdef UNI ...
- winform combobox控件绑定 分类: WinForm 2014-04-17 14:34 118人阅读 评论(0) 收藏
想要达到的效果:把数据库中的一列数据绑定到combobox控件中. 数据库表:T_Task//任务表 列名:Task_Name//名称 主键:Task_ID combobox控件名称:cbName 解 ...
- PhoneGap应用开发的那些坑爹事儿
子曾经曰过:如果你恨一个人,让他去开发PhoneGap应用:如果你爱一个人,让他去开发PhoneGap应用. 去年这个时候我很烦恼,因为我觉得我OUT了. 起因是我买了一台Android系统的手机.当 ...
- cocos2d-x 关于tilemap滚动时黑线闪动的问题
改动抗锯齿这个全然没用. 解决问题的方法是开启CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL=1.不是在自己的project中开启,而是改动libcocos2dx库来解决 wa ...
- asp.net mvc vs web form
译者介绍 小小.NET学童,滴答…滴答…的雨…… 正文如下======================================================= 原文示例(VS2012): 1 ...
- Fuel4D 2.1 免费跨平台游戏引擎 现已发布
Fuel4D 2.1 免费跨平台游戏引擎 现已发布 开发环境:纯 C/C++,无JAVA.O-C. 支持 WIN32.安卓 系统. 详情见官方网站:http://www.fuel4d.com 或者进F ...
- Linux基本配置和管理 3 ---- Linux命令行文本处理工具
1 文件浏览(简单回顾) 1 cat 查看文件的内容 2 more 以翻页的形式查看,但是只能向下翻页 3 less 以翻页的形式查看,但是能够支持向上和向下翻页 4 head 默认是查看前10行,但 ...