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

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;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值