列表

详情


NC216201. Xjj'sTouchingValue

描述

Given three integers , , , we define Xjj's touching value function as follows:

Please calculate the maximum value of the function.

输入描述

The first line of the input contains an integer , denoting the number of test cases. 

In each test case, there are three integers and in one line.

输出描述

For each test case, output the maximum value of the function in the form of the simplest fraction.

示例1

输入:

2
1 1 3
-1 -1 5

输出:

1
-3/16

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 28ms, 内存消耗: 544K, 提交时间: 2021-02-09 21:22:38

#include<iostream>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int main(){
	int t,a,b,c;cin>>t;
	while(t--){
		cin>>a>>b>>c;int n=b,d=1,f=0;
		rep(i,c){
			if(n*1.0/d<(a*i+b)*1.0/(1<<i))n=a*i+b,d=1<<i;
		}
		if(n%d){
			if(n<0)n=-n,f=1;
			int g=gcd(n,d);if(f)cout<<"-";
			cout<<n/g<<"/"<<d/g<<endl;
		}
		else cout<<n/d<<endl;
	}
	return 0;
}

Python3(3.9) 解法, 执行用时: 625ms, 内存消耗: 4004K, 提交时间: 2020-12-26 17:00:20

from fractions import Fraction
t = int(input())
for _ in range(t):
    a, b, n = map(int, input().split())
    m = Fraction(b, 1)
    for x in range(n + 1):
        m = max(m, Fraction(a * x + b, 2**x))
    print(m)

上一题