Codeforces Round #237 (Div. 2)B. Marathon解题报告

地址: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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值