P11601 题解

· · 题解

逆天模拟题。赛时把机房人集体卡红温。

正题

人的状态

容易发现对一个人,有用的信息只有几个:

我们用一个结构体维护一个人,这样就可以定义一系列关于人的操作。

请注意,要先检查是否使用过技能,这个人死了没有(女巫解自己和猎人除外),以及这个角色和角色 id 是否合法。

狼人杀人

我们可以定义一个函数,检查这个人可不可以被杀,如果可以就将其杀掉(除了用解药,都需要这个函数)。

容易发现,不合法的情况只有可能是这个人已经杀掉了。

猎人带走

判断是否本回合死亡后,视为狼人杀人处理即可。

女巫使用毒药

在检查过合法性(本回合是否使用过技能),当成狼人杀人处理即可。

女巫使用解药

判断以下几个东西:

若都合法,将这个人的死亡状态改为未死亡即可。注意猎人若当回合被救活,不一定要开枪。

回合结束

做以下几件事:

总代码

#include<bits/stdc++.h>

using namespace std;

struct man {
    int type;
    bool used1,used2;//女巫的毒药,解药
    bool died,kill;
    bool used;
    inline bool kill_it() {//是否可以被杀,如果可以就杀
        if(died||kill)return 1;
        kill=1;
        return 0;
    }
    inline bool safe() {
        if(died||!kill/*||(type==3&&!used)*/)return 1;
        kill=0;
        if(type==3)used=0;
        return 0;
    }
    inline bool update(bool &is_death) {//is_death 返回这个人是否当回合死亡
        is_death=kill;
        if(kill&&!used&&type==3)return 1;
        died|=kill;
        if(type==1||type==4)used=0;
        kill=0;
        return 0;
    }
    inline bool used_help() {
        if(used2||type!=4||used) {
            return 1;
        }
        used=1;
        used2=1;
        return 0;
    }
    inline bool used_death() {
        if(!used1&&type==4&&!kill&&!used) {
            used=1;
            used1=1;
            return 0;
        }
        return 1;
    }
} men[24],tmp[24];//tmp 用于存档

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    //解同步流,还让 cout 拥有自己的缓存区,便于查看答案
    int t,n;
    cin>>t>>n;
    for(int i=1; i<=n; i++)cin>>men[i].type;
    for(int i=1; i<=t; i++) {
        for(int x=1; x<=n; x++)tmp[x]=men[x];
        bool type=0;
        int x;
        cin>>x;
        for(int t=1; t<=x; t++) {
//          for(int x=1; x<=n; x++)cerr<<men[x].used<<' ';
//          cerr<<'\n';
            int t1,t2,t3;
            cin>>t1>>t2>>t3;
            if(t2>n||t2<1||t3>n||t3<1)type=1;
            if(type)continue;
            switch(t1) {
                case 0:
                    if(t2==t3||men[t2].died||men[t2].kill||men[t2].type!=1||men[t2].used||men[t3].kill_it()) {
                        type=1;
                        break;
                    }
                    men[t2].used=1;
                    break;
                case 1:
                    if(t2==t3||men[t2].used_death()||men[t3].kill_it()) {
                        type=1;
                        break;
                    }
                    break;
                case 2:
                    if(men[t2].died||(men[t2].kill&&t2!=t3)||men[t2].used_help()||men[t3].safe()) {
                        type=1;
                        break;
                    }
                    break;
                case 3:
                    if(men[t2].died||!men[t2].kill||men[t2].used||t3==t2||men[t2].type!=3||men[t3].kill_it()) {
                        type=1;
                        break;
                    }
                    men[t2].used=1;
                    break;
                default:
                    puts("Lucy AK IOI");
                    return -1;
            }
        }
        bool the_tmp;
        vector<int> e;
        for(int t=1; t<=n; t++) {
            type|=men[t].update(the_tmp);
            if(the_tmp)e.push_back(t);
        }
        if(type)cout<<"Wrong\n";
        if(type)for(int x=1; x<=n; x++)men[x]=tmp[x];
        if(type)continue;
        if(!e.size())cout<<"Safe\n";
        else {
            cout<<e.size()<<' ';
            for(int i=0; i<e.size(); i++)cout<<e[i]<<' ';
            cout<<'\n';
        }
    }
    return 0;
}