PTA ----バレンタインデーの特別な

私は思い出を忘れることができない川、左岸のようなチェロの音は、右岸には、私は悲しみのタッチだった一年間、私の愛は明るいを食いしばっ価値真ん中の流れです。

                                          L1-1 PTAは私がリフレッシュされます(5点)

PTAは私が.JPGリフレッシュします

これらは、湖北大学経済学部の学生の傑作です。この質問はピンインで出力するため、これらの言葉をお聞きします。

入力フォーマット:

この問題は、入力されていません。

出力フォーマット:

出力線、端に感嘆符による試料中。

サンプル入力:

出力例:

PTA shi3 wo3 jing1 shen2 huan4 fa1 !
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int main(){
    cout<<"PTA shi3 wo3 jing1 shen2 huan4 fa1 !"<<endl;
    return 0;
}

                                                     L1-2 6がオン(15分)

666.JPG

「666」は、おそらく我々は平均賞賛する、非常に強力な人である、ネットワーク言語です。最近の手段は、別の番号「9」、生み出された「6を投入し、」あまりにも多くの意味があります。あなたは、これが強力なの最高レベルであると考えられる場合は、あなたしている間違った - それは3「9」であったため、現在の最高レベルは、番号「27」です!

この質問は、「...... 6666 6」のみのシリーズで、廃止されたものを、プログラムを書くために、最新の高レベルの発現に翻訳表現感嘆文を、お聞きします。

入力フォーマット:

行の所与の入力文ではなく、より多くの1,000文字、数字、スペース、キャリッジリターンで終了することにより、すなわち、非空の文字列。

出力フォーマット:

左から右へスキャン入力文:文が連続つ以上6を有している場合、この文字列は、連続6 9によって置換される;より9連続6以上ある場合、この文字列は、連続的に置き換えられます6 27。それが出力されるように、その他のコンテンツは、影響を受けません。

サンプル入力:

it is so 666 really 6666 what else can I say 6666666666

出力例:

it is so 666 really 9 what else can I say 27
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
string s;
int main()
{
    getline(cin, s);
    int l=s.length();
    for(int i=0; i<l; i++)
    {
        int t=0;
        if(s[i]=='6')
        {
            for(int j=i; j<l; j++)
            {
                if(s[j]=='6')
                    t++;
                else
                    break;
            }
            if(t>3&&t<=9)
            {
                printf("9");
                i+=t-1;
                continue;
            }
            else if(t>9)
            {
                printf("27");
                i+=t-1;
                continue;
            }
        }
        printf("%c",s[i]);
    }
    return 0;
}

                                                    ベンノックL1-3(20点)

早く寝ボディケアのコード農家を促す毎日自称「ビッグベンV」男、リングベルマイクロブログがあります。ベルを鳴らすためにいくつかの楽しみを追加するには、だけでなく、悪い、いくつかの古代の詩を変更します。バート・変更の方法は次のとおりです。言葉に変更文の終わり、古代の詩は韻「オング」を押して検索するためにオンラインに「ベンをノック。」例えば、有名な唐の詩人李彼は言っている:「Xunzhangzhaiju古い彫刻昆虫アリア時にカーテン吊りヒスイの弓」「ワーム」(チョン)および(ゴング)「ボウが」韻「オング」押され、。この詩がに悪化していたので、「Xunzhangzhaiju古い彫刻昆虫、アリアはカーテンがベンをノックしたとき。」

あなたはに悪い韻文「オング」自動的にプレスにプログラムを書くためにあなたを求めて、詩の言葉の多くを与えている「ベンをノック。」

入力フォーマット:

まず、入力最初の行での20 Nを超えない正の整数 次いで、所与のピンイン古代詩のNラインが、最後の部分が2つに分かれており、カンマ  , 、ピリオドで区切ら  . 端です。隣接するワード綴りの間のスペースで区切られています。タイトルはアルファベットの各文字がこれ以上6文字以上、文字の各行の長さの合計が100を超えていないことを保証しないし、少なくとも三つの言葉の詩の最後の部分。

