题意:一个人绕着一个长度为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(精度)的更多相关文章

  1. CodeForces - 404B(模拟题)

    Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  2. codeforces B. Marathon 解题报告

    题目链接:http://codeforces.com/problemset/problem/404/B 题目意思:Valera 参加马拉松,马拉松的跑道是一个边长为a的正方形,要求Valera从起点( ...

  3. CodeForces 404 Marathon ( 浮点数取模 -- 模拟 )

    B. Marathon time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces 404B

    毫无疑问这题不是难题,但是这种题目最让人纠结 打心里对这种题目就比较害怕,果然,各种WE 这里贴上代码,用Python写的,比较偷懒: def cur_pos(a, d): if 0 <= d ...

  5. Codeforces 237 div2 B. Marathon(关于精度损失的教训)

    题目链接:http://codeforces.com/contest/404/problem/B?csrf_token=6292hf3e1h4g5e0d16a996ge6bgcg7g2 解题报告:一个 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #237 (Div. 2) B. Marathon(卡long long)

    题目:http://codeforces.com/contest/404/problem/B #include <iostream> #include <cstring> #i ...

  9. codeforces#1011C. Fly (二分,注意精度)

    题意:火箭经过1到n号星球,并回到1号星球,现在给出每消耗一砘燃油能带起的火箭质量a[i]和b[i],a[i]代表在第i个星球起飞,b[i]代表在第i个星球降落.求出最少消耗的汽油.保证:如果不能完成 ...

随机推荐

  1. storm的JavaAPI运行报错

    报错:java.lang.NoClassDefFoundError: org/apache/storm/topology/IRichSpout 原因:idea的bug:本地运行时设置scope为pro ...

  2. Cookie存储在哪里

    内存是临时存储,关机后信息就没了.硬盘是长久存储,不删除就一直在.内存容量决定你电脑能同时运行的程序多少,硬盘容量决定你电脑能存放多少东西. 好比内存是手,硬盘是口袋,东西可以临时放在手里,可是口袋才 ...

  3. Java面向对象之类、接口、多态

    Java面向对象之类.接口.多态 类 class Person { // 实例属性 int age; String name; // 类属性 static int v = 1; // 构造器 publ ...

  4. [7b2美化]柒比贰 魔改系列|7B2-分类封面添加波浪效果&每日诗词

    本文转载自:钻芒博客 https://www.zmki.cn/5105.html 效果如图: 代码: 首先在style.css样式表里添加波浪样式 /*浪来了*/ .lang { overflow: ...

  5. Kubernetes 各版本镜像列表

    以下镜像列表由 kubeadm v1.11.1 导出,若使用预下载镜像离线部署的方式部署,请使用 kubeadm v1.11.1 版本 导出各版本镜像列表: kubeadm config images ...

  6. windows清理命令

    总是有一些设备需要清理,第三方的软件有不可以安装,那么,就需要这两条命令来做: cleanmgr /sageset:99 #设置要被清理的东西 cleanmgr /sagerun:99 #执行清理操作 ...

  7. Hibernate(十)--spring整合hibernate

    结构: Spring和Hibernate整合借助于HibernateTemplate applicationContext.xml <?xml version="1.0" e ...

  8. Eclipse 不能调试的问题

    现象 弹出 Cannot connect to VM Console 中的输出是: ERROR: transport error 202: connect failed: Connection ref ...

  9. Day 28:SAX解析原理

    SAX解析 回顾DOM解析 DOM解析原理:一次性把xml文档加载进内存,然后在内存中构建Document树. 缺点: 不适合读取大容量的xml文件,容易导致内存溢出. SAX解析原理: 加载一点,读 ...

  10. Day 26:Dom4j修改xml

    Dom4j:Writing a document to a file import java.io.File; import java.io.FileOutputStream; import org. ...