hihocoder Arithmetic Expression【在线查询】

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=0;
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=1;i<=n;i++)
    {
        cin>>a>>op>>b;
        cal();
        double now = abs(9-sum);
        if(now < mi)//在线查询,边输入边查询,也可以叫打擂台算法,谁小谁上当min King,并记录是第几个人
        {
            idx=i;//而且是now < mi 不能等于,无形记录了字典序最小的那个人,因为后面出现的也是相等,不是小于了!
            mi=now;
        }
    }
    cout<<idx<<endl;
}

打擂台 严格小于



时间: 2024-08-29 18:16:22

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

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 operators are+,-,*,/. Each operand may be an integer or another expression. Some examples: ["2", "1", "+", "3", "

在线查询树上最近公共祖先模板

在线查询树上最近公共祖先 标准题目 第一行有2个整数n和q:n代表树的结点数量,q代表询问的次数接下来n-1行每行两个整数u和v,表示结点u到结点v有一条边.然后给出q组询问,每组询问由两个整数a和b构成,询问节点a和b的最近公共祖先. 样例数据 input:8 31 31 23 43 53 62 72 84 56 75 8 output:311 代码 1. 邻接表建图 1 #include <iostream> 2 #include <cstdio> 3 #include <

java swing调用webservice实现qq在线查询是否在线

原文:java swing调用webservice实现qq在线查询是否在线 代码下载地址:http://www.zuidaima.com/share/1550463277042688.htm 隐身的也可以看到,我测试过了. 标签: swing qq 在线查询 webservice话题: WebService 脚本和工具 Swing和AWT开发

百度账号隐藏信息在线查询工具

用法:直接把贴吧ID写进去点查询 之前在吐司论坛看到ID叫熊猫的朋友发了一个工具.......界面如图 主要觉得运行太繁琐 = = ,写了个在线查询的,解决了坑爹的url后参数中文自动编码的问题 利用的是百度知道,可以用于配合社工,可以来碰一下运气 调用接口:https://zhidao.baidu.com/mucenter/homepage?un=   这里写贴吧ID 原文地址:https://www.cnblogs.com/a1d4m/p/10050504.html

CHS-DRG ADRG在线查询

看了DRG分组PDF文档,需要查内容挺麻烦的,就花了几天时间整理出来.刚好在学习Golang,用gin做了个简单的ADRG在线查询app出来,重新体会下纯手码的痛感. 提供模糊查询.诊断+手术和操作及联合手术查询. 在线查询地址:http://www.chs-drg.net.cn 原文地址:https://www.cnblogs.com/auyeungs/p/12174035.html

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

课程大纲及内容简介: 每节课约35分钟,共不下40讲 第一章(11讲) ·分布式和传统单机模式 ·Hadoop背景和工作原理 ·Mapreduce工作原理剖析 ·第二代MR--YARN原理剖析 ·Cloudera Manager 4.1.2安装 ·Cloudera Hadoop 4.1.2 安装 ·CM下集群管理一 ·CM下集群管理二 ·Hadoop fs 命令详解 ·cloudera manager管理集群·cloudera manager下集群高级管理 第二章(约10讲) ·Hive数据表和

实时在线查询sql

场景:经过处理入库的记录都是当时在线的用户数,即一个唯一的uuid就可以表示这是一个当时的在线用户.现在要求查询出 实时在线用户数,这个"实时"肯定是最近的一个时间区间.我们取这个时间区间为5分钟. 数据也是5分钟入一次库.更精确的说法是,我们的"实时数据"是最近一次完整的5分钟区间.为什么要强调完整呢?因为入库的 时间并不能和刷新的时间做到同步,有可能页面正在刷新数据的时候,此时最近一次还没有完全入库.假设最后一次5分钟end5min 和倒数第二个5分钟last5

【微软编程一小时】题目1 : 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

Variables and Arithmetic Expression

Notes from The C Programming Language A decimal point in a constant indicates that it is floating point, however, so $5.0/9.0$ i not truncated because it is the ratio of two floating-point values. printf specification %3.0f says that a floating-point