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 ...
随机推荐
- javascript 之 对象
可以通过 Object 构造函数或对象字面量的方式创建对象,但是这些方式的缺点是使用同一个接口创建多个对象,会产生大量重复的代码. 1.工厂模式 function createPerson(name, ...
- Vue2 轮播图组件 slide组件
Vue2原生始轮播图组件,支持宽度自适应.高度设置.轮播时间设置.左右箭头按钮控制,圆点按钮切换,以及箭头.圆点按钮是否显示. <v-carousel :slideData="slid ...
- WebSocket 客户端实例
Node.js var ws = require("ws"); var socket = new ws("ws://127.0.0.1:8001); var socket ...
- CDH部署(以5.7.5为例)
博客园首发,转载请注明出处https://www.cnblogs.com/tzxxh/p/9120020.html 一.准备工作(下面的内容括号内写master的表示仅在master节点执行,all代 ...
- 树莓3B+_安装vim
第一步:访问源列表里的每个网址,并读取软件列表,然后保存在本地电脑. sudo apt-get update 第二步:安装vim sudo apt-get install vim 第三步:配置vim ...
- 改脚本之dbscaner
默认的DBscaner只是用了ipy模块支持一个段的解析,但是我想让他加载脚本进行检测 所以,直接看 def __init__(self, target, thread): self.target = ...
- 20155310 2016-2017-2《Java程序设计》课堂实践补交
20155310 2016-2017-2<Java程序设计>课堂实践补交 第九周 程序设计中临时变量的使用 public class linshibianliang { public st ...
- 初步安装配置虚拟机、Ubuntu、git、vim、码云项目
内容 虚拟机软件:Oracle VM VirtualBox 系统:Ubuntu 配置:git:码云;vim 过程 下载安装VirtualBox.ubuntu 根据链接-- 基于VirtualBox安装 ...
- installshield 判断mdmcpq.inf和usbser.sys 是否 存在
1.产品上位机程序,需要驱动支持,在安装 exe程序的时候,连同NET框架4.0和 .inf驱动文件,一起安装, 安装驱动的时候,会发现, 如果系统 C:\Windows\Inf 缺少mdmcpq. ...
- 【BZOJ3144】[HNOI2013]切糕
[BZOJ3144][HNOI2013]切糕 题面 题目描述 经过千辛万苦小 A 得到了一块切糕,切糕的形状是长方体,小 A 打算拦腰将切糕切成两半分给小 B.出于美观考虑,小 A 希望切面能尽量光滑 ...