Codeforces Round #313 (Div. 2) C. Geralds Hexagon(补大三角.cpp



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

Sample Output

Hint

This is what Gerald‘s hexagon looks like in the first sample:

And that‘s what it looks like in the second sample:

题意:

已知六边形的六条边长,求由多少个单位三等边角形拼成。边长按顺时针顺序给出,以单位三角形边长为单位。

思路:

六边形补成大等边三角形。因为边长为n的大三角形由n*n个小单位角形拼成,更容易计算。大三角形减去三个角变成六边形,减去的三个小三角形的这边长正好等于六边形中对应的的三条边长。因此,设大三角边长为s,三个小三角形边长分别为a,b,c,那个单位三角形个数为  s*s-(a*a+b*b+c*c).而 s 正好等于六边形相邻三条边之和,a,b,c 则分别等于六边形相隔的三条边,因此很容易得出答案,可以画图加深了解。

代码:

#include<cstdio>
using namespace std;
int a[7];
int main()
{
    int s;
    int ans;
    for(int i=0;i<6;i++)
        scanf("%d",&a[i]);
        s=a[0]+a[1]+a[2];
        ans=s*s-(a[0]*a[0]+a[2]*a[2]+a[4]*a[4]);
        printf("%d\n",ans);

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-25 21:17:54

Codeforces Round #313 (Div. 2) C. Geralds Hexagon(补大三角.cpp的相关文章

Codeforces Round #313 (Div. 2) C. Geralds Hexagon

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. Th

Codeforces Round #313 (Div. 2) Gerald&#39;s Hexagon

给出一个六边形六条边的长度(六边形的每个角为120度),求出这个六边形中边长为1的等边三角形有多少个 由于每个角都是120度并且上下两条边是平行的,因此我们可以补出一个矩形,再减掉周边四个角的面积,用剩下面积除以每个小三角形的面积. #include<cstdio> using namespace std; double a,b,c,d,e,f; int main() { <span style="white-space:pre"> </span>s

Codeforces Round #313 (Div. 2) C Gerald&#39;s Hexagon 计数

// Codeforces Round #313 (Div. 2) C Gerald's Hexagon // 计数 // 关键是平行于a1的长度为1的有多少条,中间的这些*2,再加上a1 // 和a4,就是三角形的总和 // 还是挺简单的,注意递增的初始值,和变化,就ac了 #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> using namespac

Codeforces Round #313 (Div. 1)

官方英文题解:http://codeforces.com/blog/entry/19237 Problem A: 题目大意: 给出内角和均为120°的六边形的六条边长(均为正整数),求最多能划分成多少个边长为1的正三角形. 题解: 把六边形补全变成一个正三角形,然后减去三个角的正三角形即可. Problem B: 题目大意: 给出长度相等的两个串AB,定义两个串相等 当且仅当  A=B  或者  当长度为偶数时,A[1...n/2]=B[1...n/2]  && A[n/2+1...n]=

Codeforces Round #313 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/560 水笔场... A. Currency System in Geraldion time limit per test:2 seconds memory limit per test:256 megabytes A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several va

【打CF,学算法——一星级】Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/A 题面: A. Currency System in Geraldion time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A magic island Geraldion, where Gerald lives,

Codeforces Round #313 (Div. 2)B.B. Gerald is into Art

B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/560/B Description Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought

Codeforces Round #313 (Div. 2)

A. Currency System in Geraldion 刚开始以为是什么动态规划,直接在那里叫这可怎么办?后来又想到如果10里面的数可以拼出来,那么大的也可以拼出来了,于是这样写就过了.今天早上一看人家的代码,才发现如果一可以拼出来,那么其他都可以拼出来.所以只需要将输入的数排序,第一个是不是一考虑一下就可以了.自己思维还是不够. #include<bits/stdc++.h> using namespace std; int a[1024],dp[1000000+5]; int ma

Codeforces Round #313 (Div. 2) 解题报告

A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假设这些纸币的最小值大于1,那么它所不能组成的最小面额就是1.所以自学求最小值就可以. 我的代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue