Cod sursa(job #1709086)

Utilizator UAICHePoBaMaHePoBaMa UAICHePoBaMa Data 28 mai 2016 10:50:54
Problema Consecutive Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.86 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class s {
public:
	int start, end;
};

bool comp(s s1, s s2)
{
	return s1.end - s1.start < s2.end - s2.start;
}
int main()
{
	ifstream fin("consecutive.in");
	ofstream fout("consecutive.out");
	int n, x,i;
	s S;
	vector<s> v;
	fin >> n;
	for (i = 0; i < n; i++)
	{
		fin >> x;
		int s=1;
		int a =1, b = 1;
		while (b <= (x+1) / 2)
		{
			if (s < x)
			{
				b++;
				s = s + b;
			}
			else if (s == x)
			{
				//fout << a << " " << b << endl;
				S.start = a;
				S.end = b;
				v.push_back(S);
				s = s - a;
				a++;
			}
			else
			{
				s = s - a;
				a++;
			}
			
		}
	}
	sort(v.begin(), v.end(), comp);
	fout << v.size()<<endl;
	for (i = 0; i < v.size(); i++)
	{
		fout << v[i].start << " " << v[i].end << endl;
	}
}