2014年10月2日 星期四

TIOJ 1099 . B.射手座之日

亂DFS


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<cmath>
using namespace std;
typedef long long int int64;
bool dp[3101][3101]; int n;
//FILE* fp;
void dfs(int x, int y, int z){
//fprintf(fp, "visit %d %d %d\n", x, y, z);
if(x < 0 or y < 0  or z < 0) return;
if(x > n or y > n  or z > n) return;
if(dp[x][y]) return;
dp[x][y] = true;
dfs(y, x, z);
dfs(x, z, y);
dfs(z, y, x);
dfs(2*y-x+1,2*x-y-1,z);
return;
}
int main()
{
//fp = fopen("ooooo.out", "w");
int a1, b1, c1, a2, b2, c2;
while(scanf("%d %d %d %d %d %d %d", &n, &a1, &b1, &c1, &a2, &b2, &c2)){
if(n == 0) break;
if(a1+b1+c1 != a2+b2+c2){
puts("No");
continue;
}
memset(dp, 0, sizeof(dp));
dfs(a1, b1, c1);
puts(dp[a2][b2] ? "Yes":"No");
}
return 0;
}

沒有留言:

張貼留言