cf404b

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


一个算精度的题目 唯一的亮点就在于把double转化为int再处理


一开始题目没看清WA了一发,以为输出要判重,结果不要...所以做题要注意A题也是的,就是只要对比对角线,以及非对角线,,我理解成对角线和 四条边,坑。


#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
using namespace std;
typedef long long ll;
struct node
{
    int x, y;
    bool operator <(const node &rhs)const
    {
        if(x != rhs.x)
            return x < rhs.x;
        else
            return y < rhs.y;
    }
};


set <node> memo;


int main()
{
//    freopen("data.in", "r", stdin);
    int n;
    int A, D;
    ll tot;
    double a, d;
    node cur;
    scanf("%lf%lf", &a, &d);
    scanf("%d", &n);
    A = round(a*10000);
    D = round(d*10000);

    cur.x = 0;
    cur.y = 0;
    tot = 0;
    while(n--)
    {
        tot += D;
        if((tot / A) % 4 == 0)//0
        {
            cur.x = tot % A;
            cur.y = 0;
//            if(!memo.count(cur))
            {
                printf("%d.%04d %d.%04d\n", cur.x/10000, cur.x%10000, cur.y/10000, cur.y%10000);
                memo.insert(cur);
            }
        }else if((tot / A) % 4 == 1)//1
        {
            cur.x = A;
            cur.y = tot % A;
//            if(!memo.count(cur))
            {
                printf("%d.%04d %d.%04d\n", cur.x/10000, cur.x%10000, cur.y/10000, cur.y%10000);
                memo.insert(cur);
            }
        }else if((tot / A) % 4 == 2)//2
        {
            cur.x = A - tot % A;
            cur.y = A;
//            if(!memo.count(cur))
            {
                printf("%d.%04d %d.%04d\n", cur.x/10000, cur.x%10000, cur.y/10000, cur.y%10000);
                memo.insert(cur);
            }
        }else if((tot / A) % 4 == 3)//3
        {
            cur.x = 0;
            cur.y = A - tot % A;
//            if(!memo.count(cur))
            {
                printf("%d.%04d %d.%04d\n", cur.x/10000, cur.x%10000, cur.y/10000, cur.y%10000);
                memo.insert(cur);
            }
        }
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值