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++交可以 ...
随机推荐
- FileStream 常用的属性和方法
FileStream常用的属性和方法 (转) 对流进行操作时要引用 using System.IO; 命名空间 FileStream常用的属性和方法: 属性: CanRead 判断当前流是否支持读取, ...
- 转:InnoDB Page Structure(InnoDB页面结构详解)
InnoDB Page Structure(InnoDB页面结构详解) 此转载自登博的博客,给大家分享.
- spring boot 学习10 定义springboot的两种方法
使用spring boot的两种方法: A:继承spring-boot-starter-parent项目 这种方式很简单,只需要在POM里面添加parent父工程即可. B: 如果你不喜欢继承spri ...
- 重新认识synchronized(下)
synchronized既保证原子性,又保证内存可见性,是一种线程同步的方式,是锁机制的一种java实现.synchronized的实现基于JVM底层,JVM是基于monitor实现的,而monito ...
- IEEE 2012 PHM数据挑战赛
Sutrisno E, Oh H, Vasan A S S, et al. Estimation of remaining useful life of ball bearings using dat ...
- select 动态添加option函数
转自:https://lym6520.iteye.com/blog/309937 经常会用到select动态添加元素,写了个方法,方便调用! ... /** * 功能:select对象动态添加Opt ...
- 根据URL下载文件
commons-io 包中已经封装好了,直接可以使用 一.添加依赖 <dependency> <groupId>org.apache.commons</groupId&g ...
- 如何边遍历集合边删除元素--使用Iterator中的remove()方法
在遍历集合时,想将符合条件的某些元素删除,开始是用了下面的方法 public static void main(String[] args) throws UnsupportedEncodingExc ...
- windows下启动命令行
1.当前目录打开命令窗口:shift+鼠标右键,然后打开命令窗口 2.查看监听的端口:netstat – ano
- 关于android通过shell修改文件权限的学习
首先是文件的读写属性(下图): 要通过shel命令l修改文件权限: 1.首先在cmd里输入adb shell 命令进入编辑模式 2.用cd命令进入到想要修改的文件目录,不知道的时候可以用ls 命令列表 ...