Pagini recente » Cod sursa (job #921142) | Cod sursa (job #380858) | Cod sursa (job #386189) | Cod sursa (job #1382655) | Cod sursa (job #2624873)
// 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