Example #1
0
void fadd(const temp_real * src1, const temp_real * src2, temp_real * result)
{
	temp_real a, b;
	int x1, x2, shift;

	x1 = src1->exponent & 0x7fff;
	x2 = src2->exponent & 0x7fff;
	if (x1 > x2)
	{
		a = *src1;
		b = *src2;
		shift = x1 - x2;
	}
	else
	{
		a = *src2;
		b = *src1;
		shift = x2 - x1;
	}
	if (shift >= 64)
	{
		*result = a;
		return;
	}
	if (shift >= 32)
	{
		b.a = b.b;
		b.b = 0;
		shift -= 32;
	}
	__asm__("shrdl %4,%1,%0 ; shrl %4,%1"
			: "=r" (b.a), "=r" (b.b)
			: "0" (b.a), "1" (b.b), "c" ((char) shift));
	signify(&a);
	signify(&b);
	__asm__("addl %4,%0 ; adcl %5,%1"
			: "=r" (a.a), "=r" (a.b)
			: "0" (a.a), "1" (a.b), "g" (b.a), "g" (b.b));
	unsignify(&a);
	*result = a;
}
Example #2
0
int main() {
    setbuf(stdout, NULL);
	int n, m, k;
	int i, j;
	int a, b;

	int cc, cs; // count covered, count signaled

	char **table;
	char ch;
	int tip;

	int cm = 0; // count mines
	int pcm = cm; // previous cm

	scanf("%d %d %d", &n, &m, &k);
	while(n != 0 || m != 0 || k != 0) {
		table = malloc(n * sizeof(char *));

		for(i = 0; i < n; i++) {
			table[i] = malloc(m * sizeof(char));

			for(j = 0; j < m; j++) {
				scanf(" %c", &ch);

				if(ch == '.') cm++;

				table[i][j] = ch;
			}
		}
		printTable(table, n, m);

		for(i = 0; i < k; i++) {
			scanf("%d %d", &a, &b);

			table[a-1][b-1] = 'i'; // invisible mine for the user
		}
		printTable(table, n, m);

		int tst = 1000;
		int pos = 1;
		do {
			pcm = cm;

			for(i = 0; i < n; i++) {
				for(j = 0; j < m; j++) {
					ch = table[i][j];

					if(ch != '.' && ch != 'x' && ch != '?' && ch != 'i') {
						cc = countCovered(table, n, m, i, j);
						cs = countSignaled(table, n, m, i, j);
						tip = ch - '0'; // char to int
						if(tip == cc + cs) {
							// all covered are mines
							cm -= signify(table, n, m, i, j);
						}
						else if(tip == cs) {
							// all covered aren't mines
							cm -= tipify(table, n, m, i, j);
							tipify(table, n, m, i, j);
						}
						else if(tip > cc + cs) { // impossible!
							pos = 0;
							tst = -1;
							i = n; j = m;
							break;
						}
					}
					if(ch == '?') {
						tipify(table, n, m, i, j);
					}
				}
			}
			tst--;
		} while(tst > 0);

		if(pos)
			for(i = 0; i < n; i++) {
				for(j = 0; j < m; j++) {
					ch = table[i][j];

					if(ch == '.') {
						printf("Impossivel\n");
						i = n; j = m;
						pos = 0;
					}
				}
			}
		else
			printf("Impossivel\n");
		if(pos)
			printf("Possivel\n");

		printTable(table, n, m);

		for(i = 0; i < n; i++) {
			free(table[i]);
		}
		free(table);

		scanf("%d %d %d", &n, &m, &k);
	}
  return 0;
}