[cpp]
描述:剛開始沒看懂題目,原來是要湊出一個數(x,y),使得x^2+y^2==s^2
#include <cstdio>
#include <cstring>
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<n; i++)
{
scanf("%d %d",&x,&y);
for(int j=0; j<m; j++)
for(int k=0; k<m; 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;
}