D: 遥 控 器
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef unsigned long long LL;
#define met(a,b) (memset(a,b,sizeof(a)))
const int INF = 1e9+7;
const int N = 11000;
const int MOD = 9973;
int a[20], s, e;
int Slove()
{
int i, Mintime = 100, shi=e/10, ge=e%10;
if(s>e)
{
if(a[11])
Mintime = min(Mintime, 100-(s-e));
if(a[12])
Mintime = min(Mintime, s-e);
}
else if(s<e)
{
if(a[11])
Mintime = min(Mintime, e-s);
if(a[12])
Mintime = min(Mintime, 100-(e-s));
}
else
Mintime = 0;
if(s!=e && !a[11] && !a[12])
{
if(shi==0)
{
if(!a[ge]) Mintime = -1;
}
else
{
if(!a[10]) Mintime = -1;
if(!a[shi]) Mintime = -1;
if(!a[ge]) Mintime = -1;
}
}
for(i=0; i<=99; i++)
{
if(i==s) continue;
int sh = i/10, g = i%10;
if(sh==0 && a[g])
{
if(i>e)
{
if(a[11]) ///变大
Mintime = min(Mintime, 100-(i-e)+1);
if(a[12]) ///变小
Mintime = min(Mintime, (i-e)+1);
}
else if(i<e)
{
if(a[11])
Mintime = min(Mintime, (e-i)+1);
if(a[12])
Mintime = min(Mintime, 100-(e-i)+1);
}
else Mintime = min(Mintime, 1);
}
else if(a[10] && a[sh] && a[g])
{
if(i>=e)
{
if(a[11])
Mintime = min(Mintime, 100-(i-e)+3);
if(a[12])
Mintime = min(Mintime, (i-e)+3);
}
else if(i<e)
{
if(a[11])
Mintime = min(Mintime, (e-i)+3);
if(a[12])
Mintime = min(Mintime, 100-(e-i)+3);
}
else Mintime = min(Mintime, 3);
}
}
if(Mintime==100)
Mintime = -1;
return Mintime;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
met(a, 0);
scanf("%d%d%d%d", &a[1], &a[2], &a[3], &a[11]);
scanf("%d%d%d%d", &a[4], &a[5], &a[6], &a[12]);
scanf("%d%d%d", &a[7], &a[8], &a[9]);
scanf("%d%d", &a[10], &a[0]);
scanf("%d%d", &s, &e);
int ans = Slove();
printf("%d
", ans);
}
return 0;
}
/**
*/
G: Divideing Jewels (01背包) 代码写的有点丑
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef unsigned long long LL;
#define met(a,b) (memset(a,b,sizeof(a)))
const int INF = 1e9+7;
const int N = 11000;
const int MOD = 9973;
int a[20], dp[N], v[N], k;
void Slove() ///重点就在于怎样的把它转化为01背包
{
int i, j;
k=1;
for(i=1; i<=10; i++)
for(j=1; j<=a[i]; j++)
v[k++] = i;
k--;
}
int main()
{
int iCase=1;
while(scanf("%d%d%d%d%d%d%d%d%d%d", &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9], &a[10])!=EOF)
{
int sum=0, i, j;
for(i=1; i<=10; i++)
sum += a[i]*i;
if(sum==0) break;
met(dp, 0);
met(v, 0);
Slove();
for(i=1; i<=k; i++)
for(j=sum/2; j>=v[i]; j--)
{
if(j>=v[i])
dp[j] = max(dp[j], dp[j-v[i]]+v[i]);
}
if(sum%2 || dp[sum/2]!=sum/2)
printf("#%d:Can't be divided.
", iCase++);
else
printf("#%d:Can be divided.
", iCase++);
}
return 0;
}