Codeforces Round #313 (Div. 1) A. Gerald's Hexagon
Gerald's Hexagon
Problem's Link: http://codeforces.com/contest/559/problem/A
Mean:
按顺时针顺序给出一个六边形的各边长(且保证每个内角都是120度),求能够分解成多少个边长为1的小正三角形。
analyse:
由于每个内角都是120度,那么把三条边延长相交,一定能够得到一个正三角形。
求出正三角形的面积S1和补上的小三角形的面积S2,则answer=S1-S2.
这里不是真正意义上求正三角形的面积,而是直接求内部可以包含多少个边长为1的小正三角形。
设正三角形边长为L,则内部可包含L*L个边长为1的小正三角形。
[以下图片为外链引用,并无实意,请忽略]
Time complexity: O(1)
Source code:
/*
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-07-23-08.20
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define LL long long
#define ULL unsigned long long
using namespace std;
int a, b, c, d, e, f;
int main()
{
scanf( "%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f );
int t = a + b + f;
cout << t*t - b*b - d*d - f*f << endl;
return 0;
}
* this code is made by crazyacking
* Verdict: Accepted
* Submission Date: 2015-07-23-08.20
* Time: 0MS
* Memory: 137KB
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define LL long long
#define ULL unsigned long long
using namespace std;
int a, b, c, d, e, f;
int main()
{
scanf( "%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f );
int t = a + b + f;
cout << t*t - b*b - d*d - f*f << endl;
return 0;
}