出力フォーマット:

各行詩のために、それは韻「オング」圧力か否かが判断されます。すなわち、二つの単語の上下端が終わる「オング」です。この圧力は、悪い面のタイトルの変更、出力フォーマットに入力に従って韻、次に出力方法であれば、そうでない場合、出力  Skipped文をスキップされ、。

サンプル入力:

5
xun zhang zhai ju lao diao chong, xiao yue dang lian gua yu gong.
tian sheng wo cai bi you yong, qian jin san jin huan fu lai.
xue zhui rou zhi leng wei rong, an xiao chen jing shu wei long.
zuo ye xing chen zuo ye feng, hua lou xi pan gui tang dong.
ren xian gui hua luo, ye jing chun shan kong.

出力例:

xun zhang zhai ju lao diao chong, xiao yue dang lian qiao ben zhong.
Skipped
xue zhui rou zhi leng wei rong, an xiao chen jing qiao ben zhong.
Skipped
Skipped
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int main()
{
    int n,flag,t;
    char str[105];
    char s[20]="qiao ben zhong.";
    cin>>n;
    getchar();
    while(n--)
    {
        cin.getline(str,10000,'\n');
        int len=strlen(str);
        flag=1;
        for(int i=0; i<len; i++)
        {
            if(str[i]==','||str[i]=='.')
            {
                if(flag&&str[i-3]=='o'&&str[i-2]=='n'&&str[i-1]=='g')
                    flag=1;
                else
                    flag=0;
            }
        }
        if(flag==1)
        {
            t=3;
            for(int i=len-1; i>=0; i--)
            {
                if(str[i]==' ')
                {
                    t--;
                    if(t==0)
                    {
                        str[i+1]='\0';
                        cout<<str<<s<<endl;
                        break;
                    }
                }
            }
        }
        else
            cout<<"Skipped"<<endl;
    }
    return 0;
}

                                        L1-4心理的な影の領域(5点)

xlyy.JPG

これは心理的な影のエリアチャートです。私たちは皆、彼が一様に動くことができると考えた(青い直線グラフ)、そして後半の先延ばしは、我々が行う傾向にある狂気ラッシュ(赤い折れ線グラフ)の最後の瞬間です。とき宿題レッド、地域の周りの青い線は、私たちの心理的な影の領域です。

座標(x、y)は今、この心理的な影の領域を把握するためにあなたを必要とし、赤ひざを与えます。

入力フォーマット:

入力2は、行のない100以上の正の整数xおよびyが与えられ、X> Yを確保されています。最大値(すなわち、完了期限と最終)の水平および垂直座標は100であると仮定する。

出力フォーマット:

行の出力心理的な影のエリア。

フレンドリーリマインダー:=三角形ベースの長さ×高さ/ 2の領域と、長方形のベース領域=長さ×高さ。5分間のテスト減算問題であまりにも複雑バオ、......

サンプル入力:

90 10

出力例:

4000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int x,y;
double jg,s1,s2,s3;
const int zs=5000;
int main(){
    cin>>x>>y;
    s1=(x*y*1.0)/2;
    s2=(100-x)*y;
    s3=((100-x)*(100-y)*1.0)/2;
    jg=zs-s1-s2-s3;
    cout<<jg<<endl;
    return 0;
}

                                              L1-5新しい脂肪式(10ポイント)

正方形の体重(kg)/身長(m)である:イブニングニュースは、最新のように計算公式ツイッター、肥満を報告します。25以上の場合は、太っています。この質問は、自動的に最終的には人が脂肪とみなされるかを決定するプログラムを書くためにあなたを依頼するようにします。

入力フォーマット:

