Arithmetic Expression
 
时间限制:2000ms
单点时限:200ms
内存限制:256MB

描述

Given N arithmetic expressions, can you tell whose result is closest to 9?

输入

Line 1: N (1 <= N <= 50000).
Line 2..N+1: Each line contains an expression in the format of "a op b" where a, b are integers (-10000 <= a, b <= 10000) and op is one of addition (+), subtraction (-), multiplication (*) and division (/). There is no "divided by zero" expression.

输出

The index of expression whose result is closest to 9. If there are more than one such expressions, output the smallest index.

样例输入
4
901 / 100
3 * 3
2 + 6
8 - -1
样例输出
2

【题意】:算出的结果最接近9的为第几个,相同的话输出靠前的。注意卡精度!要用double~
【代码】:
#include <bits/stdc++.h>
#define LL long long
#define maxn 500005
const int inf = 0x3f3f3f3f;
using namespace std; int n,idx;
double a,b,sum=;
char op;
double mi=0x3f3f3f3f3f;
void cal()
{
switch(op)
{
case '+':
sum=a+b;
break;
case '-':
sum=a-b;
break;
case '*':
sum=a*b;
break;
case '/':
sum=a/b;
break; }
}
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a>>op>>b;
cal();
double now = abs(-sum);
if(now < mi)//在线查询,边输入边查询,也可以叫打擂台算法,谁小谁上当min King,并记录是第几个人
{
idx=i;//而且是now < mi 不能等于,无形记录了字典序最小的那个人,因为后面出现的也是相等,不是小于了!
mi=now;
}
}
cout<<idx<<endl;
}

打擂台 严格小于



hihocoder Arithmetic Expression【在线查询】的更多相关文章

  1. [UCSD白板题] Maximize the Value of an Arithmetic Expression

    Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...

  2. leetcode-Evaluate the value of an arithmetic expression in Reverse Polish Notation

    leetcode 逆波兰式求解 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid ope ...

  3. 实时分析(在线查询),firehose---clickhouse

    firehose---clickhouse 在Hive中适不适合像传统数据仓库一样利用维度建模hive新功能 Cube, Rollup介绍https://blog.csdn.net/moon_yang ...

  4. 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)

    Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...

  5. MD5在线查询的实现

    #!/usr/bin/env python # -*- coding: UTF-8 -*- ''' 快速查询md5值工具,通过模拟浏览器发包请求http://cmd5.com和 http://xmd5 ...

  6. ACM Arithmetic Expression

    Description Given N arithmetic expressions, can you tell whose result is closest to 9? Input Line 1: ...

  7. Arithmetic Expression

    时间限制:2000ms 单点时限:200ms 内存限制:256MB 描述 Given N arithmetic expressions, can you tell whose result is cl ...

  8. Cloudera Hadoop 4 实战课程(Hadoop 2.0、集群界面化管理、电商在线查询+日志离线分析)

    课程大纲及内容简介: 每节课约35分钟,共不下40讲 第一章(11讲) ·分布式和传统单机模式 ·Hadoop背景和工作原理 ·Mapreduce工作原理剖析 ·第二代MR--YARN原理剖析 ·Cl ...

  9. 【微软编程一小时】题目1 : Arithmetic Expression

    时间限制:2000ms 单点时限:200ms 内存限制:256MB 描写叙述 Given N arithmetic expressions, can you tell whose result is ...

随机推荐

  1. python学习笔记十七:base64及md5编码

    一.Python Base64编码 Python中进行Base64编码和解码要用base64模块,代码示例: #-*- coding: utf-8 -*- import base64 str = 'c ...

  2. 【Linear Regression】林轩田机器学习基石

    这一节开始讲基础的Linear Regression算法. (1)Linear Regression的假设空间变成了实数域 (2)Linear Regression的目标是找到使得残差更小的分割线(超 ...

  3. Jmeter测试SOAP协议(Jmeter 3.3)

    公司协议都是SOAP协议的,最初在网上看到Jmeter测试soap协议需要插件,但是Jmeter3.2开始就不在支持该插件,后来又查了些资料,找到了解决办法,Jmeter提供专门创建针对soap协议的 ...

  4. Oracle 学习----:ora-00054 资源正忙 ,但指定以nowait方式获取资源 ,或者超时失效---解决方法

    1.查询被锁的会话ID: select session_id from v$locked_object;查询结果:SESSION_ID-------92.查询上面会话的详细信息: SELECT sid ...

  5. hnust 好友互动标识

    问题 A: 好友互动标识 时间限制: 1 Sec  内存限制: 128 MB提交: 897  解决: 122[提交][状态][讨论版] 题目描述       QQ有一个有趣的功能即显示好友互动标识,它 ...

  6. 简述Shiro验证过程

    如果让我们自己实现用户登录验证我们都需要哪些步骤? 很简单,根据用户提供的账号从数据库中查询该账户的密码以及一些其他信息,然后拿这个密码与用户输入的密码相比较,因为保存在数据库中的密码一般是经过加密的 ...

  7. CentOS6.5下搭建LAMP环境(源码编译方式)

    CentOS 6.5安装配置LAMP服务器(Apache+PHP5+MySQL) 学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP ,WAMP,MAMP等.这里我介 ...

  8. Python下安装protobuf

    1. 下载安装包 2. 解压缩 tar –xzvf protobuf-2.6.1.tar.gz 3. 安装protoc 在python中使用protocbuf需要Protocal Buffer 编译器 ...

  9. 团队冲刺Alpha(八)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  10. J2EE的十三种技术——JNDI

    背景: 上一篇博客中介绍了J2EE的十三种技术之一--JDBC,主要用于提供了统一访问多种数据库的方式.这篇文章我们继续介绍J2EE的技术--JNDI. JNDI: Java Naming and D ...