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;
}