ural1721--binary matching--two Sides of the same Coin

Source: Internet
Author: User

Side OnePoll flew above the city. Bright street lights flashed by below. He is winding his around needle-sharp spires of communication towers and wicker grid radiators of thermonuclear power Plants. Express Mail helicopters rushed past him. Suddenly, the neat layout of the streets below was broken. The streets, which used to is straight and parallel, had started to twist and twirl like a bunch of glowing tentacles. Poll soared upwards. Looking down from above, Poll no longer saw streets. Instead, he saw a neural network-live and pulsating with energy. One of the neurons flashed and faded to black. Its neighbours were saturated and burst too. With each impulse, a neuron would reach its neighbour and turn it into light. The wave of flashes was propagating through the neural tissue, consuming and annihilating it. Soon, Poll found himself alone in the dark. The darkness surrounded him, filled his eye sockets and mouth, squeezed his chest. Poll couldn ' t breath, couldn ' t think and The only thing he felt is absolute, total terror ... Poll woke up screaming. His dreams had turned for the worse that week. Vivid, detailed, indistinguishable from reality, but at the same time incoherent and perplexed. Actually, it is a well-known symptom, one of the those that were featured prominently in the sermons of street Preachers from Doomsday Cults. Poll is in a state of denial for a month, but he condition had become too obvious to ignore. He typed "Neurointerface autoinduction syndrome" in him favourite search engine and in a short time found a specialized CL Inic nearby. He registered on the its site and booked a appointment that evening. Poll went to work on foot. Private vehicles were forbidden in the city, and he didn ' t want to suffocate in overcrowded carriages. But the streets were far from deserted either. The buzzing of the crowd is complemented by the screaming ads running on huge screens which were profusely hanged above T He pavement. Poll noticed painfully familiar logo On one of the screens, and a pleasant female voice informed him that "subregional programming Contest would be held in the The city is less than a week. Make sure "Re registered!" Poll had entered a high-rise building and went up to floor 70. The floor housed the jury of the contest mentioned in the advertisement, and Poll is the chairman of the jury. Several people were sitting behind their desktops in a big class. Most of the them were using neurointerfaces, so no clacking of keyboards could is heard. Those people were Poll ' s hand-picked team, they were preparing the problems for the contest. All of them were professionally licensed problemsetters with a rank of 3 or higher. Nevertheless, Poll always verified and approved every problem by himself before a contest. He trusted his team, but the stakes were high-and a second pair of eyes couldn ' t hurt. Poll went to He office, got connected to the internal network via he neurointerface and plunged into the work. The day passed by. Poll NotiCed that it got dark outside if headlights of a fire helicopter flying by his window illuminated the class. He looked at his watch, and realized that he is late for the doctor ' s appointment. He logged off and hurried to the clinic. A nice nurse greeted Poll on the reception and directed him to the Doctor Wasat ' office. Dr. Wasat turned out to being a friendly, sympathetic aged physician, who could easily gain the confidence of his patients. He listened carefully and immediately went to the heart of the problem. After some consideration, he suggested for Poll to undergo brain scanning immediately, to confirm or deny any issues with The Neurointerface. Poll felt relieved that his case had been in the hands of a specialist, and he agreed to the procedure. They went to the neighbouring, where there is a sophisticated device resembling an electric chair. Poll sat down on it. The doctor fixed his head between a hemispheres and stepped away to the control Panel. Poll saw nothing BUT a plain white wall in front of him. He sensed that something is connected to his neurointerface. 
"Don ' t resist it," the doctor said gently.
Poll relaxed. The device hummed to life, sending warm waves through Poll ' s body. Nothing happened to a while, and then suddenly Poll noticed thin sharp spikes extending from the white wall. They were slowly growing, coming closer and closer to him. All of the them were aimed at the his heart. He tried to break free, to dodge, but to no avail. Thousands of white spikes penetrated his chest, pierced he heart, and started to pump bright white light into him. The light displaced blood in he arteries, reached all corners of his body, flooded he mouth, poured out of his eyes. Poll shut his eyes tight and violently writhed.
"Poll! poll! Calm down! It's OK, it's over now! "the doctor ' s voice sounded concerned.
Poll opened his eyes. Doctor Wasat was holding his shoulders and watching him closely. There were neither spikes nor light around. A nurse took Poll back to the office and brought him hot tea. He is sitting there alone for a long time, until Doctor Wasat finally returned. The doctor was gloomy. He sat behind his desk and categorically stated:
"I don ' t want to scare you, but the your condition is very serious indeed. I ' m sure you understand it too. It ' ll get worse. You'll experience visions not be only if you're sleeping, but if you ' re awake too. To is precise, you won ' t is able to distinguish dreams and reality. " They talked for a couple of hours. The doctor promised to help on any-possible, but he couldn ' t guarantee anything. Modern medical science still wasn ' t able to treat such conditions. Poll left the clinic very depressed. The doctor suggested to lift him home in a medical helicopter, but Poll declined. He didn ' t want to go home. He went straight to the local council building, which is the tallest in the neighbourhood. Although its roof is off-limits to the public and Poll happened to know the access code. He climbed the roof, walked up to the edge, and breathed the cool night air. He could see the city up to the horizon. The Twisted city from he dreams, but the usual bustling city of real people. The Reality. With All its flaws, Poll didn ' t want to get detached from it. Better to being dead than to end-in-a straitjacket inside an asylum. 
"Gonna jump?" A female voice from behind caught Poll by surprise.
Poll turned back. A girl, mid-20 ' s, is sitting on an air duct. She grinned and looked down at him.
"Don ' t know," said Poll with a smile. The girl jumped off the duct and walked up to Poll. She stepped on the edge near him and looked down in awe.
"So high ... I ' m Alhena. You? "
"Poll."
They were standing shoulder to shoulder for a few minutes. Poll started to feel a little self-conscious. Alhena broke the silence first:
"So, Poll. Gonna invite me for a date? But not tonight, "she added hastily.
"All right, what about tomorrow?" Poll replied captivatedly.
"That's d be great."
They exchanged their numbers and went down to the street together. Poll tried to follow she, but soon lost she in the crowd. Next Morning Poll is late for work. When he is finally arrived, he found his old friend Castor waiting for him in the office. They had been arranging contests together for a long time. But Castor wasn ' t a problemsetter. From a young age he is passionate about protection of everything. He is responsible for physical and information security of the contests. People called him "Castor-hound" behind his back, but Poll liked him. Maybe because Castor helped Poll deal with several delicate situations and difficult people, earning he deep trust and re Spect. From time-to-time, Castor came to personally update the access codes through the Neurointerface. The employees called this "Castor eating our brains." And when the codes weren ' t updated for some time, someone always asked "when would Castor eat our brains again?" Today is the day. Castor got connectedTo Poll's neurointerface and while the codes were being uploaded, they chatted randomly. When Castor left, Poll was feeling much better. A chat with a friend calmed him down and he is ready for get into gear. He worked hard all day. In the evening he called Alhena and invited hers for dinner. They went to the best restaurant in the neighbourhood. Alhena turned out to be very sociable able to find common ground even with such an extreme introvert as Poll. They talked about a range of things, and Poll felt he really got to know her. The only thing that troubled him is that he couldn ' t figure out what she is doing on the roof, and he didn ' t know how to Ask. After the restaurant they went. She lived alone in a small, tidy apartment. Poll settled on a couch while Alhena poured out both glasses of wine. They toasted the evening and sipped a little. She leaned forward to kiss him ... SideShe leaned forward to kiss him, when suddenly her head jerked up and she gave a shrill scream. Her whole body is shaking with convulsions and she tumbled down to the floor. In a moment, mayhem broke out in the apartment. The main door is pulled out, windows were broken, and a dozen of armed men wearing masks and body armor poured inside. Four of the them grabbed Alhena and dragged her away. Were holding Poll down tight. But Poll didn ' t-even try to struggle, he is dumbfounded by the unexpected twist of the story. A man in the same body armor but without a mask entered the class. Poll, to He utter surprise, recognized his buddy Castor. Castor sat down opposite Poll and grinned. By then, the initial shock is wearing off, and Poll burst out on him:
"Castor, what the hell?" What's going on here? "
"Me Saving your" Again is going on here, "said Castor favorably and in a commanding voice ordered," Release him. "
The Poll off and stepped out. Poll rubbed his left shoulder and asked, frowning:
"What's up with Alhena?"
"She was smashed by the virus I planted into your head today."
"I don ' t understand."
"It's really easy," said Castor, making himself comfortable. "As a matter of fact, you ' re not ill. They somehow managed to hack your brain and infect it with a virus which made you believe you ' ve got a syndrome. Besides, the virus allowed them to make a copy of your memory via the neurointerface without you even noticing it. She just tried to does this very thing. She tried to download your today's memories, memories of all the problems you worked on. But she didn ' t know that I erased their virus from your system and planted mine. I call it Castor-hound, "and he winked at Poll. "Whenever someone tries to connect to the backdoor on your head, Castor-hound starts to eat his brain. You saw the result. "
Poll started to connect the dots.
"and Doctor Wasat ..."
"... is a doctor. You were he first and last patient. He downloaded a good chunk of information from your head, and all the work you do this month. We eventually captured him, but it is too late, he already sold the data. There is no-i-i-Stop the leak now. I ' m afraid the contest should be canceled. " Poll was fuming. He is tricked like a big silly. He stared at Castor and said categorically:
"No, we won ' t cancel the contest. We ' ll prepare new problems.
"Does you have enough time?" How many problems can you prepare simultaneously? "
That is a good question. The contest rules state this every problem should be prepared by the persons Exactly:one should write a statement, the OT Her one should prepare a set of tests. Generally, professional problemsetters has license for only one of the tasks, but some of them can do both. Besides, to eliminate a possibility of conflicts between the problemsetters working on the same problem, the difference of Their ranks should is equal to 2.They had is much time left, so each of the them could prepare only one problem. Poll urgently needed to answer the question:how many problems would the jury is able to prepare for the contest?