输入在一行中给出两个正数,依次为一个人的体重(以 kg 为单位)和身高(以 m 为单位),其间以空格分隔。其中体重不超过 1000 kg,身高不超过 3.0 m。

输出格式:

首先输出将该人的体重和身高代入肥胖公式的计算结果,保留小数点后 1 位。如果这个数值大于 25,就在第二行输出 PANG,否则输出 Hai Xing

输入样例 1:

100.1 1.74

输出样例 1:

33.1
PANG

输入样例 2:

65 1.70

输出样例 2:

22.5
Hai Xing
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
double w,h,pd;
int main()
{
    cin>>w>>h;
    pd=w/(h*h);
    printf("%.1f\n",pd);
    if(pd>25)
        cout<<"PANG"<<endl;
    else
        cout<<"Hai Xing"<<endl;
    return 0;
}

                                                L1-6 幸运彩票 (15分)

彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。

输入格式:

输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。

输出格式:

对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.

输入样例:

2
233008
123456

输出样例:

You are lucky!
Wish you good luck.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,sz;
int main()
{
    cin>>n;
    while(n--)
    {
        cin>>sz;
        if(sz/100000+sz/10000%10+sz/1000%10==sz%10+sz%100/10+sz%1000/100)
            cout<<"You are lucky!"<<endl;
        else
            cout<<"Wish you good luck."<<endl;
    }
    return 0;
}

                                            L1-7 吃鱼还是吃肉 (10分)

fish.JPG 肉.JPG

国家给出了 8 岁男宝宝的标准身高为 130 厘米、标准体重为 27 公斤;8 岁女宝宝的标准身高为 129 厘米、标准体重为 25 公斤。

现在你要根据小宝宝的身高体重,给出补充营养的建议。

输入格式:

输入在第一行给出一个不超过 10 的正整数 N,随后 N 行,每行给出一位宝宝的身体数据:

性别 身高 体重

其中性别是 1 表示男生,0 表示女生。身高体重都是不超过 200 的正整数。

输出格式:

对于每一位宝宝,在一行中给出你的建议:

  • 如果太矮了,输出:duo chi yu!(多吃鱼);
  • 如果太瘦了,输出:duo chi rou!(多吃肉);
  • 如果正标准,输出:wan mei!(完美);
  • 如果太高了,输出:ni li hai!(你厉害);
  • 如果太胖了,输出:shao chi rou!(少吃肉)。

先评价身高,再评价体重。两句话之间要有 1 个空格。

输入样例:

4
0 130 23
1 129 27
1 130 30
0 128 27

输出样例:

ni li hai! duo chi rou!
duo chi yu! wan mei!
wan mei! shao chi rou!
duo chi yu! shao chi rou!

 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,xb,h,w;
int main()
{
    cin>>n;
    getchar();
    while(n--)
    {
        cin>>xb>>h>>w;
        if(xb)
        {
            if(h<130)
                cout << "duo chi yu! " ;
            else if(h>130)
                cout << "ni li hai! " ;
            else
                cout << "wan mei! " ;
            if(w<27)
                cout << "duo chi rou!" ;
            else if(w>27)
                cout << "shao chi rou!" ;
            else
                cout << "wan mei!" ;
        }
        else
        {
            if(h<129)
                cout << "duo chi yu! " ;
            else if(h>129)
                cout << "ni li hai! " ;
            else
                cout << "wan mei! " ;
            if(w<25)
                cout << "duo chi rou!" ;
            else if(w>25)
                cout << "shao chi rou!" ;
            else
                cout << "wan mei!" ;
        }
        cout<<endl;
    }
    return 0;
}

                               L1-8 估值一亿的AI核心代码 (20分)

AI.jpg

以上图片来自新浪微博。

