题目链接:https://codeforces.ml/contest/1421/problem/D
//首先借贴说一下,唉我还是太没自信了。之前多少场的cf把我快打废了,吐血。就这一题,思路是对的,但是后面又尼玛懈怠了,用编译器调了半小时bug,咋就不用脑子调??
题意:给的数据为x,y(终点的坐标,起点再(0,0))。和c1,c2,c3,c4,c5,c6分别表示朝某个方向走一步需要多少价值。
题解:经分析之后,都是只走两个方向走到终点。(在坐标轴上是以下t1=0||t2=0)
代码:
#include <bits/stdc++.h>
#define ll long long
#define pi acos(-1)
#define pb push_back
#define mst(a, i) memset(a, i, sizeof(a))
#define pll pair<ll, ll>
#define fi first
#define se second
#define dbg(x) cout << #x << "===" << x << endl
using namespace std;
template<class T>void read(T &x){T res=0,f=1;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){res=(res<<3)+(res<<1)+c-'0';c=getchar();}x=res*f;}
void print(ll x){if(x<0){putchar('-');x=-x;}if(x>9)print(x/10);putchar(x%10+'0');}
const ll maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
ll n,a[]={0,1,0,-1,-1,0,1},b[]={0,1,1,0,-1,-1,0};
ll x,y;
ll v[10];
ll gcd(ll a,ll b){return (b==0)?a:gcd(b,a%b);}
ll qpow(ll a,ll p,ll mod){ll ans=1;a=a%mod;while(p){if(p&1)ans=(ans*a)%mod;p>>=1;a=(a*a)%mod;}return ans;}
int main() {
ll _s = 1;
read(_s);
for (ll _=1;_<=_s;_++) {
read(x),read(y);
for(ll i=1;i<=6;i++){
read(v[i]);
}
ll mi=8e18,xx,yy;
if(x>0) xx=1;
else if(x==0) xx=0;
else xx=-1;
if(y>0) yy=1;
else if(y==0) yy=0;
else yy=-1;
for(ll i=1;i<=6;i++){
for(ll j=1;j<=6;j++){
if(i==j||abs(i-j)==3) continue;
ll t1=(a[j]*y-b[j]*x)/(a[j]*b[i]-a[i]*b[j]);
ll t2=(a[i]*y-b[i]*x)/(a[i]*b[j]-a[j]*b[i]);
if(t1<0||t2<0) continue;
ll w=t1*v[i]+t2*v[j];
//cout<<"i=,j="<<i<<" "<<j<<endl;
//cout<<t1<<" "<<t2<<">>>"<<a[i]<<" "<<b[i]<<" jjj=="<<a[j]<<" "<<b[j]<<endl;
mi=min(w,mi);
}
}
cout<<mi<<endl;
}
return 0;
}
/*
input:::
2
-3 1
1 3 5 7 9 11
1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:::
*/