Sicily 13859. Farmer John has no Large Brown Cow

Source: Internet
Author: User

13859. Farmer John has no Large Brown Cow Constraints

Time limit:1 secs, Memory limit:256 MB

Description

Farmer John likes to collect as many different types of cows as possible. In fact, he had collected almost every conceivable type of cow, except for a few, written on a short list of N lines (1 &L t;= N <= 100). The list looks like this:

Farmer John has no large brown noisy cow.
Farmer John had no small white silent cow.
Farmer John has no large spotted noisy cow.

Each item in the list describes a missing cow in terms of a short list of adjectives, and each item contains the same numb Er of adjectives (3, in this case). The number of adjectives per line is in the range 2..30.

Farmer John had a cow fitting every other possible adjective combination not on the his list. In this example, the first adjective can be large or small, the second can is brown, white, or spotted, and the third can Be noisy or silent. This gives 2 x 3 x 2 = different combinations, and Farmer John have a cow fitting each one, except for those Specificall Y mentioned on the his list. In this example, a large, white, noisy cow are one of his 9 cows. Farmer John was certain that he had at the most 1,000,000,000 cows.

If Farmer John lists his cows in alphabetical order, what's the Kth cow in this list?

Input

* Line 1:two integers, N and K.

* Lines 2..1+n:each Line was a sentence like ' Farmer John has no large spotted ' noisy '. Each adjective in the sentence is a string of at most lowercase letters. You know your reached the end of the sentence when you see the string "cow." ending with a period.

Output

* Line 1:the Description of the Kth cow on the farm.

Sample Input
3 7Farmer John has no large brown noisy cow. Farmer John had no small white silent cow. Farmer John has no large spotted noisy cow.
Sample Output
Small spotted noisy
Hint

In the sample, the input matches the sample given in the problem statement above. Farmer John would like to know the 7th cow on the He farm, when listed in alphabetical order. Farmer John had cows matching the following descriptions, listed in alphabetical order:

Large brown Silent
Large spotted silent
Large white Noisy
Large white Silent
Small brown Noisy
Small brown Silent
Small spotted noisy
Small spotted silent
Small white Noisy

The 7th cow in this list is described as "small spotted noisy".

Problem Source

2015 The second game of every Monday

The combination number and the non-existent combination number can be calculated directly.

#include <iostream> #include <string> #include <set> #include <algorithm> #include <vector  >using namespace Std;int N, k;vector<set<string> > adj;  All adjectivesvector<int> adjnum;  adjective numberset<vector<string> > nonexist; The nonexisted adjectivesint Main () {Std::ios::sync_with_stdio (false); Cin >> n >> k;for (int i = 0; i < N  i++) {string temp;vector<string> adjtemps; Adj in a sentence, horizontalint pos = 0;while (temp! = "no") Cin >> Temp;while (1) {cin >> temp;if (temp = = "cow.")  Break;adjtemps.push_back (temp); if (Pos >= adj.size ()) {set<string> Adjeachpos; Adj at a position, Verticaladjeachpos.insert (temp); Adj.push_back (Adjeachpos);} else {Adj[pos].insert (temp);} pos++;} Nonexist.insert (adjtemps);} if (n = = 1) return 0;adjnum.resize (Adj.size ()), for (int i = Adj.size ()-1, num = 1; I >= 0; i--) {Adjnum[i] = Num;num *= adj[i].size ();} Vector<int> NONEXISTPOS;for (set<vector<string> >::iterator iter = Nonexist.begin (); ITER! = Nonexist.end (); iter++) {int num = 0; The order number of a string of adj which is nonexistedfor (int i = 0; i < iter->size (); i++) {int pos = 0;for (s Et<string>::iterator iter2 = Adj[i].begin (); Iter2! = Adj[i].end (); iter2++) {if (*iter2! = (*iter) [i]) pos++;else break;} num + = pos * Adjnum[i];} Nonexistpos.push_back (num);}  k--; The are at the 0 positionsort (Nonexistpos.begin (), Nonexistpos.end ()) and for (int i = 0; i < nonexistpos.size (); i++) { if (Nonexistpos[i] <= k) k++;} for (int i = 0; i < adj.size (); i++) {int pos = k/adjnum[i];k%= adjnum[i];for (set<string>::iterator iter = AD J[i].begin (); Iter! = Adj[i].end (); iter++) {if (pos = = 0) {if (i) cout << ""; cout << *iter;break;} pos--;}} cout << Endl;return 0;}


Sicily 13859. Farmer John has no Large Brown Cow

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.