Cod sursa(job #2624869)

Utilizator marian222200Dimofte Marian marian222200 Data 5 iunie 2020 16:01:50
Problema Numarare triunghiuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.71 kb
// tema_sd_mare.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include<fstream>
#include<algorithm>
#define N 30001
using namespace std;
ifstream cin("nrtri.in");
ofstream cout("nrtri.out");
int fr[N];
int nr[N];
void citire() {
	int n, i, x;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x;
		fr[x]++;
	}
}
void precalculare() {
	nr[0] = fr[0];
	for (int i = 1; i < N; i++)nr[i] = nr[i - 1] + fr[i];
}
int rez() {
	int i, s = 0, a, b, c, nrc;		///a,b,c-am notat laturile triunghiului
	for (i = 0; i < N; i++) 
	if(fr[i]!=0){
		a = i;
		if (fr[a] >= 3)s += (fr[a] - 2);///triunghi echilateral
		cout << s << " ";
		for (b = a - 1; b >a/2; b--) {
			nrc = nr[b - 1] - nr[a - b - 1];
			s += nrc * fr[i];
		}
		cout << s << " ";
		if (fr[a / 2] >= 2)s += (fr[a] - 1);///isoscel
		cout << s << "\n";
	}
	return s;
}
int main() {
	citire();
	for (int i = 0; i < N; i++)cout << fr[i] << " ";
	cout << "\n";
	precalculare();
	for (int i = 0; i < N; i++)cout << nr[i] << " ";
	cout << "\n";
	cout << rez();
	return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file