题意:一个人绕着一个长度为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. 在IDEA中如何使用tomcat部署项目

    1.首先,你得先建个Java 项目,然后next 2.新建完项目后,然后右击项目,选择“Add Framework Support...” 3.将Web Application 前的框勾选起来,然后点 ...

  2. 刷题55. Jump Game

    一.题目说明 题目55. Jump Game,给定一组非负数,从第1个元素起,nums[i]表示你当前可以跳跃的最大值,计算能否到达最后一个index.难度是Medium. 二.我的解答 非常惭愧,这 ...

  3. jquery获取select选中的文本值

    误区: 一直以为jquery获取select中option被选中的文本值,是这样写的:   $("#id").text();  //获取所有option的文本值 实际上应该这样: ...

  4. IdentityServer4专题之五:OpenID Connect及其Client Credentials流程模式

    1.基于概念 OAuth2.0与身份认证协议的角色映射 OpenID Connect 这个协议是2014颁发的,基于OAuth2.0,在这个协议中,ID Token会和Access Token一起发回 ...

  5. 嵊州普及Day3T2

    题意:对于n数列的全排列,有多少种可能,是每项前缀和不能整除3.输出可能性%1000000000037. 思路:全部模三,剩余1.2.0,1.2可这样排:1.1.2.1.2.1.2.……2或2.2.1 ...

  6. 模拟实现ES6的set类

    function Set() { var items = {}; // this.has = function(value){ // return value in items; // } this. ...

  7. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:分割按钮

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. NO16 第二关课后考试-aw-F-过滤已知的一级目录

    ·总结的经验:1.学会总结时学好运维的重要前提.2.通过案列或例子来总结一个技术点或者命令.3.画一张逻辑图,形象的卡通记忆这个知识技术点.4.通过管道过滤数据时,最好先输出结果,然后回退再使用管道看 ...

  9. tomcat报错catalina.sh: line 401: /usr/java/jdk1.7.52/bin/java: No such file or directory(转)

    原文:https://blog.csdn.net/reblue520/article/details/52588825 将生产服务器的Tomcat目录打包过来后解压后,启动Tomcat后,发现如下问题 ...

  10. Jmeter测试入门——带token的http请求

    安装 官网下载地址:http://jmeter.apache.org/download_jmeter.cgi 下载完成后解压zip包 启动JMeter,双击JMeter解压路径bin下面的jmeter ...