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++交可以 ...
随机推荐
- AngularJS:SQL
ylbtech-AngularJS:SQL 1.返回顶部 1. AngularJS SQL 在前面章节中的代码也可以用于读取数据库中的数据. 使用 PHP 从 MySQL 中获取数据 AngularJ ...
- centos7下搭建ceph luminous(12.2.1)--无网或网络较差
本博客的主要内容是在centos7下搭建luminous,配置dashboard,搭建客户端使用rbd,源码安装ceph,最后给出一些较为常用的命令.本博客针对初次接触ceph的人群. 搭建环境: 主 ...
- mysql查询最近30天、7天、每天、昨天、上个月的记录
一些变量说明: add_time为插入的时间 to_days是sql函数,返回的是个天数 data_sub(date,INTERVAL expr type)给指定的日期减去多少天 data()函数 ...
- catkin 工作空间
catkin 工作空间:组织和管理功能包的文件夹,以 catkin 工具编译 建立工作空间 sch01ar@ubuntu:~$ mkdir -p ~/catkin_ws/src sch01ar@ubu ...
- 2015广州强网杯(Misc)
单身狗: 下载图片 被一只狗挡住了的二维码,用图片处理软件把上面两个正方形随便一个覆盖狗的地方 我直接用美图秀秀处理一下,扫一下就得到flag
- How to Enabling and Diabling VxDMP devices for use with Oracle ASM
Enable DMP support for ASM to make DMP devices visible to ASM as available disks To make DMP devices ...
- 2.2.3 Analyzing the output 分析对用户推荐书目的结果(2)
2.2.3 Analyzing the output 在之前的程序运行结果中我们得到的结果输出是: RecommendedItem [item:104, value:4.257081] 程序要 ...
- [转]AJAX工作原理及其优缺点
1.什么是AJAX?AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是一种创建交互式网页应用的网页开发技术.它使用:使用XHTML ...
- IOS UITableView分组与索引分区实例
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- PCL—点云分割(基于形态学) 低层次点云处理
博客转载自:http://www.cnblogs.com/ironstark/p/5017428.html 1.航空测量与点云的形态学 航空测量是对地形地貌进行测量的一种高效手段.生成地形三维形貌一直 ...