@HDU6424 @2018 Multi-University Training Contest 9 : Rikka with Time Complexity (数学题)

版权声明:岂曰无衣,与子同袍 https://blog.csdn.net/sizaif/article/details/82118158

Rikka with Time Complexity

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 538    Accepted Submission(s): 194


 

Problem Description

Calculating and comparing time complexity for algorithms are the most important necessary skills for CS students.

This semester, Rikka applies for the assistant of course "Algorithm Analysis". Now Rikka needs to set problems for the final examination, and she is going to set some tasks about time complexity. 

Let fa(n)=log…logn (there are exactly a log in this function, and log uses base 2). And then, for an integer array A, Rikka defines gA(n) in the following way (Bis the suffix of A with length |A|−1):

gA(n)={fA1(n)fA1(n)gB(n)|A|=1|A|>1



For example, g[1,2](n)=(logn)loglogn and g[3,1,1](n)=(logloglogn)(logn)logn.

Now, given integer arrays A and B, Rikka wants you to compare gA(n) with gB(n). i.e., let k be limn→+∞gA(n)gB(n). If k=0, output −1; if k=+∞, output 1; otherwise output 0.

ut

The first line contains a single number t(1≤t≤105), the number of testcases.

For each testcase, the first line contains two integers a,b(1≤a,b≤3), the length of A and B.

The second line contains a integers Ai and the third line contains b integers Bi(1≤Ai,Bi≤109), which describe A and B.

Output

For each testcase, output a single line with a single integer, the answer.

 

Sample Input

3

1 1

1

2

2 2

1 2

2 1

1 3

1

1000000000 3 3

Sample Output

1

-1

-1

 [题意] 

数学题;   定义 fa(n)  = A 个 log相乘 *n

然后 定义 

然后给集合 A和 B   

比较 G(A) 与 G(B)得大小,

[思路]

a,b <=3   , 化简公式  F(A)^{(F(B)^{F(C)}} 取一次log 变成 F(B)^{F(C)} * log(F(A)) = F(B)^{F(C)} * F(A+1)

在取一次log  变成 F(C)*log(F(B)) + log(F(A+1)) = F(C)*F(B+1) + F(A+2)

然后比较这个式子,  先取小值比较,在取大值标记,   取两次

[代码]

#include <bits/stdc++.h>
#include <stdio.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fi first
#define se second
typedef long long ll;

const int inf =0x3f3f3f3f;
using namespace std;

struct node{

	int x,y;
	node(int px,int py){
		x = min(px,py);
		y = max(px,py);
	}
};
bool com(node a,node b)
{
	return (a.x<b.x) || (a.x==b.x && a.y<b.y);
}

int main(int argc, char const *argv[])
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		int pa[4][4];

		memset(pa,inf,sizeof(pa));

		rep(i,1,a) scanf("%d",&pa[0][i]);
		rep(i,1,b) scanf("%d",&pa[1][i]);	
		
		node t1 = node{pa[0][1]+2,inf};
		node t2 = node{pa[0][2]+1,pa[0][3]};

		node t3 = node{pa[1][1]+2,inf};
		node t4 = node{pa[1][2]+1,pa[1][3]};

		int ans = 0;

		if( com(t2,t1) ) swap(t1,t2);
		if( com(t4,t3) ) swap(t3,t4);

		if( com(t1,t3 ) )
			ans = 1 ;
		else if( com(t3,t1) )
			ans = -1;
		else if( com(t2,t4) )
			ans = 1;
		else if( com(t4,t2) )
			ans = -1;
		else 
			ans = 0;
		printf("%d\n",ans);

	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/sizaif/article/details/82118158