Input

The first line contains the number Nof Problemsetters in the Program Committee (2≤ N≤1000). Each of the following NLines contains a problemsetter ' s name, his specialization and he rank separated with spaces. The name consists of up to Latin letters. There is no problemsetters with the same name. Specialization is denoted by one of the three words: ' statements ', ' testdata ', or ' anything ', corresponding to the people Able to write statements, people able to prepare the tests and to the people able to do both. The rank is a integer in range from 3 to 1000.

Output

The first line output the maximal number of problems so can be prepared for the contest. For each of these problems output a line containing the name of a person writing the statement, a space, and the name of a Person preparing the tests. If there is several ways to prepare such an amount of problems the output any one.

Sample Input

input Output
7Poll anything 8Tejat statements 6Mebsuta testdata 6Propus testdata 4Alzir anything 7Mekbuda anything 3Dirah testdata 9
3Poll Mebsutatejat Propusalzir Dirah
Original Blog http://blog.sina.com.cn/s/blog_7c0916330101conm.html
/* Main question: The maximum matching problem, a s a T or one of the two points directly 2 points can be connected to all eligible edges are connected to all sides of the Hungarian algorithm code is the Hungarian algorithm adjacency table notation, a bit of God! Continue is designed to determine S-tree and T-tree for easy output order */#include <cstdio> #include <cstring> #include <algorithm> #include < Map> #include <iostream>using namespace Std;const int MAX = + + 10;int Head[max], Vis[max], match[max];struct Ed    ge{int u, v; int next;} B[max];int E, N;map <int, string> g;char s[max];int a[max][2];int find (int u) {for (int i = head[u]; I! =-1; i =            B[i].next) {int v = b[i].v;//Here is a bit different from the general wording if (!vis[v]) {vis[v] = 1;                if (match[v] = = 1 | | find (MATCH[V])) {Match[v] = u;            return true; }}} return false;}    void Add (int u, int v) {b[e].v = v;    B[e].next = Head[u]; Head[u] = e++;}    void Inti () {string ss;    int m;    G.clear ();    int E = 0;         for (int i = 1; I <= n; i++) {cin >> SS;        G[i] = SS;        scanf ("%s%d", S, &m);          if (s[0] = = ' a ')   A[i][0] = 0;        else if (s[0] = = ' s ') a[i][0] = 1;        else a[i][0] = 2;    A[i][1] = m;    }} int main () {while (~SCANF ("%d", &n)) {inti ();    Memset (Head,-1, sizeof (head));        for (int i = 1; I <= n; i++) {if (A[i][1]% 4 >= 2) continue;            for (int j = 1; J <= N; j + +) {if (A[j][1]% 4 < 2) continue; if (a[i][1] + 2 = = A[j][1] | | a[i][1] = = A[j][1] + 2) if (a[i][0] = = 0 | | a[j][0] = = 0 | | (A[i][0] = = 1 && a[j][0] = = 2) | |                    (A[i][0] = = 2 && a[j][0] = = 1))        Add (i, j);    }} memset (Match,-1, sizeof (match));    int ans = 0;        for (int i = 1; I <= n; i++) {if (A[i][1]% 4 >=2) continue;        memset (Vis, 0, sizeof (VIS));    if (find (i)) ans++;    } printf ("%d\n", ans);        for (int i = 1; I <= n; i++) {if (A[i][1]% 4 < 2) continue;        if (match[i] = =-1) continue; if (a[i][0] = = 1) cout <<        G[i] << "<< g[match[i]" << Endl;        else if (a[i][0] = = 2) cout << G[match[i]] << "<< g[i] << Endl; else {if (a[match[i]][0] = = 1) cout << G[match[i]] << "<< G[i] << End            L        else cout << G[i] << "<< g[match[i] << Endl; }}} return 0;}

  

ural1721--binary matching--two Sides of the same Coin

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.