题意很好理解的贪心题,然而却卡疯了的精度坑。

再次理解一下double小数运算时可能导致的精度问题,本题为避免该问题可以将小数乘以100化为整数进行比较,输出的时候再除以100就ok;

思路也很好想,数据也不大,直接贴代码吧。

 #include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define MAXN 100010
const int maxn = ;
struct Player
{
double a, b, c;
int max_;
set<int> s;
} p[maxn];
int r[maxn], vis[maxn];
int main()
{
int n;
int T = ;
while(~scanf("%d", &n) && n)
{
for(int i = ; i <= n; i++)
p[i].s.clear();
for(int i = ; i <= n; i++)
{
scanf("%lf%lf%lf", &p[i].a, &p[i].b, &p[i].c);
int a = (p[i].a+0.005)*; //注意此处控制精度,其实就是为了四舍五入
int b = (p[i].b+0.005)*;
int c = (p[i].c+0.005)*; p[i].s.insert(a);
p[i].s.insert(b);
p[i].s.insert(c);
p[i].s.insert(a+b);
p[i].s.insert(a+c);
p[i].s.insert(b+c);
p[i].s.insert(a+b+c);
p[i].s.insert();
p[i].max_ = a+b+c;
}
bool ok = true;
for(int i = ; i < n; i++)
{
scanf("%d", &r[i]);
}
int ans = p[r[]].max_;
for(int i = ; i < n; i++)
{
int last = r[i-], now = r[i];
if(last > now)
{
if(*p[now].s.begin() >= ans)
{
ok = false;
break;
}
set<int>::iterator it = p[now].s.lower_bound(ans);
it--;
ans = *it;
}
else
{
if(*p[now].s.begin() > ans)
{
ok = false;
break;
}
set<int>::iterator it = p[now].s.lower_bound(ans);
if(it == p[now].s.end() || *it > ans)
{
--it;
ans = *it;
}
}
}
if(ok)
{
printf("Case %d: %.2lf\n", T++, (double)ans/100.00);
}
else
{
printf("Case %d: No solution\n", T++);
}
}
return ;
}

UVa_Live 3664(精度坑)的更多相关文章

  1. poj1064 Cable master(二分查找,精度)

    https://vjudge.net/problem/POJ-1064 二分就相当于不停地折半试. C++AC,G++WA不知为何,有人说C函数ans那里爆int了,改了之后也没什么用. #inclu ...

  2. poj1113 凸包

    result=对所有点凸包周长+pi*2*L WA了一次,被Pi的精度坑了 以后注意Pi尽可能搞精确一点.Pi=3.14还是不够用 Code: #include<vector> #incl ...

  3. HDU 4643 GSM 暑期多校联合训练第五场 1001

    点击打开链接 我就不说官方题解有多坑了 V图那么高端的玩意儿 被精度坑粗翔了 AC前 AC后 简直不敢相信 只能怪自己没注意题目For the distance d1 and d2, if fabs( ...

  4. tyvj 2020 rainbow 的信号

    期望 被精度坑惨的我 注意:能开 long long 尽量开, 先除后乘, int 转 double 的时候 先转换在做运算 本题与位运算有关,位与位之间互不影响,所以我们可以分开考虑 #includ ...

  5. 网络-05-端口号-F5-负载均衡设-linux端口详解大全--TCP注册端口号大全备

    [root@test1:Standby] config # [root@test1:Standby] config # [root@test1:Standby] config # [root@test ...

  6. BigDecimal精度与相等比较的坑

    先想一下,创建BigDecimal对象的时候一般是怎么创建的? new一个,传进去值 BigDecimal.valueOf方法,传进去值 作为一个数字类型,经常有的操作是比较大小,有一种情况是比较是否 ...

  7. double精度的坑与BigDecimal

    近期经常接触支付相关的功能,在开发及测试过程中,开始金额都使用的是double类型,而近期新进的需求存在支付时打折的情况,也就是会出现如 1.23元的情况,那么这时候问题来了,如果是直接使用1.23进 ...

  8. [坑]c#中double转字符串精度丢失问题记录

    在项目遇到了一个比较大的double值,然后出现了一些意想不到的状况: double b=1141.161994934082; b.ToString();//'1141.16199493408' 然后 ...

  9. POJ 1759 Garland(二分+数学递归+坑精度)

    POJ 1759 Garland  这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...

随机推荐

  1. &(((struct A*)NULL)->m_float)---offsetof

    问题描述: struct A { int m_int; float m_float; }; int main(void) { printf("%p",&(((struct ...

  2. JS和OC间的通信(使用JavaScriptCore)

    JavaScriptCore 时代的通讯 iOS 7 开始,苹果提供了一个叫作 JavaScriptCore 的框架,使用 JavaScriptCore 框架可以实现 OC 和 JS 的互相调用,而不 ...

  3. rails的respond to format

    Here are all the default Rails Mime Types: "*/*" => :all "text/plain" => : ...

  4. 2015.1.8 Left join 左连接

    格式 select f1.a, f2.b form f1 left jion f2 on .... 注意:左边的查询部分只能有select和from,不能出现where order by等.若有必须在 ...

  5. HotSpotVM创建过程(JNI_CreateJavaVM)详解

    来自:<Java Performance>第3章 JVM Overview The HotSpot VM's implementation of the JNI_CreateJavaVM ...

  6. SqlServer——事务—隔离级别

    隔离实际上是通过锁来实现的,作用于整个事务,它通常在事务开始前指定,如 SET TRANSACTION ISOLATION LEVEL READ Committed,指定后面的事务为 已提交读:而锁是 ...

  7. elastic(7)bulk

    转自:https://www.cnblogs.com/xing901022/p/5339419.html bulk批量导入 批量导入可以合并多个操作,比如index,delete,update,cre ...

  8. Javascript面向对象(三):非构造函数的继承

    这个系列的第一部分介绍了"封装",第二部分介绍了使用构造函数实现"继承". 今天是最后一个部分,介绍不使用构造函数实现"继承". 一.什么是 ...

  9. 【271】IDL-ENVI二次开发

    参考:String Processing Routines —— 字符串处理函数 01   STRING 返回字符串. 02   STRCMP 比较字符串,一样返回1,不一样返回0,默认大小写敏感. ...

  10. Android常用开源库集合【持续更新】

    1.FastJson  阿里巴巴工程师做的一个方便的JSON转换库 2.ButterKnife 只要作用能代替代码中大量的findviewbyid语句的使用,使用@injectview注入方式 3.v ...