本题要求你实现一个稍微更值钱一点的 AI 英文问答程序,规则是:

  • 无论用户说什么,首先把对方说的话在一行中原样打印出来;
  • 消除原文中多余空格:把相邻单词间的多个空格换成 1 个空格,把行首尾的空格全部删掉,把标点符号前面的空格删掉;
  • 把原文中所有大写英文字母变成小写,除了 I
  • 把原文中所有独立的 can youcould you 对应地换成 I canI could—— 这里“独立”是指被空格或标点符号分隔开的单词;
  • 把原文中所有独立的 I 和 me 换成 you
  • 把原文中所有的问号 ? 换成惊叹号 !
  • 在一行中输出替换后的句子作为 AI 的回答。

输入格式:

输入首先在第一行给出不超过 10 的正整数 N,随后 N 行,每行给出一句不超过 1000 个字符的、以回车结尾的用户的对话,对话为非空字符串,仅包括字母、数字、空格、可见的半角标点符号。

输出格式:

按题面要求输出,每个 AI 的回答前要加上 AI: 和一个空格。

输入样例:

6
Hello ?
 Good to chat   with you
can   you speak Chinese?
Really?
Could you show me 5
What Is this prime? I,don 't know

输出样例:

Hello ?
AI: hello!
 Good to chat   with you
AI: good to chat with you
can   you speak Chinese?
AI: I can speak chinese!
Really?
AI: really!
Could you show me 5
AI: I could show you 5
What Is this prime? I,don 't know
AI: what Is this prime! you,don't know
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int N;
int main()
{
    cin>>N;
    getchar();
    while(N--)
    {
        string s,S[1010],s1;
        int cnt=0;
        getline(cin,s);
        cout<<s<<endl;
        cout<<"AI:";
        for(int i=0; i<s.size(); i++)
        {
            if(isalnum(s[i]))
            {
                if(s[i]!='I')
                    s[i]=tolower(s[i]);
            }
            else
            {
                s.insert(i," ");
                i++;
            }
            if(s[i]=='?')
                s[i]='!';
        }
        stringstream ss(s);
        while(ss>>s1)
            S[cnt++]=s1;
        if(!isalnum(S[0][0]))
            cout<<" ";
        for(int i=0; i<cnt; i++)
        {
            if(!isalnum(S[i][0]))
                cout<<S[i];
            else if(S[i]=="can"&&(i+1<cnt&&S[i+1]=="you"))
            {
                cout<<" I can";
                i++;
            }
            else if(S[i]=="could"&&(i+1<cnt&&S[i+1]=="you"))
            {
                cout<<" I could";
                i++;
            }
            else if(S[i]=="I"||S[i]=="me")
                cout<<" you";
            else
                cout<<" "<<S[i];
        }
        cout<<endl;
    }
    return 0;
}

                                           L2-1 特立独行的幸福 (25分)

对一个十进制数的各位数字做一次平方和,称作一次迭代。如果一个十进制数能通过若干次迭代得到 1,就称该数为幸福数。1 是一个幸福数。此外,例如 19 经过 1 次迭代得到 82,2 次迭代后得到 68,3 次迭代后得到 100,最后得到 1。则 19 就是幸福数。显然,在一个幸福数迭代到 1 的过程中经过的数字都是幸福数,它们的幸福是依附于初始数字的。例如 82、68、100 的幸福是依附于 19 的。而一个特立独行的幸福数,是在一个有限的区间内不依附于任何其它数字的;其独立性就是依附于它的的幸福数的个数。如果这个数还是个素数,则其独立性加倍。例如 19 在区间[1, 100] 内就是一个特立独行的幸福数,其独立性为 2×4=8。

另一方面,如果一个大于1的数字经过数次迭代后进入了死循环,那这个数就不幸福。例如 29 迭代得到 85、89、145、42、20、4、16、37、58、89、…… 可见 89 到 58 形成了死循环,所以 29 就不幸福。

本题就要求你编写程序,列出给定区间内的所有特立独行的幸福数和它的独立性。

输入格式:

输入在第一行给出闭区间的两个端点:1<A<B≤10​4​​。

