zoukankan      html  css  js  c++  java
  • D. Innokenty and a Football League

    Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.

    Each club's full name consist of two words: the team's name and the hometown's name, for example, "DINAMO BYTECITY". Innokenty doesn't want to assign strange short names, so he wants to choose such short names for each club that:

    1. the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN",
    2. or, the first two letters of the short name should be the same as the first two letters of the team's name, while the third letter is the same as the first letter in the hometown's name. For the mentioned club it is "DIB".

    Apart from this, there is a rule that if for some club x the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club x. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team's name, and "N" is the first letter of hometown's name. Of course, no two teams can have the same short name.

    Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen.

    Input

    The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.

    Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20.

    Output

    It it is not possible to choose short names and satisfy all constraints, print a single line "NO".

    Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.

    If there are multiple answers, print any of them.

    然后这个问题要是转化为图形语言的话,感觉这个问题就是很容易的解决了,所以我现在画个图。

    每个club能选择两个名字,保证选的n个名字不会相同,并且要是选择x2,如果y1==x1就不能选择y1,同理。。。

    这就是大致的题意,如果我把题目画成这个图,感觉题目就能很容易的解决出来了,所以基本的思路就是2-sat.然后把路径输出就行了。

    定义两个状态要是选择第一个名字定义为1,否则的话就是定义为0。所以我们现在要做的就是for循环枚举每一个状态,然后就是套用模板就行了。

  • 相关阅读:
    div错位解决IE6、IE7、IE8样式不兼容问题
    DIV背景半透明文字不半透明的样式
    Div 自适应屏幕大小
    mysql 设置外键 四大属性 CASCADE SET NULL NO ACTION RESTRICT 理解
    msyql 主从配置
    全国最新区划数据-四级-省-市-县(区)-乡(镇)
    ThinkPHP3.2 伪静态配置
    色彩网站
    Javascript php 异常捕获
    jQuery 操作大全
  • 原文地址:https://www.cnblogs.com/Heilce/p/6511432.html
Copyright © 2011-2022 走看看