Rogu P1311: Select Inn, rogu p1311 Inn

Source: Internet
Author: User

Rogu P1311: Select Inn, rogu p1311 Inn
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 decided to live in the 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.

Input/Output Format

Input Format:

 

Enter the file hotel. in, n + 1 lines in total.

The three integers n, k, and p in the first line are separated by a space, indicating the number of inns, the number of tones, and the maximum value of acceptable minimum consumption;

There are two integers in the next n rows, I + 1, which are separated by a space to represent the decorative tones of inn I and the lowest consumption of the coffee shop of inn I.

 

Output Format:

 

The output file name is hotel. out.

The output contains only one row and an integer, indicating the total number of optional accommodation schemes.

 

Input and Output sample input sample #1:
5 2 3 0 5 1 3 0 2 1 4 1 5 
Output sample #1:
3
Description

[Input and output sample description]

Two people want to stay in the same color Inn. All optional accommodation schemes include: Stay inn ①, ② ④, ② ⑤, ④, But if you choose to stay in inn No. 4 and No. 5, 4. The minimum consumption of a coffee shop between inns on the 5 th is 4, and the minimum consumption that the two can afford is 3 yuan, so they do not meet the requirements. Therefore, only the first three solutions are available.

[Data Scope]

For 30% of data, n ≤ 100;

For 50% of data, n ≤ 1,000;

For 100% of data, there are 2 ≤ n ≤ 200,000, 0 <k ≤ 50, 0 ≤ p ≤ 100, 0 ≤ minimum consumption ≤ 100.

 

Brute force attacks are good, so you can easily get 60 points

I have come up with a solution that uses the concept of rejection. The solution is similar to the normal solution, but it has not been called for a long time ..

Positive Solution:

The prefix and concept are used to record the appearance location of each color and enumerate the number of occurrences of each color,

If a range meets the requirements, you can use the prefix and the number of feasible solutions for this point and other points within the time of O (1 ).

 

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <deque> 6 # include <ctime> 7 # include <cstdlib> 8 # include <algorithm> 9 using namespace std; 10 const int MAXN = 201; 11 inline void read (int & n) 12 {13 char c = getchar (); n = 0; bool flag = 0; 14 while (c <'0' | c> '9') c = '-'? Flag = 1, c = getchar (): c = getchar (); 15 while (c> = '0' & c <= '9 ') n = n * 10 + c-48, c = getchar (); flag = 1? N =-n: n = n; 16} 17 int happen [51]; 18 int how [51] [200001]; 19 int sum [200001]; 20 struct node21 {22 int color; 23 int spend; 24} house [200001]; 25 int main () 26 {27 int n, k, p; 28 read (n ); read (k); read (p); 29 for (int I = 1; I <= n; I ++) 30 {31 read (house [I]. color); read (house [I]. spend); 32 how [house [I]. color] [++ happen [house [I]. color] = I; // time stamp 33 if (house [I]. spend <= p) sum [I] = sum [I-1] + 1; 34 else sum [I] = sum [I-1]; 35} 36 int ans = 0; 37 for (int I = 0; I <k; I ++) 38 {39 for (int j = 1; j <= happen [I]; j ++) // enumerate the number of occurrences of each color for 40 for (int k = j + 1; k <= happen [I]; k ++) 41 if (sum [how [I] [k]-sum [how [I] [j]-1]) 42 {ans = ans + happen [I]-(k-1); break;} 43} 44 printf ("% d", ans); 45 46 return 0; 47}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.