输出格式:

按递增顺序列出给定闭区间 [A,B] 内的所有特立独行的幸福数和它的独立性。每对数字占一行,数字间以 1 个空格分隔。

如果区间内没有幸福数,则在一行中输出 SAD

输入样例 1:

10 40

输出样例 1:

19 8
23 6
28 3
31 4
32 3

注意:样例中,10、13 也都是幸福数,但它们分别依附于其他数字(如 23、31 等等),所以不输出。其它数字虽然其实也依附于其它幸福数,但因为那些数字不在给定区间 [10, 40] 内,所以它们在给定区间内是特立独行的幸福数。

输入样例 2:

110 120

输出样例 2:

SAD
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int pri[10010],mp[10010];
bool pd(int n)
{
    if(n==1)
        return true;
    if(n==4)
        return false;
    int tmp=0;
    while(n>0)
    {
        tmp+=(n%10)*(n%10);
        n/=10;
    }
    mp[tmp]=1;
    return pd(tmp);
}
int dfs(int n,int dep)
{
    if(n==1)
        return dep;
    int tmp=0;
    while(n>0)
    {
        tmp+=(n%10)*(n%10);
        n/=10;
    }
    return dfs(tmp,dep+1);
}
void db()
{
    for(int i=2; i<=10000; i++)
    {
        if(pri[i]==0)
        {
            int j=i;
            while(j*i<=10000)
            {
                pri[i*j]=1;
                j++;
            }
        }
    }
}
int main()
{
    db();
    int a,b;
    int fg=1;
    cin>>a>>b;
    for(int i=a; i<=b; i++)
        if(!pd(i))
            mp[i]=1;
    for(int i=a; i<=b; i++)
    {
        if(mp[i]==0)
        {
            int jg=dfs(i,0);
            if(pri[i]==0)
                jg*=2;
            cout<<i<<" "<<jg<<endl;
            fg=0;
        }
    }
    if(fg)
        cout<<"SAD"<<endl;
    return 0;
}

                                                 L2-2 冰岛人 (25分)

2018年世界杯,冰岛队因1:1平了强大的阿根廷队而一战成名。好事者发现冰岛人的名字后面似乎都有个“松”(son),于是有网友科普如下:

iceland.JPG

冰岛人沿用的是维京人古老的父系姓制,孩子的姓等于父亲的名加后缀,如果是儿子就加 sson,女儿则加 sdottir。因为冰岛人口较少,为避免近亲繁衍,本地人交往前先用个 App 查一下两人祖宗若干代有无联系。本题就请你实现这个 App 的功能。

输入格式:

输入首先在第一行给出一个正整数 N(1<N≤10​5​​),为当地人口数。随后 N 行,每行给出一个人名,格式为:名 姓(带性别后缀),两个字符串均由不超过 20 个小写的英文字母组成。维京人后裔是可以通过姓的后缀判断其性别的,其他人则是在姓的后面加 m 表示男性、f 表示女性。题目保证给出的每个维京家族的起源人都是男性。

随后一行给出正整数 M,为查询数量。随后 M 行,每行给出一对人名,格式为:名1 姓1 名2 姓2。注意:这里的是不带后缀的。四个字符串均由不超过 20 个小写的英文字母组成。

题目保证不存在两个人是同名的。

输出格式:

对每一个查询,根据结果在一行内显示以下信息:

  • 若两人为异性,且五代以内无公共祖先,则输出 Yes
  • 若两人为异性,但五代以内(不包括第五代)有公共祖先,则输出 No
  • 若两人为同性,则输出 Whatever
  • 若有一人不在名单内,则输出 NA

所谓“五代以内无公共祖先”是指两人的公共祖先(如果存在的话)必须比任何一方的曾祖父辈分高。

输入样例:

