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. 《Cracking the Coding Interview》——第17章:普通题——题目1

    2014-04-28 21:45 题目:就地交换两个数,不使用额外的变量. 解法:没说是整数,我姑且先当整数处理吧.就地交换可以用加法.乘法.异或完成,其中乘法和加法都存在溢出问题.三种方法都不能处理 ...

  2. 《Cracking the Coding Interview》——第13章:C和C++——题目7

    2014-04-25 20:18 题目:给定一个Node结构体,其中包含数据成员和两个Node*指针指向其他两个Node结构(还不如直接说这是个图呢).给你一个Node指针作为参数,请做一份深拷贝作为 ...

  3. 孤荷凌寒自学python第四十六天开始建构自己用起来更顺手一点的Python模块与类尝试第一天

     孤荷凌寒自学python第四十六天开始建构自己用起来更顺手一点的Python模块与类,尝试第一天 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 按上一天的规划,这是根据过去我自学其它编程语 ...

  4. springbootDay03 cookie和session 购物车技术

    一.会话技术 1. 什么是会话 在计算机术语中,会话指的是客户端和服务器交互通讯的过程.简单的理解,大家可以看成是两个普通的人在打电话.一次电话从通话开始到挂断,可以看成是会话. 会话的特征 会话能够 ...

  5. BATCH梯度下降,单变量线性回归

  6. SQL小助手——SQL Prompt

    背景: 当数据库设计的比较复杂.庞大时,我们如果对脚本不是很熟悉,就会很难完成看似简单的增.删.改.查的操作.我们需要一款软件来给出相应的提示或帮助,来提高代码的可读性,更快更好的完成任务. 简介: ...

  7. 转换 nvarchar 值 '2013071200000578' 时溢出了整数列

    sqlserver 把一个nvarchar 与 int  类型 拼接 会自动转换 INT 做运算,nvarchar 类型有16位 转换失败 只能 str(int) 转换成 字符型 进行拼接 (sqls ...

  8. [SP10707]COT2 - Count on a tree II

    题目大意:有一棵$n$个节点的树,第$i$个点有一个颜色$C_i$,$m$组询问,每次问$x->y$的路径上有多少种颜色 题解:树上莫队,把树按欧拉序展开成一条链,令第$i$个节点第一次出现在序 ...

  9. Leetcode 4. Median of Two Sorted Arrays(二分)

    4. Median of Two Sorted Arrays 题目链接:https://leetcode.com/problems/median-of-two-sorted-arrays/ Descr ...

  10. webdiyer aspnet pager最近又用这个。还是记录下。

    这个是页面里的代码需要在上面引入: <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer&quo ...