Cod sursa(job #664285)

Utilizator andreidanAndrei Dan andreidan Data 19 ianuarie 2012 21:28:08
Problema Fructe Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <cstdio>

int main(){
	int p,b,t,i,j;
	
	scanf("%d", &t);
	
	freopen("fructe.in","r",stdin);
	freopen("fructe.out","w",stdout);
	
	for(i=1;i<=t;++i){
		scanf("%d %d", &p, &b);
		for(j=1;;++j){
			
			if(p>=2){
				while(p>b&&p>=2){
					p=p-2;
					++p;
					//printf("1");
				}
			}
			if(b>=2){
				while(p<b&&b>=2){
					b=b-2;
					++p;
					//printf("2");
				}
			}
			if(b>=1&&p>=1){
				while(p==b&&p>=1){
					--p;
					--b;
					++b;
					//printf("3");
				}
			}
			if(p==0&&b==1){
				printf("1\n");
				break;
			}
			if(p==1&&b==0){
				printf("0\n");
				break;
			}
			
		}
	}
}