Skip to main content
  1. Posts/

codeforces #341 div 2 D. Rat Kwesh and Cheese

·3 mins
Table of Contents
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://codeforces.com/contest/621/problem/D
#

题意:给出12个式子,问哪个最大。 思路:主要记住两个。一个是比较指数形式的数一个常用办法是取对数,同时要考虑是否能取对数,分情况讨论对于不能取对数的情况经过变换去取对数。第二个是取了两次对数后比较时候的最大值可能是小于0的。所以初始时置于0不够小。官方题解说得很清楚。

The tricky Rat Kwesh has finally made an appearance; it is time to prepare for some tricks. But truly, we didn’t expect it to be so hard for competitors though. Especially the part about taking log of a negative number.

We need a way to deal with x__y__z and x__yz. We cannot directly compare them, 200200200 is way too big. So what we do? Take log!

is an increasing function on positive numbers (we can see this by taking
, then
, which is positive when we are dealing with positive numbers). So if
, then x ≥ y.

When we take log,

But y__z can still be 200200, which is still far too big. So now what can we do? Another log! But is it legal? When x = 0.1 for example,
, so we cannot take another log. When can we take another log, however? We need
to be a positive number. y__z will always be positive, so all we need is for
to be positive. This happens when x > 1. So if_x_, y, z > 1, everything will be ok.

There is another good observation to make. If one of x, y, z is greater than 1, then we can always achieve some expression (out of those 12) whose value is greater than 1. But if x < 1, then x__a will never be greater than 1. So if at least one of x, y, z is greater than 1, then we can discard those bases that are less than or equal to 1. In this case,

. Remember that
, so
. Similarly,
.

The last case is when x ≤ 1, y ≤ 1, z ≤ 1. Then, notice that for example,

