您的位置:首页 > 其它

RCC 2014 Warmup (Div. 2)__Elimination

2014-04-18 17:21 309 查看
题目链接

题意:

给定n、m、k、c、d,使得满足x1 / c * n + x2  * d + k >= m * n中的x1 + x2最小,(式中的x1 % c == 0)
关键:

这个题目很简单,自己的方法也比较麻烦。重点需要注意的一个,对下文中的程序,对于变量‘all’,之后的各种操作都是以其为正值来的。而c语言的特点决定了负数也是可以进行这些操作的,因此,在进行这些计算的时候要注意保证所计算的值一定不能是负数
int main()
{
//    freopen("in.txt", "r", stdin);
int c, d, n, m, k;
RV(c, d, n, m, k);
int all = n * m - k;
if (all <= 0)
puts("0");
else if (c < n * d)
{
int ans = all / n * c;
all -= all / n * n;
if (all != 0)
{
if (c < all * d)
ans += c;
else
ans += all * d;
}
cout << ans << endl;
}
else
cout << d * all << endl;
return 0;
}


反思:

其实这个问题本没有这么麻烦。。。。。,数据如此之少,直接枚举即可,还不会出错
int main()
{
//    freopen("in.txt", "r", stdin);
int c, d, n, m, k;
RV(c, d, n, m, k);
int ans = INF;
FE(i, 0, 10000)
{
int tt = n * m - i * n - k;
ans = min(ans, i * c + max(0, tt) * d);
}
printf("%d\n", ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm 枚举