Untitled
raw download clone
TEXT
views 14
,
size 1618 b
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
int t;
double n, A[6][6], x0[6], min;
int main()
{

	scanf("%d", &t);
	for (int i = 0; i < t; i++)
	{
		double tmp[6] = { 0 }, tmp2[6] = { 0 };				
		int no=0,ans = 0;
		 
		scanf("%lf",&n);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				scanf("%lf", &A[i][j]);
		for (int i = 0; i < n; i++)
			scanf("%lf", &x0[i]);
		scanf("%lf", &min);
		if (x0[0] <= min)
		{
			printf("0\n");
		}
		else {
			ans++;
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					tmp[i] += A[i][j] * x0[j];
				}
			}
			if (tmp[0] > x0[0])printf("Never\n");
			else if (tmp[0] <= min)
			{
				printf("%d\n", ans);
			}
			else if (tmp[0] <= x0[0] && tmp[0] > min)//if (min < tmp[0] && tmp[0] < x0[0])
			{
				while (tmp[0] > min)
				{
					if (tmp[0] == tmp2[0] && ans >5)
					{

						printf("Never\n");
						no++;
						break;

					}
					else
					{
						for (int i = 0; i < n; i++)
						{
							tmp2[i] = 0;
						}
						ans++;
						for (int i = 0; i < n; i++)
						{
							for (int j = 0; j < n; j++)
							{
								tmp2[i] += A[i][j] * tmp[j];
							}
						}
						for (int i = 0; i < n; i++)
						{
							tmp[i] = tmp2[i];
						}
					}
				}
				if (no == 0)printf("%d\n", ans);
			}
			for (int i = 0; i < n; i++)
			{
				tmp[i] = 0;
			}
		}
	}
	return 0;
}
/*3

2
0.5 0.5
0.5 0.5
1000 0
500

3
0.4 0.5 0.3
0.4 0.3 0
0.2 0.2 0.7
6000 3000 1000
1000

2
0.9 0.8
0.1 0.2
1000 0
889*/
close fullscreen
Login or Register to edit or fork this paste. It's free.