15
chris smithm
adam smithm
bob adamsson
jack chrissson
bill chrissson
mike jacksson
steve billsson
tim mikesson
april mikesdottir
eric stevesson
tracy timsdottir
james ericsson
patrick jacksson
robin patricksson
will robinsson
6
tracy tim james eric
will robin tracy tim
april mike steve bill
bob adam eric steve
tracy tim tracy tim
x man april mikes

输出样例:

Yes
No
No
Whatever
Whatever
NA
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
struct node
{
    char xb;
    string fa;
};
map<string, node> R;
int judge(string a,string b)
{
    int i=1,j;
    for(string A=a; !A.empty(); A=R[A].fa,i++)
    {
        j=1;
        for(string B=b; !B.empty(); B=R[B].fa,j++)
        {
            if(i>=5&&j>=5)
                return 1;
            if(A==B&&(i<5||j<5))
                return 0;
        }
    }
    return 1;

}
int main()
{
    int n, m;
    string str,a,b;
    cin.sync_with_stdio(false);
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>a>>b;
        if (b.back()=='n')
            R[a]= {'m',b.substr(0,b.size()-4)};
        else if (b.back() == 'r')
            R[a]= {'f',b.substr(0, b.size()-7)};
        else
            R[a].xb=b.back();
    }
    cin>>m;
    for (int i=0; i<m; i++)
    {
        cin>>a>>str>>b>>str;
        if (R.find(a)==R.end()||R.find(b)==R.end())
            printf("NA\n");
        else if(R[a].xb==R[b].xb)
            printf("Whatever\n");
        else
            printf("%s\n", judge(a,b)?"Yes":"No");
    }
    return 0;
}

                                                L2-3 深入虎穴 (25分)

著名的王牌间谍 007 需要执行一次任务,获取敌方的机密情报。已知情报藏在一个地下迷宫里,迷宫只有一个入口,里面有很多条通路,每条路通向一扇门。每一扇门背后或者是一个房间,或者又有很多条路,同样是每条路通向一扇门…… 他的手里有一张表格,是其他间谍帮他收集到的情报,他们记下了每扇门的编号,以及这扇门背后的每一条通路所到达的门的编号。007 发现不存在两条路通向同一扇门。

内线告诉他,情报就藏在迷宫的最深处。但是这个迷宫太大了,他需要你的帮助 —— 请编程帮他找出距离入口最远的那扇门。

输入格式:

输入首先在一行中给出正整数 N(<10​5​​),是门的数量。最后 N 行,第 i 行(1≤i≤N)按以下格式描述编号为 i 的那扇门背后能通向的门:

K D[1] D[2] ... D[K]

其中 K 是通道的数量,其后是每扇门的编号。

输出格式:

在一行中输出距离入口最远的那扇门的编号。题目保证这样的结果是唯一的。

输入样例:

13
3 2 3 4
2 5 6
1 7
1 8
1 9
0
2 11 10
1 13
0
0
1 12
0
0

输出样例:

12

 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,k,t,s,mx,jg,arr[100005],cd[100005],vis[100005];
vector <int> V[100005];
void dfs(int x)
{
    queue<int> Q;
    Q.push(x);
    mx=-1;
    cd[x]=0;
    vis[x]=1;
    jg=x;
    while(!Q.empty())
    {
        int ft=Q.front();
        Q.pop();
        for(int i=0; i<V[ft].size(); i++)
        {
            if(vis[V[ft][i]]==0)
            {
                vis[V[ft][i]]=1;
                cd[V[ft][i]]=cd[ft]+1;
                if(cd[V[ft][i]]>mx)
                {
                    mx = cd[V[ft][i]];
                    jg = V[ft][i];
                }
                Q.push(V[ft][i]);
            }
        }
    }
    return;
}
int main()
{
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> k;
        for(int j=0; j<k; j++)
        {
            cin>>t;
            arr[t]++;
            V[i].push_back(t);
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(arr[i]==0)
        {
            s=i;
            break;
        }
    }
    dfs(s);
    cout<<jg<<endl;
    return 0;
}

                                                       L2-4 彩虹瓶 (25分)

