2018 Multi-University Training Contest 9--HDU 6424 Rikka with Time Complexity

題意:

通過題目給的函數計算出 g(A)/g(B) 的極限,如果極限爲0就輸出-1,否則輸出1。

題解:

因爲函數是指數的類型,我們就可以通過對函數用 log 化簡,最大有 3,所以要化簡2次就得到了 f(A1+2)+f(A2+1)*f(A3) 和f(B1+2)+f(B2+1)*f(B3),這種 a+b 和 c+d 比較大小可以先比較 max(a, b) 與 max(c, d),如果相等就比較 min(a, b) 與 min(c, d)。

#include <algorithm>
#include  <iostream>
#include   <cstdlib>
#include   <cstring>
#include    <cstdio>
#include    <string>
#include    <vector>
#include    <bitset>
#include     <stack>
#include     <cmath>
#include     <deque>
#include     <queue>
#include      <list>
#include       <set>
#include       <map>
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
using namespace std;
typedef long long ll;

const ll inf = 0x3f3f3f3f3f3f;

ll a1[5], b1[5];

struct node{
	ll x, y;
	node(ll a, ll b){
		x = min(a, inf);
		y = min(b, inf);
		if(x > y){
			swap(x, y);
		}
	}
};

int cmp(node a, node b){
	if(a.x < b.x){
		return -1;
	}
	else if(a.x > b.x){
		return 1;
	}
	if(a.y < b.y){
		return -1;
	}
	else if(a.y > b.y){
		return 1;
	}
	return 0;
}

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		ll A, B;
		scanf("%lld %lld", &A, &B);
		mem(a1, inf);
		mem(b1, inf);
		for(int i = 0; i < A; i++){
			scanf("%lld", &a1[i]);
		}
		for(int i = 0; i < B; i++){
			scanf("%lld", &b1[i]);
		}
		node a = node(a1[0]+2, inf);
		node b = node(a1[1]+1, a1[2]);
		node c = node(b1[0]+2, inf);
		node d = node(b1[1]+1, b1[2]);
		if(cmp(a, b) == 1){
			swap(a, b);
		}
		if(cmp(c, d) == 1){
			swap(c, d);
		}
		if(cmp(a, c)){
			printf("%d\n", -cmp(a, c));
		}
		else{
			printf("%d\n", -cmp(b, d));
		}
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章