第六周O题(等边三角形个数)

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

Input

1 1 1 1 1 1

Output

6

Input

1 2 1 2 1 2

Output

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;
}
时间: 2024-12-08 14:56:38

第六周O题(等边三角形个数)的相关文章

程序设计入门—Java语言 第六周编程题 1 单词长度(4分)

第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这里的单词与语言无关,可以包括各种符号,比如"it's"算一个单词,长度为4.注意,行中可能出现连续的空格. 输入格式: 输入在一行中给出一行文本,以'.'结束,结尾的句号不能计算在最后一个单词的长度内. 输出格式: 在一行中输出这行文本对应的单词的长度,每个长度之间以空格隔开,行末没有最后

第六周 N题

Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks. He wants to make a calculated risk, and grab as much money as possible. But his friends - Hermi

HDU 1465 第六周L题

Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情.如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题

HDU1465 第六周L题(错排组合数)

L - 计数,排列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然

HDU 2669 第六周 I题

Description The Sky is Sprite.  The Birds is Fly in the Sky.  The Wind is Wonderful.  Blew Throw the Trees  Trees are Shaking, Leaves are Falling.  Lovers Walk passing, and so are You.  ................................Write in English class by yifenf

集训第六周 E题

E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once.

第六周 G题

G - 数论,最大公约数 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in antic

Light OJ 1104 第六周F题

F - 概率(经典问题) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there ar

第六周 可执行代码 以及 PSP 燃尽图 等等

转眼已经第六周了.这周主要内容有下:(CHECKLIST) 1.完成未完成的功能点. 2.PSP. 3.站立会议(待开). 4.燃尽图. 5.各种图(折线,饼图). 6.checkList 具体任务如下: 1. i.将用户做过的题目整理到习题本中. ii.习题本可以记录用户当时填写的答案. iii.规范算式(4个数字). iv.将做过的题目去重. v.再次规范化输出算式(生成数目多少,括号位置,括号对数). vi.支持分数运算. vii.结果用分数显示. viii.结果显示分数的最简形式. iX