Description:
There are n special inns on the Lijiang River, which are numbered from 1 to n in order of location. Each inn is decorated in a certain color tone (K in total, with an integer of 0 ~ K-1 said), and each Inn has a coffee shop, each coffee shop has their own minimum consumption.
The two tourists traveled to Lijiang together. They liked the same color and wanted to try two different inns, so they decidedLiving in two inns with the same color. In the evening, they plan to choose a coffee shop and ask the coffee shop to be located between the two inns (including the inn where they live). The minimum consumption of the coffee shop is no more than P.
They want to know the total number of options for accommodation, so that they can find a coffee shop with a minimum consumption of no more than P yuan in the evening.
Thought: A simple combination makes such a look... !!! If it is difficult, the result is all the numbers minus the numbers that do not match. Note that each operation is performed on the same color. Finally, C (n, 2) (Two combinations in n) = N * (n-1)/2... This question tells us that the idea of mathematics should be carried out in Oi, And oi should also be carried out in mathematics...
Code:
# Include <iostream> # include <cstdio> using namespace STD; int sum [51] = {0}, Summ [51] = {0}; long ans = 0, agans = 0; int main () {int N, K, P, I, j, CO, VA; CIN> N> K> P; for (I = 1; I <= N; ++ I) {CIN> Co> Va; ++ Co; ++ sum [CO]; if (va <= P) for (j = 1; j <= K; ++ J) {agans = agans + (summ [J] * (summ [J]-1)/2; summ [J] = 0;} else ++ summ [CO];} for (I = 1; I <= K; ++ I) {ans = ans + (sum [I] * (sum [I]-1)/2; agans = agans + (summ [I] * (summ [I]-1)/2;} cout <ANS-agans <Endl;
}
Codevs1135 select Inn (2011noip raise Group)