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

再次理解一下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. 非常不错的LTE架构讲解

    <LTE系统协议架构---通俗易懂超经典> <3GPP协议导读> <3GPP协议36211-850中文翻译> <LTE全套协议汇总> <NB-IO ...

  2. codeforce -39E-What Has Dirichlet Got to Do with That?(博弈+dfs)

    You all know the Dirichlet principle, the point of which is that if n boxes have no less than n + 1  ...

  3. HTML 5中的结构元素

    1.header:标记头部区域的内容 .footer:标记页脚区域的内容 .section:Web页面中的一块区域 4.article:独立的文章内容区域 5.aside:相关侧边内容或者引文区域 6 ...

  4. git 学习 多个提交用同一个commit

    git add .git commit --amend(连续按连个ZZ)git push -f origin ibm_branch(命令行可能不好用,用IDEA force push好用)

  5. Android SDK下载项的说明

    Tools下 1.android sdk tools 软件开发工具包(software development kit):包括测试.调试.第三方工具.模拟器.数据管理工具等. 2.android sd ...

  6. nginx for windows之负载均衡

    1.编辑c:\nginx\conf\nginx.conf   添加以下内容: #user  nobody;   #启动进程worker_processes  1;   #全局错误日志及PID文件err ...

  7. 数据库最佳实践:DBA小马如何走上升值加薪之路?

    DBA可能是互联网公司里面熬夜最多,背锅最多的岗位之一,腾讯云数据库团队的同学结合自身的成长经历,用漫画的形式为我们分享了一位DBA是如何从菜鸟成长为大神,走上升职加薪,迎娶白富美之路的. 此文已由作 ...

  8. jdbcTemplate学习(二)

    前面讲了增加.删除.更新操作,这节讲一下查询. 查询操作: (一)查询一个值(不需要注入参数) queryForObject(String sql, Class<T> requiredTy ...

  9. DAY10-MYSQL完整性约束

    一 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...

  10. Linux服务器在外地,如何用eclipse连接hdfs

    配置外网和内网的映射,内部所有配置全部用内网的IP 本地所有配置皆为外网地址 本地给服务器发指令全部由映射转换为内网指定IP,即可​