10306 - e-Coins

2014-11-24 02:42:08 · 作者: · 浏览: 5
[cpp]
描述:刚开始没看懂题目,原来是要凑出一个数(x,y),使得x^2+y^2==s^2
#include
#include
int v[310][310],arr[45][2];
int pow_two(int x,int y)
{
return x*x+y*y;
}
int main()
{
// freopen("a.txt","r",stdin);
int n,m,t,sum,count;
scanf("%d",&t);
while(t--)
{
memset(v,0,sizeof(v));
v[0][0]=1;
scanf("%d%d",&n,&m);
int x,y;
sum=m*m;
count=0;
for(int i=0; i {
scanf("%d %d",&x,&y);
for(int j=0; j for(int k=0; k if(v[j][k]&&pow_two(x+j,y+k)<=sum&&(!v[j+x][y+k]||v[j+x][k+y]>v[j][k]+1))
{
v[j+x][y+k]=v[j][k]+1;
if(pow_two(x+j,y+k)==sum&&(!count||count>v[j+x][y+k])) count=v[j+x][y+k];
}
}
if(count) printf("%d\n",count-1);
else puts("not possible");
}
return 0;
}