2018 Multi-University Training Contest 9-J-Rikka with Time Complexity(取对数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6424

题意:看题面吧,贼容易看懂。

 

题解:因为有最多两层指数,高数上的常规方法是将其取对数使得变成两个数相乘,这样比大小就简单了,见图:

然后就是两项比大小了,肯定是先比大的然后比相对较小的了。。。。

#include<math.h>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int inf=2e9;
struct node
{
	int x,y;
	node(int xx,int yy)
	{
		x=xx;y=yy;
		x=min(xx,inf);
		y=min(yy,inf);
		if(x>y) swap(x,y);
	}
};
int comp(node k1,node k2)
{
	if (k1.x<k2.x) return 1; else if (k1.x>k2.x) return -1;
    if (k1.y<k2.y) return 1; else if (k1.y>k2.y) return -1;
    return 0;
}
int check(node k1,node k2,node k3,node k4)
{
	int w=comp(k1,k3); 
	if (w) return w;
    return comp(k2,k4);   
}
int a[5],b[5],n,m;
int main(void)
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=3;i++)
			a[i]=b[i]=inf;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(int i=1;i<=m;i++)
			scanf("%d",&b[i]);
		node t1=node(a[1]+2,inf),t2=node(a[2]+1,a[3]);
		node t3=node(b[1]+2,inf),t4=node(b[2]+1,b[3]);
		if(comp(t1,t2)==-1) swap(t1,t2);
		if(comp(t3,t4)==-1) swap(t3,t4);
		printf("%d\n",check(t1,t2,t3,t4));
	}
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值