HDU 5170 GTY's math problem 水题
题目链接:
hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5170
bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=567&pid=1001
题解:
先用java大数幂写的,t了
import java.util.*;
import java.math.*;
public class Main {
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
BigInteger a,c;
int b,d; while(cin.hasNext()){
a=cin.nextBigInteger();
b=cin.nextInt();
c=cin.nextBigInteger();
d=cin.nextInt(); a=a.pow(b);
c=c.pow(d);
//四则运算 if(a.compareTo(c)>0) System.out.println(">");
else if(a.compareTo(c)<0) System.out.println("<");
else System.out.println("=");
}
}
}
然后用java写了一个大数的快速幂,同t
import java.util.*;
import java.math.*;
public class Main {
public static BigInteger solve(BigInteger a,int n){
BigInteger ret=BigInteger.ONE;
// System.out.println("a:"+a.toString());
while(n>0){
if((n&1)>0){
// System.out.println("fuck!");
ret=ret.multiply(a);
}
a=a.multiply(a);
n/=2;
}
// System.out.println("ret!"+ret.toString());
return ret;
}
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
BigInteger a,c;
int b,d; while(cin.hasNext()){
a=cin.nextBigInteger();
b=cin.nextInt();
c=cin.nextBigInteger();
d=cin.nextInt(); a=solve(a,b);
c=solve(c,d); // System.out.println(a.toString());
// System.out.println(c.toString());
//四则运算 if(a.compareTo(c)>0) System.out.println(">");
else if(a.compareTo(c)<0) System.out.println("<");
else System.out.println("=");
}
}
}
终于意识到,只要转化为等幂,比较底数大小就可以了。。
a^b,(c^(d/b))d,只要比较a和c^(d/b)的大小。
第一发,没考虑进度,wa了
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std; int main() {
int a, b, c, d;
while (scanf("%d%d%d%d", &a, &b, &c, &d) == ) {
double tmp = d*1.0 / b;
tmp = pow(c*1.0, tmp);
if (a*1.0 > tmp) puts(">");
else if (a*1.0 < tmp) puts("<");
else puts("=");
}
return ;
}
贴正解:。。
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std; const double eps = 1e-; int main() {
int a, b, c, d;
while (scanf("%d%d%d%d", &a, &b, &c, &d) == ) {
double tmp = d*1.0 / b;
tmp = pow(c*1.0, tmp);
if (a*1.0-tmp>eps) puts(">");
else if (a*1.0 - tmp<-eps) puts("<");
else puts("=");
}
return ;
}
总结:
1、不要太冲动,一有想法就上键盘,多考虑下是否有更简单的解决方案。
2、写浮点数,一定要考虑精度!!!!,罚时伤不起。。
HDU 5170 GTY's math problem 水题的更多相关文章
- hdu 5170 GTY's math problem(水,,数学,,)
题意: 给a,b,c,d. 比较a^b和c^d的大小 思路: 比较log(a^b)和log(c^d)的大小 代码: int a,b,c,d; int main(){ while(scanf(" ...
- HDU 5170 GTY's math problem
数学题,a的b次方和c的d次方都很大,直接判断是做不出来的. 如果我们能找到一个函数F(x)是单调的,而F(X)的值又比较好算,那么可以通过比较F(X)的大小来判断自变量的大小. 令F(X)=log( ...
- Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题
A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis ...
- HDU 2096 小明A+B --- 水题
HDU 2096 /* HDU 2096 小明A+B --- 水题 */ #include <cstdio> int main() { #ifdef _LOCAL freopen(&quo ...
- HDU 4706 Children's Day (水题)
Children's Day Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 2117:Just a Numble(水题,模拟除法运算)
Just a Numble Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 2050:折线分割平面(水题,递归)
折线分割平面 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 2044:一只小蜜蜂...(水题,斐波那契数列)
一只小蜜蜂... Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepte ...
- [HDU 2602]Bone Collector ( 0-1背包水题 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...
随机推荐
- string函数库的原型
#ifndef __HAVE_ARCH_STRCPY /** * strcpy - Copy a %NUL terminated string * @dest: Where to copy the s ...
- 20155231 2016-2017-2 《Java程序设计》第1周学习总结
20155231 2016-2017-2 <Java程序设计>第1周学习总结 考核方式学习 课前准备 教材学习内容总结 第一章 Java平台概论 了解java 通过学习了解到,java设计 ...
- day 9 追踪一个蓝色的物体
# -*- coding: utf- -*- import cv2 import numpy as np #.打开摄像头 cap=cv2.VideoCapture('output.avi') ): # ...
- dotnet core在Task中使用依赖注入的Service/EFContext
C#:在Task中使用依赖注入的Service/EFContext dotnet core时代,依赖注入基本已经成为标配了,这就不多说了. 前几天在做某个功能的时候遇到在Task中使用EF DbCon ...
- Sqlserver新增自增列
if exists(select * from syscolumns where id=object_id('表名') and name='列名') begin alter table 表名 drop ...
- git remote: error: hook declined to update
提交一个项目,push的时候,报错: remote: error: File xxx.rar is MB; this exceeds Git@OSC's file size limit of 100 ...
- 算法工程师进化-NLP之主题模型
1 引言 主题模型是文本挖掘的重要工具,近年来在学术界和工业届都获得了非常多的关注.学术界的工作主要集中在建模层面,即提出各种各样的主题模型来适应不同的场景,因此缺乏指导主题模型在工业场景落地的资源和 ...
- 【sed】常用命令
替换 替换某一整行 sed '1c hello' test #将第一行替换为hello str1替换为str2 sed 's/^str1.*/str2/' filename #以str1开头 sed ...
- Windows 下在 Python (Anaconda) 中安装 Dlib 库
0. 引言 介绍在 Windows 操作系统下,在 Python 的 Anaconda 集成环境中,安装 Dlib 库 : 对于不了解源码编译的,或者利用 cmake 方法失败的,可以尝试下此方法: ...
- 搭建docker 私有镜像仓库
前期准备 服务器:centos 7.3 docker-ce: 18.06.1-ce docker-compose: 1.22.0 docker 安装 首先,更新系统 yum update yum up ...