Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.
As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters.
Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2·d, ..., n·d meters.
The first line contains two space-separated real numbers a and d (1 ≤ a, d ≤ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.
The second line contains integer n (1 ≤ n ≤ 105) showing that Valera needs an extra drink n times.
Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers i·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4.
Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.
2 5 2
1.0000000000 2.0000000000 2.0000000000 0.0000000000
4.147 2.8819 6
2.8819000000 0.0000000000 4.1470000000 1.6168000000 3.7953000000 4.1470000000 0.9134000000 4.1470000000 0.0000000000 2.1785000000 0.7034000000 0.0000000000
题意:在一个正方形边长为a的跑道跑步,起点位置在(0,0),逆时针跑,每距离d给一次水,一共给n次水,求每次给水的坐标
简单的模拟一下,注意一下浮点型取模就行,要用到fmod函数,用这个函数要math.h头文件,可以对浮点型进行取模运算,如果转化成整数再做运算会有误差,精度丢失较严重
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
#define pi acos(-1.0)
#define eps 1e-15
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))
const int inf=0x3f3f3f3f;
double a,d;
double ans[100005][2];
int n;
int A,D;
int main()
{
while(~sf("%lf%lf",&a,&d))
{
double l=a*4.0;
sf("%d",&n);
for1(i,n)
{
double c=fmod(i*d,l);//浮点型取模
int flag=1;
while(c-a>0)//确定在哪一条边上
c-=a,flag++;
if(fabs(c-a)<eps)//eps要定义的足够小,不然就WA了
c=0.0,flag++;
if(flag==4)
pf("%.10lf %.10lf\n",0.0,a-c);
else if(flag==1)
pf("%.10lf %.10lf\n",c,0.0);
else if(flag==2)
pf("%.10lf %.10lf\n",a,c);
else
pf("%.10lf %.10lf\n",a-c,a);
}
}
return 0;
}