. But the denominator of this fraction is something we recognize, because 10 / 3 > 1. So if all x, y, z < 1, then it is the same as the original problem, except we are looking for the minimum this time.

  1/* ***********************************************
  2Author :111qqz
  3Created Time :2016年02月08日 星期一 03时38分46秒
  4File Name :code/cf/#341/D.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33double x,y,z;
 34string ans[20];
 35
 36double cal( double a,double b,double c)
 37{
 38    return c*log(b)+log(log(a));
 39}
 40double cal2(double a,double b,double c)
 41{
 42    return log(b*c*log(a));
 43}
 44
 45
 46void pre()
 47{
 48    ans[1] = "x^y^z";
 49    ans[2] = "x^z^y";
 50    ans[5] = "y^x^z";
 51    ans[6] = "y^z^x";
 52    ans[9] = "z^x^y";
 53    ans[10]= "z^y^x";
 54
 55
 56    ans[3] ="(x^y)^z";
 57    ans[4] ="(x^z)^y";
 58    ans[7] ="(y^x)^z";
 59    ans[8] ="(y^z)^x";
 60    ans[11]="(z^x)^y";
 61    ans[12]="(z^y)^x";
 62}
 63int dblcmp(double d)
 64{
 65    return d<-eps?-1:d>eps;
 66}
 67struct node
 68{
 69    double val;
 70    int id;
 71    node()
 72    {
 73	val = -9999999;  //初始化是0不够小,虽然最大值一定大于0,但是比较的时候由于取了两次对数所以不一定大于0.
 74    }
 75
 76    bool operator <(node b)const
 77    {
 78	int d = dblcmp(val-b.val);
 79	if (d>0) return true;
 80	if (d==0&&id<b.id) return true;
 81	return false;
 82    }
 83
 84}a[20];
 85
 86
 87
 88bool cmp(node a,node b)
 89{
 90    int d = dblcmp(a.val-b.val);
 91    if (d<0) return true;
 92    if (d==0&&a.id<b.id) return true;
 93    return false;
 94}
 95int main()
 96{
 97	#ifndef  ONLINE_JUDGE
 98	freopen("code/in.txt","r",stdin);
 99  #endif
100
101	cin>>x>>y>>z;
102	pre();
103	for ( int i = 1 ; i <= 12 ; i ++) a[i].id = i ;
104	int cnt = 0 ;
105
106	if (x>1)
107	{
108
109	    a[1].val = cal(x,y,z);
110	  //   cout<<"a[1].val:"<<a[1].val<<endl;
111
112	    a[2].val = cal(x,z,y);
113
114	    a[3].val = cal2(x,y,z);
115	  //  cout<<"a[3].val:"<<a[3].val<<endl;
116
117	    a[4].val = cal2(x,z,y);
118	}
119	if (y>1)
120	{
121	    a[5].val = cal(y,x,z);
122	    a[6].val = cal(y,z,x);
123	    a[7].val = cal2(y,x,z);
124	    a[8].val = cal2(y,z,x);
125	}
126	if (z>1)
127	{
128	    a[9].val = cal(z,x,y);
129	    a[10].val = cal(z,y,x);
130	    a[11].val = cal2(z,x,y);
131	    a[12].val = cal2(z,y,x);
132	}
133
134	if (x>1||y>1||z>1)
135	{
136	    sort(a+1,a+13);
137	}
138	else
139	{
140	    a[1].val = cal(1.0/x,y,z);
141
142	    a[2].val = cal(1.0/x,z,y);
143
144	    a[3].val = cal2(1.0/x,y,z);
145
146	    a[4].val = cal2(1.0/x,z,y);
147
148	    a[5].val = cal(1.0/y,x,z);
149	    a[6].val = cal(1.0/y,z,x);
150	    a[7].val = cal2(1.0/y,x,z);
151	    a[8].val = cal2(1.0/y,z,x);
152
153	    a[9].val = cal(1.0/z,x,y);
154	    a[10].val = cal(1.0/z,y,x);
155	    a[11].val = cal2(1.0/z,x,y);
156	    a[12].val = cal2(1.0/z,y,x);
157	//    for ( int i = 1 ; i <=12 ; i++) cout<<a[i].val<<endl;
158	    sort(a+1,a+13,cmp);
159
160	}
161
162	cout<<ans[a[1].id]<<endl;
163
164
165
166
167
168
169
170
171  #ifndef ONLINE_JUDGE
172  fclose(stdin);
173  #endif
174    return 0;
175}

Related

codeforces #342 div 2 A. Guest From the Past

·1 min
http://codeforces.com/contest/625/problem/A 题意:有n块钱,塑料瓶饮料a元一瓶,玻璃瓶饮料b元一瓶,退还玻璃瓶可以得到c元。问最多能买多少瓶饮料。 思路:贪心。如果塑料瓶比玻璃瓶的实际价格便宜,那么一定买塑料瓶的,否则先买玻璃瓶,再用塑料瓶填。注意一些边界的判断。。

codeforces 107 B. Basketball Team

·2 mins
http://codeforces.com/problemset/problem/107/B 题意:有m个部门,每个部分s[i]个人,HW在第h部门,现在要从这m个部门中挑选包括HW在内的n个人去参加比赛,问被挑选的人中有HW的队友(同部门的人)的概率是多少。如果m个部分的人数不够组成n人的球队,输出-1. # 思路:考虑一般情况。至少有一个队友的情况较多,应该从反面考虑,即没有一个队友的情况。选完HW以后面临的状态是:事件总数为从total(m个部门的人员之和)-1个人中选n-1个的方案数,包含的事件数目为从a(a=total-s[h])中选n-1个人包含的方案数。 可以看出分母相同,可以约掉。 # 然后对于边界情况,首先判断total是否比n小。然后,如果a<n-1,表示除去HW所在的h部分之外的人不可能组成n-1个人,也就是一定要选择HW的队友,概率为1.

codeforces 312 B. Archer

·2 mins
http://codeforces.com/problemset/problem/312/B # 题意:两个人比赛射箭,先射的人射中的概率是a/b,后射的人射中的概率是c/d,问先射的人赢的概率。 思路:应该叫条件概率。。。? 不过我们可以用古典概型的思维想。每射一次看成一个点,射中的点用白色表示,没有射中的用黑色表示。如果两个人第i次都没有射中,那么就要继续第i+1 轮,而第i+1轮和之前的每一轮是独立的。等于重复这个过程。所以古典概型的样本总量应该减去宝石两个人都没有射中的点的个数,为bd-(b-a)(d-c),整理为bc+ad-a*c,设为n.要想第一个人赢,那么对于某一次,只要不是第一个人没射中,第二个人射中这种情况,就都是第一个人赢。而第一个人没射中的事件数为b-a,第二个人射中的事件数为c,总数为(b-a)*c,所以答案为(n-(b-a)*c)/n

codeforces 453 A. Little Pony and Expected Maximum

·1 min
http://codeforces.com/problemset/problem/453/A 题意:m面筛子,每面点数出现的概率相同,连续投掷n次,问出现的最大值的数学期望。 思路:手写样例。。。发现答案为 。。。记得把(1/m)^n放进去。

codeforces 476 B. Dreamoon and WiFi

·2 mins
http://codeforces.com/problemset/problem/476/B 题意:给出两个长度相等-且不超过10的字符串,串1只包含‘-’,’+‘。按照‘+’为1,‘-’为-1累加可以得到一个值。串2还包含若干‘?’,代表该处的值不确定,且为’+‘和’-‘的概率相等,都是0.5.问串2的值和串1相等的概率。 思路:我们可以扫一遍得到‘?’的个数和两个式子的差值。设问号个数为a,差值为b,那么在a个问号中需要有(a-b)/2个为‘+’(容易知道,a,b一定奇偶性相同,所以a-b一定能被2整除),根据超几何分布,概率为 c[a][(a-b)/2]*(1/2)^a; 写的时候可以先打个组合数的表。1A,开心。