CodeForces 559A Gerald's 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 120°. 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:

題目的意思是給你一個(gè)等角六邊形(六個(gè)角都為120°),六條邊的長(zhǎng)度都給你,按與邊平行劃線蔚润, 問(wèn)最多會(huì)分成多少個(gè)邊長(zhǎng)為1的小三角形乙各。

20161103_161028.jpg

根據(jù)等角六邊形的特點(diǎn)(六個(gè)角都為120°工禾,對(duì)邊平行)赌蔑,可以將該六邊形劃分成如圖所示的情況悯周。求出六邊形的面積拌蜘,再除以小三角形的面積杆烁,即可得到最終的結(jié)果。

參考代碼:

#include <iostream>
#include <algorithm>
#include <cmath>
#define PI acos(-1.0) 
using namespace std;
const int N = 6+2;

int a[N];

void input() {
    for (int i = 1;i <= 6;++i) {
        cin >> a[i];
    }
}

int result() {
    double tixing = (a[4] + a[1]) * ((a[3] * sqrt(3.0) / 2.0) + a[2] * (sqrt(3.0) / 2.0)) / 2.0;
    double sanjiao1 = a[2] * a[3] * (sqrt(3.0) / 2.0) / 2.0;
    double sanjiao2 = a[5] * a[6] * (sqrt(3.0) / 2.0) / 2.0;
    double total = sanjiao1 + sanjiao2 + tixing;
    double sanjiao = 1 * 1 * (sqrt(3.0) / 2.0) / 2.0;
    //cout << (total / sanjiao) << endl;
    int ans = (int) (total / sanjiao + 0.5);
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    input();
    int ans = result();
    cout << ans << endl;
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末简卧,一起剝皮案震驚了整個(gè)濱河市兔魂,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌举娩,老刑警劉巖析校,帶你破解...
    沈念sama閱讀 217,907評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異铜涉,居然都是意外死亡智玻,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)芙代,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)吊奢,“玉大人,你說(shuō)我怎么就攤上這事纹烹∫彻觯” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,298評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵铺呵,是天一觀的道長(zhǎng)裹驰。 經(jīng)常有香客問(wèn)我,道長(zhǎng)片挂,這世上最難降的妖魔是什么幻林? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,586評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮音念,結(jié)果婚禮上滋将,老公的妹妹穿的比我還像新娘。我一直安慰自己症昏,他們只是感情好随闽,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,633評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著肝谭,像睡著了一般掘宪。 火紅的嫁衣襯著肌膚如雪蛾扇。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,488評(píng)論 1 302
  • 那天魏滚,我揣著相機(jī)與錄音镀首,去河邊找鬼。 笑死鼠次,一個(gè)胖子當(dāng)著我的面吹牛更哄,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播腥寇,決...
    沈念sama閱讀 40,275評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼成翩,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了赦役?” 一聲冷哼從身側(cè)響起麻敌,我...
    開(kāi)封第一講書(shū)人閱讀 39,176評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎掂摔,沒(méi)想到半個(gè)月后术羔,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,619評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡乙漓,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,819評(píng)論 3 336
  • 正文 我和宋清朗相戀三年级历,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片叭披。...
    茶點(diǎn)故事閱讀 39,932評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡鱼喉,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出趋观,到底是詐尸還是另有隱情,我是刑警寧澤锋边,帶...
    沈念sama閱讀 35,655評(píng)論 5 346
  • 正文 年R本政府宣布皱坛,位于F島的核電站,受9級(jí)特大地震影響豆巨,放射性物質(zhì)發(fā)生泄漏剩辟。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,265評(píng)論 3 329
  • 文/蒙蒙 一往扔、第九天 我趴在偏房一處隱蔽的房頂上張望贩猎。 院中可真熱鬧,春花似錦萍膛、人聲如沸吭服。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,871評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)艇棕。三九已至蝌戒,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間沼琉,已是汗流浹背北苟。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,994評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留打瘪,地道東北人友鼻。 一個(gè)月前我還...
    沈念sama閱讀 48,095評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像闺骚,于是被迫代替她去往敵國(guó)和親彩扔。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,884評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容