rb.JPG

彩虹瓶的制作过程(并不)是这样的:先把一大批空瓶铺放在装填场地上,然后按照一定的顺序将每种颜色的小球均匀撒到这批瓶子里。

假设彩虹瓶里要按顺序装 N 种颜色的小球(不妨将顺序就编号为 1 到 N)。现在工厂里有每种颜色的小球各一箱,工人需要一箱一箱地将小球从工厂里搬到装填场地。如果搬来的这箱小球正好是可以装填的颜色,就直接拆箱装填;如果不是,就把箱子先码放在一个临时货架上,码放的方法就是一箱一箱堆上去。当一种颜色装填完以后,先看看货架顶端的一箱是不是下一个要装填的颜色,如果是就取下来装填,否则去工厂里再搬一箱过来。

工場出荷のオーダーは、より良い、労働者が正常にロード完了することができます。図7は、例えば、色の順序に従って、充填、7に従って次への2つの非混和性7.6ロードされた色を取得するために、この順序に応じて作業者が7,6,1,3,2,5,4工場出荷しました棚上のスタックのために6; 1を得るために直接ロードすることができ、3時間及びカラーボックス6の仮コード番号を取得する必要があり、図2は、取得直接ロードすることができ、続いて上部棚3から取り外さがロードされ;最後に色番号4に直接ロードした取る;次いで5、仮コードの上方に配置された6は、取得したまま、順次5,6,7が順次ロード棚から除去されます。

複数のボックスの後に記入カラーパッケージ2は、棚の上に下に移動していないので、この順番3,1,5,4,2,6,7にしたがって工場出荷場合、労働者は、怒りトスの棚でなければなりませんあなたは成功したタスクを完了することは不可能である、第3のボックスを取得します。

財の蓄積は、労働者の能力を超えた場合に加えて、限られた容量の棚には、タスクを正常に完了するための方法はありません。棚が十分に高いである場合7,6,5,4,3,2,1この順序に従って工場出荷などの、ボックス6を積層することができ、それはまだ正常に完了することができる;しかし棚ボックスは5人を積層した場合にのみ私たちは怒りを持っている......

この質問は、植物は、労働者が正常にタスクを完了するために出荷されたかどうか、自分自身で判断をお願いします。

入力フォーマット:

まず、入力3つの正の整数の1行目に、それぞれ、虹色のボトルの数N(1 <N≤103)、一時棚M(<N)の容量、および必要は配達の順序を決定します数K.

次いで、Nデジタル与えられたのK行は、植物の配信順序に対応する、Nを1に配置されています。

デジタル行がスペースで区切られています。

出力フォーマット:

作業者は、各配信順序の行に出力を完成するにとどまることができる場合は  YES、そうでなければ出力  NO

サンプル入力:

7 5 3
7 6 1 3 2 5 4
3 1 5 4 2 6 7
7 6 5 4 3 2 1

出力例:

YES
NO
NO
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n,m,k,x;
int main()
{
    cin>>n>>m>>k;
    while(k--)
    {
        int j=0;
        vector<int> zs,xz;
        for(int i=1; i<=n; i++)
        {
            cin>>x;
            zs.push_back(x);
            xz.push_back(i);
        }
        stack<int> st;
        for(int i=0; i<n; i++)
        {
            if(zs[i]!=xz[j])
            {
                st.push(zs[i]);
                if(st.size()>m)
                    break;
            }
            else
            {
                j++;
                while(st.size()&&st.top()==xz[j])
                {
                    st.pop();
                    j++;
                }
            }
        }
        if(j==n&&st.empty())
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

 

公開された804元の記事 ウォン称賛42 ビュー40000 +

おすすめ

転載: blog.csdn.net/weixin_44170305/article/details/104363115
おすすめ