国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Codeforces 782D Innokenty and a Football League【貪心】

2019-11-06 06:44:22
字體:
供稿:網(wǎng)友

D. Innokenty and a Football Leaguetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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:

the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN",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 clubx. 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 least3 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 printn 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.

ExamplesInput
2DINAMO BYTECITYFOOTBALL MOSCOWOutput
YESDINFOOInput
2DINAMO BYTECITYDINAMO BITECITYOutput
NOInput
3PLAYFOOTBALL MOSCOWPLAYVOLLEYBALL SPBGOGO TECHNOCUPOutput
YESPLMPLSGOGInput
3ABC DEFABC EFGABD OOOOutput
YESABDABEABONote

In the first sample Innokenty can choose first option for both clubs.

In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.

In the third example Innokenty can choose the second options for the first two clubs, and the first option for the third club.

In the fourth example note that it is possible that the chosen short name for some clubx is the same as the first option of another cluby if the first options of x and y are different.

題目大意:

一共有N個隊名,每個隊名包含兩個部分,我們需要給每個隊名一個縮寫,縮寫包含三個字母。

我們對于一個隊伍可以選擇兩種縮寫方式:

第一個字符串取前三個字母。

第一個字符串取前兩個字符,第二個字符串取第一個字母。

要求所有縮寫必須互不相同。

并且要求,如果存在x選1方法縮寫,y選1方法縮寫,那么對應(yīng)如果x選了方案2縮寫,y就不能選第一種方案了。

思路:

分幾種情況:

①對應(yīng)所有隊伍名都按照第一種方式縮寫沒有重復(fù)的情況,那么對應(yīng)輸出所有隊伍都按第一種方案縮寫即可。

②如果存在所有隊伍名都按照第一種方式縮寫的重復(fù)情況,那么嘗試所有隊伍名都按照第二種方案縮寫,如果可以,輸出,如果不行,那就真的不行了。

Ac代碼:

#include<stdio.h>#include<string.h>#include<map>#include<iostream>using namespace std;char b[50],c[50];string a[1005][2];int main(){    int n;    while(cin>>n)    {        map<string,int >s;        map<string,int >s2;        int fst,scd;        fst=scd=1;        for(int i=0;i<n;i++)        {            scanf("%s%s",b,c);            for(int j=0;j<2;j++)            {                a[i][0]+=b[j];                a[i][1]+=b[j];            }            a[i][0]+=b[2];            a[i][1]+=c[0];            if(s[a[i][0]]==0)s[a[i][0]]=1;            else fst=0;            if(s2[a[i][1]]==0)s2[a[i][1]]=1;            else scd=0;        }        if(fst==1)        {            printf("YES/n");            for(int i=0;i<n;i++)cout<<a[i][0]<<endl;        }        else if(scd==1)        {            printf("YES/n");            for(int i=0;i<n;i++)cout<<a[i][1]<<endl;        }        else printf("NO/n");    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 德保县| 庆云县| 双鸭山市| 镇平县| 运城市| 革吉县| 防城港市| 黄平县| 曲水县| 铁岭市| 浑源县| 丹巴县| 泸溪县| 手游| 平利县| 天长市| 定安县| 白朗县| 兰坪| 裕民县| 孝昌县| 奉贤区| 兴山县| 连江县| 河北省| 怀来县| 汝州市| 林口县| 墨江| 德阳市| 鹿泉市| 张家川| 鸡泽县| 连山| 金川县| 交口县| 万全县| 沈阳市| 宜黄县| 福安市| 万荣县|