2025第三赛季人工智能算法巅峰赛算法优化题
·
#include <bits/stdc++.h>
using namespace std;
const int N = 4009;
int n, m;
double k;
struct task
{
int value, power, heat;
int res, id;
} ta[N];
struct fuwu
{
int p;
double h;
double curh;
int curp;
} fu[N];
bool cmp1(task t1, task t2)
{
if (t1.value == t2.value)
{
if (t1.power == t2.power)
return t1.heat <= t2.heat;
else
return t1.power < t2.power;
}
else
return t1.value > t2.value;
}
bool cmp2(task t1, task t2)
{
return t1.id < t2.id;
}
bool check(int i, int j)
{
double t1, t2, t3;
t2 = fu[j].curh + ta[i].heat;
if (t2 > fu[j].h)
return 0;
if (j == 1)
{
t3 = fu[j + 1].curh + ta[i].heat * k;
if (t3 > fu[j + 1].h)
return 0;
}
else if (j == m)
{
t1 = fu[j - 1].curh + ta[i].heat * k;
if (t1 > fu[j - 1].h)
return 0;
}
else
{
t3 = fu[j + 1].curh + ta[i].heat * k;
t1 = fu[j - 1].curh + ta[i].heat * k;
if (t1 > fu[j - 1].h)
return 0;
if (t3 > fu[j + 1].h)
return 0;
}
return 1;
}
void renew(int j, int i)
{
fu[j].curp += ta[i].power;
fu[j].curh += ta[i].heat;
if (j == 1)
fu[j + 1].curh += ta[i].heat * k;
else if (j == m)
fu[j - 1].curh += ta[i].heat * k;
else
{
fu[j + 1].curh += ta[i].heat * k;
fu[j - 1].curh += ta[i].heat * k;
}
}
int main()
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
{
cin >> ta[i].value >> ta[i].power >> ta[i].heat;
ta[i].id = i;
}
for (int i = 1; i <= m; i++)
{
cin >> fu[i].p >> fu[i].h;
fu[i].curh = fu[i].curp = 0;
}
sort(ta + 1, ta + n + 1, cmp1);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (fu[j].curp + ta[i].power <= fu[j].p && check(i, j))
{
renew(j, i);
ta[i].res = j;
// cout << j << endl;
break;
}
else
ta[i].res = 0;
}
// cout << ta[i].id << " " << ta[i].res << endl;
}
sort(ta + 1, ta + n + 1, cmp2);
/// for (int i = 1; i <= m; i++) cout << fu[i].curh << endl;
for (int i = 1; i <= n; i++)
{
cout << ta[i].res << " ";
}
}
考试题目大意时在满足每个机器的发热不超过阈值的情况下保证最终结果最优,此代码得分大概370多分,能够保证学生在算法巅峰赛得到国一水平。
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐



所有评论(0)