题意:
一张有无限多的六变形组成的图,询问最少需要划几条线能构成>=n数量的三角形,在其中划线,线必须和边平行
思路:
因为要跟六边形的边平行,所以能够划的线只有,\—/, 分别记为x, y, z, 假设我有m条边,x条x边,y条y边, z条z边,那构成的等边三角形的个数就为 2 * x * y + 2 * x * z + 2 * y * z, 每次只要能得到这个式子的最大值即可,最大值只要尽可能的平均分配即可
总结:
图形题目,可以将条件利用起来,从原条件中抽象出来,变为数学公式,将不能求的,或者很复杂的转换为一般态,可求的状态,最后就是答案
#include <bits/stdc++.h>
#define endl '\n'
#define IOS ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
ll T, n;
ll cnt[N];
void Init()
{
cnt[1] = 0, cnt[2] = 2, cnt[3] = 6;
for (ll i = 4; i <= 1e5; ++i) //i代表边数
{
ll left = i % 3;
if (left == 0) //说明没有余数
{
ll x = i / 3;
cnt[i] = 6ll * x * x;
}
else if (left == 1)
{
ll x = i / 3;
cnt[i] = 2ll * x * x + 2ll * x * (x + 1) + 2ll * x * (x + 1);
}
else
{
ll x = i / 3;
cnt[i] = 2ll * (x + 1) * x + 2ll * (x + 1) * x + 2ll * (x + 1) * (x + 1);
}
}
}
int main()
{
//IOS; cin.tie(0), cout.tie(0);
Init();
cin >> T;
while (T--)
{
cin >> n;
int ans = lower_bound(cnt + 1, cnt + 1 + 100000, n) - cnt;
cout << ans << endl;
}
return 0;
}
初次遇见图形题,感觉好玩!