[BZOJ5044]岛屿生成

[BZOJ5044]岛屿生成

试题描述

小Q设计了一款2D游戏,它的地图建立在二维笛卡尔坐标系上。这个游戏最大的特色就是可以随机生成地图,但是岛屿生成却给小Q带来了巨大的麻烦。一个岛屿可以看成一个恰好有 \(n\) 个顶点的简单多边形,每个顶点的坐标都必须是整数,同时为了防止精度误差,每条边的长度也必须是整数。为了体现程序的随机性,任何一条边都不能与 \(x\) 轴或者 \(y\) 轴平行。当然,这个多边形不能自交,也不允许连续 \(3\) 个点共线。请写一个程序帮助小Q实现岛屿生成功能。

输入

第一行包含一个正整数 \(n(3 \leq n \leq 1000)\),表示多边形的点数。

输出

输出 \(n\) 行,每行两个整数 \(x_i,y_i(|x_i|,|y_i| \leq 10000)\),按顺时针或者逆时针顺序依次输出每个顶点的坐标。

若有多组解,输出任意一组。

输入示例

3

输出示例

0 0
4 3
-20 21

数据规模及约定

见“输入”和“输出

题解

有趣的构造题。

考验想象力的时候到了。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;

const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
	if(Head == Tail) {
		int l = fread(buffer, 1, BufferSize, stdin);
		Tail = (Head = buffer) + l;
	}
	return *Head++;
}
int read() {
	int x = 0, f = 1; char c = Getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = Getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = Getchar(); }
	return x * f;
}

int main() {
	int n = read();
	
	if(n == 3) return puts("0 0\n4 3\n-20 21"), 0;
	int x = 0;
	if(n & 1) {
		puts("0 0\n-32 -24\n40 72\n136 0");
		int m = n - 4 >> 1; x = 136;
		for(int i = 1; i <= m; i++, x += 8) printf("%d 3\n%d 0\n", x + 4, x + 8);
	}
	else {
		puts("0 0");
		int m = n - 1 >> 1;
		for(int i = 1; i <= m; i++, x += 8) printf("%d 3\n%d 0\n", x + 4, x + 8);
	}
	printf("%d -%d\n", x >> 1, (x >> 1) / 4 * 3);
	
	return 0;
}
posted @ 2017-10-04 14:05  xjr01  阅读(456)  评论(0编辑  收藏  举报