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

题目:http://codeforces.com/contest/404/problem/B

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 int main()
 9 {
10     __int64 g;   //g一定要是长整形,因为数据会超int.这个也是错误的最主要原因
11     int n, i;
12     double a, d, x, y, sum, cnt;
13     while(~scanf("%lf%lf%d", &a, &d, &n))
14     {
15         sum = (double)(a*4);
16         for(i = 1; i <= n; i++)
17         {
18             cnt = (double)i*d;
19 
20             g =(long long)(cnt/sum); //这里一定把要转换的部分加上括号
21             cnt = (double)(cnt-g*sum);
22             if(cnt-a<=0)
23             {
24                 y = 0;
25                 x = cnt;
26             }
27             else if(cnt-2*a<=0)
28             {
29                 x = a;
30                 y = cnt-a;  
31             }
32             else if(cnt-3*a<=0)
33             {
34                 x = a-(cnt-2*a);
35                 y = a;
36             }
37             else
38             {
39                 x = 0;
40                 y = a-(cnt-3*a);
41             }
42             printf("%.10lf %.10lf\n", x, y);
43         }
44     }
45     return 0;
46 }

 

posted @ 2014-03-22 02:18  水门  阅读(186)  评论(0编辑  收藏  举报