题意:一个人绕着一个长度为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. kafka在zookeeper默认使用/为根目录,将/更换为/kafka

    需求:kafka在zookeeper默认使用/为根目录,将/更换为/kafka 步骤:1.进入kafka的根目录: [root@node01 kafka_2.11-1.0.0]# cd /export ...

  2. Eclipse - 常见问题 - Refresh

    有时候项目代码正确但运行后出现异常,是因为eclipse没有刷新 (如jar包添加了但没用),比较脑慢. 解决方法: clean缓存,或者要多点几次Refresh,或者重启 eclipse.

  3. app开屏广告

    最近公司有个需求需要做app开屏广告(跳转到不同的页面)--下面是app开屏广告的处理 1.管理后台效果图 (1)广告链接--商品详情 (2)广告链接--关联模块 (3)广告链接--消息富文本 (4) ...

  4. Java导出Excel(项目实战Demo)

    Controller 层 /** * 考勤机刷卡明细导出Excel * * @throws Exception */ // @RequiresPermissions("report:Expo ...

  5. 修改Centos7的yum源

    以下为修改Centos7的yum源: 1. 备份原镜像文件,便于后期恢复 [root@keepmydream ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc ...

  6. JuJu团队1月7号工作汇报

    JuJu团队1月7号工作汇报 JuJu 周六周日放假,所以空了两天~   Scrum 团队成员 今日工作 剩余任务 困难 飞飞 完成data process readme部分 实现三维Dense 无 ...

  7. css调试与样式优先级

    如何查看一个标签的当前css样式 如上图所示 先用标签选择器选择某个标签 然后在elements区域就会自动找到该标签 然后在右侧的styles区域整个区域都是该标签的样式,从上到下是显示的优先级,被 ...

  8. wdcp升级php5.8到php7.1.12后安装swoole

    http://pecl.php.net/package/swoole wget http://pecl.php.net/get/swoole-4.0.1.tgztar zxvf swoole-4.0. ...

  9. ConfigureDefender – Windows Defender 设置工具

    用于配置Windows 10内置Defender防病毒设置的实用程序.它是一个便携式实用程序 ConfigureDefender实用程序是一个GUI应用程序,用于在Windows 10上查看和配置重要 ...

  10. DNS and Bind

    DNS  :  工作在应用层 DNS 作用 :  完成域名到IP的解析过程  FQDN --> IP 例如  :  www.ifeng.com  -->  123.103.122.24 D ...