USACO 2.1.2 – Ordered Fractions


#include <cstdio>

using namespace std;
int n;
void gen(pair<int, int> a, pair<int, int> b){
	if(a.second+b.second>n)
		return;
	pair<int, int> mid = make_pair(a.first+b.first, a.second + b.second);
	gen(a, mid);
	printf("%d/%d\n", mid.first, mid.second);
	gen(mid, b);
}
int main() {
	freopen("frac1.in", "r", stdin), freopen("frac1.out", "w", stdout);
	scanf("%d", &n);
	puts("0/1");
	gen(make_pair(0, 1), make_pair(1, 1));
	puts("1/1");
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: