题目链接:http://codeforces.com/problemset/problem/404/B

题目意思:Valera 参加马拉松,马拉松的跑道是一个边长为a的正方形,要求Valera从起点(0,0)出发,每经过距离d就给他一杯drink。求出n个位置,即Valera每经过d距离的position。

一开始我是直接模拟的,每次算出一个position就记录离该边最末还剩多少距离,假设为k,然后更新初始已有的距离k,又开始加a的距离直到到达下一个点...代码复杂之余,还超时了。

比较好的作法是:既然要求position,那么这个position一定是经过 i*d(i  = 1 ~ n) 的距离的。那么问题关键就是定位!也就是坐标位置!这时需要知道Valera 经过多少条长度为a的边i*d/a (k)。接着就是确定具体是那条边了,可以通过对 k mod 4来求得。下边:0 ;右边:1; 上边:2; 左边:3。另外引入t,它表示经过id距离之后,与经过相应的a边的长度之差,即t = id - ka。

至于具体的坐标点则根据这些边的不同而有所不同。由于一直是逆时针跑的,因此下边的x坐标是(t,0),右边是(a, t), 上边是(a-t, a)(求的时候是逆时针方向的,也就是该点离右边的距离,我们需要求的是离左边的距离),左边(0, a-t)(与上边同理)

还有一个要注意的地方,就是要取 int64了,10^5 * 10^5 !

 #include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std; int main()
{
double a, d, t;
__int64 k, n, i;
while (scanf("%lf%lf%I64d", &a, &d, &n) != EOF)
{
double zero = 0.0;
for (i = ; i <= n; i++)
{
k = i * d / a;
t = i * d - k * a;
// printf("k = %d, t = %lf\n", k, t);
if (k % == )
printf("%lf %lf\n", t, zero);
else if (k % == )
printf("%lf %lf\n", a, t);
else if (k % == )
printf("%lf %lf\n", a-t, a);
else
printf("%lf %lf\n", zero, a-t);
}
}
return ;
}

codeforces B. Marathon 解题报告的更多相关文章

  1. codeforces 31C Schedule 解题报告

    题目链接:http://codeforces.com/problemset/problem/31/C 题目意思:给出 n 个 lessons 你,每个lesson 有对应的 起始和结束时间.问通过删除 ...

  2. codeforces 499B.Lecture 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 profes ...

  3. codeforces 495C. Treasure 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/C 题目意思:给出一串只有三种字符( ')','(' 和 '#')组成的字符串,每个位置的这个字符 ...

  4. codeforces 490B.Queue 解题报告

    题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位 ...

  5. CodeForces 166E -Tetrahedron解题报告

    这是本人写的第一次博客,学了半年的基础C语言,初学算法,若有错误还请指正. 题目链接:http://codeforces.com/contest/166/problem/E E. Tetrahedro ...

  6. codeforces 489A.SwapSort 解题报告

    题目链接:http://codeforces.com/problemset/problem/489/A 题目意思:给出一个 n 个无序的序列,问能通过两两交换,需要多少次使得整个序列最终呈现非递减形式 ...

  7. codeforces 485A.Factory 解题报告

    题目链接:http://codeforces.com/problemset/problem/485/A 题目意思:给出 a 和 m,a 表示第一日的details,要求该日结束时要多生产 a mod ...

  8. codeforces 483A. Counterexample 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/A 题目意思:给出一个区间 [l, r],要从中找出a, b, c,需要满足 a, b 互质,b, ...

  9. codeforces 479C Exams 解题报告

    题目链接:http://codeforces.com/problemset/problem/479/C 题目意思:简单来说,就是有个人需要通过 n 门考试,每场考试他可以选择ai, bi 这其中一个时 ...

随机推荐

  1. SG函数学习总结

    有点散乱, 将就着看吧. 首先是博弈论的基础, 即 N 和 P 两种状态: N 为必胜状态, P 为必败状态. 对于N, P两种状态, 则有 1. 没有任何合法操作的状态, P; 2. 可以移动到P局 ...

  2. Maven的安装文字版(Windows/Linux/Mac)

    以下内容引用自https://ayayui.gitbooks.io/tutorialspoint-maven/content/book/maven_environment_setup.html,安装信 ...

  3. Android --修改arr文件

    1. 改为zip文件 2. 修改 3. 改后缀

  4. Neural Networks for Machine Learning by Geoffrey Hinton (1~2)

    机器学习能良好解决的问题 识别模式 识别异常 预測 大脑工作模式 人类有个神经元,每一个包括个权重,带宽要远好于工作站. 神经元的不同类型 Linear (线性)神经元  Binary thresho ...

  5. Android自己定义实现循环滚轮控件WheelView

    首先呈上效果图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...

  6. [Algorithm] Write a Depth First Search Algorithm for Graphs in JavaScript

    Depth first search is a graph search algorithm that starts at one node and uses recursion to travel ...

  7. iOS开发UI篇—懒载入

    iOS开发UI篇-懒载入 1.懒载入基本 懒载入--也称为延迟载入,即在须要的时候才载入(效率低,占用内存小).所谓懒载入,写的是其get方法. 注意:假设是懒载入的话则一定要注意先推断是否已经有了. ...

  8. 高速创建和mysql表相应的java domain实体类

    今天创建了一个表有十几个字段,创建完之后必定要写一个与之相应的java domain实体类. 这不是反复的工作吗?为什么不先把这个表的全部的字段查出来,然后放到linux环境下,用sed工具在每一行的 ...

  9. nightwatch testing 注意事项

    coding style 好的測試項目應該盡量不要使用pause 並且要有驗證的機制 .click('input.btn') //.pause(3000) .waitForElementVisible ...

  10. Linaro/Yocto/Openwrt

    http://en.wikipedia.org/wiki/Linaro Linaro From Wikipedia, the free encyclopedia     This article ap ...