原题连接:http://codeforces.com/contest/876/problem/A
题目大意:现在有三个结点,每个地方有肉吃,吃了一次要离开了再回来才能再吃一次,结点之间互联,距离不同,要求吃n次肉最少需要跑多少距离
思路:简单题,就看当前所在位置去哪里最近就去哪好了,(不过相同位置的选择总是确定的,大概可以算出来直接求?不过还是暴力舒服)
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include<algorithm>
using namespace std;
int main() {
int n, a, b, c;
scanf("%d %d %d %d", &n, &a, &b, &c);
n--;
int distance = 0;
int flag = 0;
while (n) {
if (flag == 0) {
if (a < b) {
flag = 1;
distance += a;
}
else {
flag = 2;
distance += b;
}
}
else if (flag == 1) {
if (a < c) {
flag = 0;
distance += a;
}
else {
flag = 2;
distance += c;
}
}
else {
if (b < c) {
flag = 0;
distance += b;
}
else {
flag = 2;
distance += c;
}
}
n--;
}
printf("%d\n", distance);
return 0;
}