这场比赛打着很来感,虽然手速太慢,最后没改好C题.
又一次变成黄人,上次已经是11年春天的事了,内牛满面.
下面是A,B,C 3题的题解:
A
------------------------------------------------------代码--------------------------------------------------
LL nMin = LLONG_MAX;
LL nMax = 0;
cin >> N;
for(LL i = 1; i * i <= N; i++)
{
if(N % i) continue;
LL x = i, y = N / i;
for(LL j = 1; j * j <= y; j++)
{
if(y % j) continue;
LL p = j, q = y / j;
LL tmp = (x + 1) * (p + 2) * (q + 2) - N;
nMax = max(nMax, tmp);
nMin = min(nMin, tmp);
}
for(LL j = 1; j * j <= x; j++)
{
if(x % j) continue;
LL p = j, q = x / j;
LL tmp = (y + 1) * (p + 2) * (q + 2) - N;
nMax = max(nMax, tmp);
nMin = min(nMin, tmp);
}
}
cout << nMin << " " << nMax << endl;
------------------------------------------------------------------------------------------------------------------
B:UVa_696_How_Many_Knights 是个差不多的题目,方法是二分图+推规律.
C:使用最大团求解.
先把每个点如何放置T字设备[点(x,y)对应T字的交叉处]标记为状态,最多有9*9*4个状态
然后根据各个状态是否可以共存建立无向图,求出该图的最大团即可.
奉上最大团模板:
-------------------------------------------------代码--------------------------------------------------------------
const int MAXN = 110;
int g[MAXN][MAXN];//顶点是从1开始索引..
int path[MAXN];//记录最大团的节点,个数是best
int num[MAXN];//num[i] 记录 vi 到 vn 这个集合的最大团是多少
int adj[MAXN];
int x[MAXN];
int nVertex;
int best;
void build()
{
for(int i = 1; i <= nVertex; i++)
{
for(int j = 1; j <= nVertex; j++)
{
scanf("%d", &g[i][j]);
}
}
}
bool Search(int adj[], int total, int cnt)
{
int t[MAXN];
if(0 == total)
{
if(best < cnt)
{
best = cnt;
for(int i = 0; i < cnt; i++) path[i] = x[i];
return true;
}
return false;
}
for(int i = 0; i < total; i++)
{
if(cnt + (total - i) <= best) return false;
if(cnt + num[adj[i]] <= best) return false;
x[cnt] = adj[i];
int k = 0;
for(int j = i + 1; j < total; j++)
{
if(g[adj[j]][adj[i]]) t[k++] = adj[j];
}
if(Search(t, k, cnt + 1)) return true;
}
return false;
}
void MaxClique()
{
best = 0;
for(int i = nVertex; i >= 1; i--)
{
x[0] = i;
int k = 0;
for(int j = i + 1; j <= nVertex; j++) if(g[i][j]) adj[k++] = j;
Search(adj, k, 1);
num[i] = best;
}
// print
printf("%d\n", best);
// for(int i = 0; i < best; i++)
// {
// if(i) putchar(' ');
// printf("%d\n", path[i]);
// }
}
------------------------------------------------------------------------------------------------------------------