CodeForces - 404B Marathon(精度)
题意:一个人绕着一个长度为a的正方形逆时针跑,以(0,0)为起点,喝一次水可以跑d米,问每喝一次水可以跑到的位置坐标。
分析:这道题卡精度卡的太厉害了。
设l是正方形的周长,只有d对l取余且每次跑d米都对l取余,并用取余后的结果继续跑,这样的精度才够。
1、double a = fmod(x, y);返回的是浮点数x对浮点数y取余后的结果。
2、每跑d米,通过对l取余得到当前位置与起点的路径长,从而确定当前位置的坐标。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-12;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
double a, d;
int n;
scanf("%lf%lf%d", &a, &d, &n);
double sum = 0;
double l = 4 * a;
d = fmod(d, 4 * a);
while(n--){
sum += d;
sum = fmod(sum, l);
double tmp = fmod(sum, a);
if(dcmp(sum, a) < 0){
printf("%.10f 0.0000000000\n", tmp);
}
else if(dcmp(sum, 2 * a) < 0){
tmp = fmod(tmp, a);
printf("%.10f %.10f\n", a, tmp);
}
else if(dcmp(sum, 3 * a) < 0){
tmp = fmod(tmp, a);
printf("%.10f %.10f\n", a - tmp, a);
}
else{
tmp = fmod(tmp, a);
printf("0.0000000000 %.10f\n", a - tmp);
}
}
return 0;
}
CodeForces - 404B Marathon(精度)的更多相关文章
- CodeForces - 404B(模拟题)
Marathon Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- codeforces B. Marathon 解题报告
题目链接:http://codeforces.com/problemset/problem/404/B 题目意思:Valera 参加马拉松,马拉松的跑道是一个边长为a的正方形,要求Valera从起点( ...
- CodeForces 404 Marathon ( 浮点数取模 -- 模拟 )
B. Marathon time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces 404B
毫无疑问这题不是难题,但是这种题目最让人纠结 打心里对这种题目就比较害怕,果然,各种WE 这里贴上代码,用Python写的,比较偷懒: def cur_pos(a, d): if 0 <= d ...
- Codeforces 237 div2 B. Marathon(关于精度损失的教训)
题目链接:http://codeforces.com/contest/404/problem/B?csrf_token=6292hf3e1h4g5e0d16a996ge6bgcg7g2 解题报告:一个 ...
- Codeforces gym 101343 A. On The Way to Lucky Plaza【概率+逆元+精度问题】
2017 JUST Programming Contest 2.0 题目链接:http://codeforces.com/gym/101343/problem/A A. On The Way to ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- Codeforces Round #237 (Div. 2) B. Marathon(卡long long)
题目:http://codeforces.com/contest/404/problem/B #include <iostream> #include <cstring> #i ...
- codeforces#1011C. Fly (二分,注意精度)
题意:火箭经过1到n号星球,并回到1号星球,现在给出每消耗一砘燃油能带起的火箭质量a[i]和b[i],a[i]代表在第i个星球起飞,b[i]代表在第i个星球降落.求出最少消耗的汽油.保证:如果不能完成 ...
随机推荐
- gerrit关闭管理员权限后解决办法
问题描述:gerrit以管理员的身份登录后,create new list和 create new group不显示,导致无法创建新的项目和权限组 出现问题:gerrit可视化页面误删all_proj ...
- redis学习笔记-02:为什么使用NoSQL数据库
一.第一代:单机版的MySQL 1.静态网页,动态交互类型的网站不多. 2.架构:APP---->DAL---->MySQL Instance 3.数据存储的瓶颈: (1)数据量总大小超过 ...
- Hyper-V网卡ping不通本机
可能的解决方案: 添加网卡时选择"旧版"
- TeX 常用命令记录
常用: $a_{i}^{2}$ a_{i}^{2} $\sqrt x$ $\sqrt[n] x$ \sqrt[n] x $\frac{1+2}{3+4}$ 重音符号: $\hat ...
- BUU re1
先shift+F12定位到关键句 然后crtl+X查看函数的交叉调用 定位到该函数处 F5查看伪代码 插入一段re1 re2题中都遇到的技巧: 很多时候出现的数字是asc码,热键R可以把数字转化成字母 ...
- Kubernetes 各版本镜像列表
以下镜像列表由 kubeadm v1.11.1 导出,若使用预下载镜像离线部署的方式部署,请使用 kubeadm v1.11.1 版本 导出各版本镜像列表: kubeadm config images ...
- openCV 3.4 windows下的配置说明
链接: https://pan.baidu.com/s/1dkS_G8ZSBD8EnhYeEFZxhQ 密码: xu99 (从官网下的, 但360会提示有毒, 哈哈哈) 运行exe, 解压openCV ...
- Spark Scheduler 模块(上)
在阅读 Spark 源代码的过程中,发现单步调试并不能很好的帮助理解程序.这样的多线程的分布式系统,更好的阅读源代码的方式是依据模块,分别理解. 在包 org.apache.spark 下面有很多 ...
- win2008R2 局域网共享
1.解决windows server 2008 R2 不能开启网络发现 开始–>管理工具–>服务,以下3个服务选择自动.开启: Function Discovery Resource Pu ...
- 08 MySQL存储引擎
查询当前默认存储引擎 SHOW VARIABLES LIKE 'table_type' ; 查询当前数据库支持的引擎有哪些 : SHOW ENGINES \G -- 推荐 ...