地址:http://codeforces.com/contest/404/problem/B
题意:运动员在一个a*a的正方形跑道沿着逆时针跑,每隔d米就喝一瓶水,求每次喝水的坐标,题目不难,模拟题一道
开始挂在了第八组上了,代码如下
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; void prin(double s,double len) { int m=(int)floor(s/len); int t=m; double r=s-m*len; t=t%4; switch(t) { case 0: { printf("%.10lf 0.0000000000\n",r);break; } case 1: { printf("%.10lf %.10lf\n",len,r);break; } case 2: { printf("%.10lf %.10lf\n",len-r,len);break; } case 3: { printf("0.0000000000 %.10lf\n",len-r);break; } } } int main() { double a,d; int n,i; scanf("%lf%lf",&a,&d); scanf("%d",&n); for(i=1;i<=n;i++) prin(i*d,a); return 0; }
错误数据:1 100000 100000原因:int造成的精度损失,改成long long 即可正确代码:#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; void prin(double s,double len) { long long m=(long long)floor(s/len); long long t=m; double r=s-m*len; t=t%4; switch(t) { case 0: { printf("%.10lf 0.0000000000\n",r);break; } case 1: { printf("%.10lf %.10lf\n",len,r);break; } case 2: { printf("%.10lf %.10lf\n",len-r,len);break; } case 3: { printf("0.0000000000 %.10lf\n",len-r);break; } } } int main() { double a,d; long n,i; scanf("%lf%lf",&a,&d); scanf("%d",&n); for(i=1;i<=n;i++) prin(i*d,a); return 0; }