UVa_Live 3664(精度坑)
题意很好理解的贪心题,然而却卡疯了的精度坑。
再次理解一下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(精度坑)的更多相关文章
- poj1064 Cable master(二分查找,精度)
https://vjudge.net/problem/POJ-1064 二分就相当于不停地折半试. C++AC,G++WA不知为何,有人说C函数ans那里爆int了,改了之后也没什么用. #inclu ...
- poj1113 凸包
result=对所有点凸包周长+pi*2*L WA了一次,被Pi的精度坑了 以后注意Pi尽可能搞精确一点.Pi=3.14还是不够用 Code: #include<vector> #incl ...
- HDU 4643 GSM 暑期多校联合训练第五场 1001
点击打开链接 我就不说官方题解有多坑了 V图那么高端的玩意儿 被精度坑粗翔了 AC前 AC后 简直不敢相信 只能怪自己没注意题目For the distance d1 and d2, if fabs( ...
- tyvj 2020 rainbow 的信号
期望 被精度坑惨的我 注意:能开 long long 尽量开, 先除后乘, int 转 double 的时候 先转换在做运算 本题与位运算有关,位与位之间互不影响,所以我们可以分开考虑 #includ ...
- 网络-05-端口号-F5-负载均衡设-linux端口详解大全--TCP注册端口号大全备
[root@test1:Standby] config # [root@test1:Standby] config # [root@test1:Standby] config # [root@test ...
- BigDecimal精度与相等比较的坑
先想一下,创建BigDecimal对象的时候一般是怎么创建的? new一个,传进去值 BigDecimal.valueOf方法,传进去值 作为一个数字类型,经常有的操作是比较大小,有一种情况是比较是否 ...
- double精度的坑与BigDecimal
近期经常接触支付相关的功能,在开发及测试过程中,开始金额都使用的是double类型,而近期新进的需求存在支付时打折的情况,也就是会出现如 1.23元的情况,那么这时候问题来了,如果是直接使用1.23进 ...
- [坑]c#中double转字符串精度丢失问题记录
在项目遇到了一个比较大的double值,然后出现了一些意想不到的状况: double b=1141.161994934082; b.ToString();//'1141.16199493408' 然后 ...
- POJ 1759 Garland(二分+数学递归+坑精度)
POJ 1759 Garland 这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...
随机推荐
- JDK 8 - JVM 对类的初始化探讨
在<深入理解 Java 虚拟机>(第二版,周志明著)中,作者介绍了 JVM 必须初始化类(或接口)的五种情况,但是是针对 JDK 7 而言的. 那么,在 JDK 8 中,这几种情况有没有变 ...
- 第15届浙江省赛 D Sequence Swapping(dp)
Sequence Swapping Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found a strange s ...
- mysql的默认隔离级别
原文:https://www.cnblogs.com/rjzheng/p/10510174.html 知识点总结 ------------------------------------------- ...
- hibernate学习笔记(4)表单操作
User.hbm.xml的表单配置: ①主键 <id name="id" type="java.lang.Integer"> <column ...
- MyBatis总结一:快速入门
简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以使用简单的 ...
- SQL查询语句 [2]
一.快捷查询 快捷查询方式是一种多字段查询的简化写法,在多个字段之间用'|'隔开表示OR,用'&'隔开表示 AND. 1.不同字段相同查询条件 在 Home/controller/UserC ...
- Centos7安装mysql缺乏yum源怎么安装
找到mysql5.6的centos的repo源,终于解决mysql的安装问题: 1.确保centos安装了wget,没有的话安装wget 1 yum install wget 2.下载mysql的 ...
- Boost log中的几个问题
1. 使用动态库时,要定义 BOOST_LOG_DYN_LINK 或者 BOOST_ALL_DYN_LINK 否则会出现如下错误: CMakeFiles/xxxx.dir/xxxx.cpp.o: I ...
- oracle数据库输入conn / as sysdba 出现ORA-01031: insufficient privileges + 忘记sys密码如何改密码
今天忘记了oracle数据库sys用户的密码,想着直接改密码输入conn / as sysdba 出现了ORA-01031: insufficient privileges(权限不足)的错误,到处搜教 ...
- parseXXX的用法
转换字符串. parseXXX是Integer类.等基本数据类型包装类的方法,用于实现String和int型数据的转换.例如, Integer.getInteger(String s) 从字符串中获取 ...