标签:sam cstring similar osi color div text ems ber
Input
There will be at most 30 test cases. The first line of each test case contains two integers x and y(0<=x<=y<=105). Each of the 3 lines contains 10 positive integers (not greater than 105), i.e. the costs of each button.Sample Input
100 100 10 100 100 100 100 100 100 100
Sample Output
Case 2: 12 3
AC代码例如以下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define M 10010
using namespace std;
struct H
{
friend bool operator <(const H x,const H y)
{
return x.a>y.a||(x.a==y.a&&x.b>y.b);
}
int a,b,c;
};
int cas=0;
int n,m;
int r1[10],r2[10],r3[10];
int vis[100005];
void bfs()
{
int i,j;
H aa,bb,cc;
priority_queue<H> q;
aa.c=n;
aa.a=0;
aa.b=0;
q.push(aa);
while(!q.empty())
{
bb=q.top();
q.pop();
if(vis[bb.c])
continue;
vis[bb.c]=1;
if(bb.c==m)
{
printf("Case %d: %d %d\n",cas,bb.a,bb.b);
return;
}
for(i=0;i<10;i++)
{
cc.c=bb.c*10+i;
if(cc.c>=0&&cc.c<100001&&!vis[cc.c])
{
cc.b=bb.b+1;
cc.a=bb.a+r1[i];
q.push(cc);
}
cc.c=bb.c+i;
if(cc.c>=0&&cc.c<100001&&!vis[cc.c])
{
cc.b=bb.b+1;
cc.a=bb.a+r2[i];
q.push(cc);
}
cc.c=bb.c*i;
if(cc.c>=0&&cc.c<100001&&!vis[cc.c])
{
cc.b=bb.b+1;
cc.a=bb.a+r3[i];
q.push(cc);
}
}
}
}
int main()
{
int i,j;
while(~scanf("%d%d",&n,&m))
{
cas++;
for(i=0;i<10;i++)
scanf("%d",&r1[i]);
for(i=0;i<10;i++)
scanf("%d",&r2[i]);
for(i=0;i<10;i++)
scanf("%d",&r3[i]);
memset(vis,0,sizeof vis);
bfs();
}
return 0;
}
湖南省第九届大学生计算机程序设计竞赛 Interesting Calculator
标签:sam cstring similar osi color div text ems ber
原文地址:http://www.cnblogs.com/tlnshuju/p/6979931.html