absi2011's Blog & Daily Life.

全新的开始       我要省选翻盘       I wanna AK in 高考\化学       自此,生无可恋
POJ 3910 碎碎念

100202 H 碎碎念

absi2011 posted @ Nov 17, 2015 11:46:13 PM in 个人感想 with tags 碎碎念 CF Gym 杂文 , 329 阅读

醉了

写了398行了,总是WA on test 10

不知道该怎么办了

最近一切的一切都不是那么的顺呢

不知道为什么呢

回想起来,我这NOIP是第三次挂了

分组赛,NOI,NOIP

状态还没有恢复么,不会之后来不及了吧?

写到醉了

wjh带我翻译我得写出来再说啊...

不过还是特别鸣谢wjh啦

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<math.h>
#include<string>
#include<time.h>
#include<bitset>
#include<vector>
#include<memory>
#include<utility>
#include<stdio.h>
#include<sstream>
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[1005];
char stop_flag;
void read()
{
    char x;
    for (;;)
    {
        x=getchar();
        if (x!=' ') break;
    }
    int sum=1;
    a[0]=x;
    for (;;)
    {
        a[sum]=getchar();
        if ((a[sum]=='\n')||(a[sum]==',')||(a[sum]==-1))
        {
            stop_flag=a[sum];
            for (;(a[sum-1]==' ')||(a[sum-1]=='\r');)
            {
                sum--;
            }
            a[sum]='\0';
            return;
        }
        sum++;
    }
}
map<string,int> ma;
string room[15];
int x[65],y[65];
string key[65];
struct character
{
    string name;
    int need[205];
    int offer[205];
};
character b[15][205];
struct object
{
    string name;
    int need[205];
    int offer[205];
};
object c[15][205];
int d[15][205];
string items[205];
map<string,int> item;
bool visit[15];
int open[65];
bool can_visit[15];
int own[205];
int n;
int m;
int get_num()
{
    static int sum=0;
    string b=a;
    if (item.find(b)==item.end())
    {
        item[b]=sum;
        items[sum]=b;
        sum++;
    }
    return item[b];
}
void dfss(int now,int goal,int flag=0)
{
    if (!flag) printf("go to %s\n",room[now].c_str());
    if (visit[now]) return;
    visit[now]=true;
    if (now==goal) return;
    int i;
    for (i=0;i<m;i++)
    {
        if (!open[i]) continue;
        if (x[i]==now)
        {
            dfss(y[i],goal);
            if (visit[goal]) return;
            printf("go to %s\n",room[now].c_str());
        }
        if (y[i]==now)
        {
            dfss(x[i],goal);
            if (visit[goal]) return;
            printf("go to %s\n",room[now].c_str());
        }
    }
}
void dfs(int x,int y)
{
    memset(visit,false,sizeof(visit));
    dfss(x,y,1);
}
int main()
{
    freopen("quest.in","r",stdin);
    freopen("quest.out","w",stdout);
    ios::sync_with_stdio(false);
    scanf("%d",&n);
    int i;
    getchar();
    for (i=0;i<n;i++)
    {
        read();
        room[i]=a;
        ma[a]=i;
    }
    scanf("%d",&m);
    for (i=0;i<m;i++)
    {
        scanf("%d%d",&x[i],&y[i]);
        x[i]--;
        y[i]--;
        read();
        key[i]=a;
        get_num();
    }
    for (i=0;i<n;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        getchar();
        int j;
        for (j=0;j<x;j++)
        {
            int t=0;
            read();
            b[i][j].name=a;
            for (;;)
            {
                read();
                b[i][j].need[t++]=get_num();
                if (stop_flag=='\n') break;
            }
            b[i][j].need[t]=-1;
            t=0;
            for (;;)
            {
                read();
                b[i][j].offer[t++]=get_num();
                if (stop_flag=='\n') break;
            }
            b[i][j].offer[t]=-1;
        }
        for (j=0;j<y;j++)
        {
            int t=0;
            read();
            c[i][j].name=a;
            for (;;)
            {
                read();
                c[i][j].need[t++]=get_num();
                if (stop_flag=='\n') break;
            }
            c[i][j].need[t]=-1;
            t=0;
            for (;;)
            {
                read();
                c[i][j].offer[t++]=get_num();
                if (stop_flag=='\n') break;
            }
            c[i][j].offer[t]=-1;
        }
        for (j=0;j<z;j++)
        {
            read();
            d[i][j]=get_num();
        }
        d[i][z]=-1;
    }
    read();
    int start=ma[a];
    read();
    int end=ma[a];
    can_visit[start]=true;
    //can_do_list:
    //1,go to another room(with key)
    //2,pick up something
    //3,talk to a character or use object
    memset(own,0,sizeof(own));
    int now=start;
    for (;;)
    {
        if (can_visit[end])
        {
            dfs(now,end);
            printf("save princess\n");
            return 0;
        }
        int i;
        for (i=0;i<m;i++)
        {
            if ((own[i])&&((can_visit[x[i]])^(can_visit[y[i]])))
            {
                if (can_visit[x[i]])
                {
                    dfs(now,x[i]);
                    now=x[i];
                    printf("open door to %s\n",room[y[i]].c_str());
                    can_visit[y[i]]=true;
                    open[i]=true;
                    break;
                }
                if (can_visit[y[i]])
                {
                    dfs(now,y[i]);
                    now=y[i];
                    printf("open door to %s\n",room[x[i]].c_str());
                    can_visit[x[i]]=true;
                    open[i]=true;
                    break;
                }
            }
        }
        if (i!=m) continue;
        for (i=0;i<n;i++)
        {
            if (can_visit[i])
            {
                if (d[i][0]==-1) continue;
                dfs(now,i);
                now=i;
                int j;
                for (j=0;d[i][j]!=-1;j++)
                {
                    printf("pick %s\n",items[d[i][j]].c_str());
                    own[d[i][j]]=true;
                }
                d[i][0]=-1;
                break;
            }
        }
        if (i!=n) continue;
        for (i=0;i<n;i++)
        {
            if (can_visit[i])
            {
                int j;
                for (j=0;b[i][j].name.length()!=0;j++)
                {
                    if (b[i][j].need[0]==-1) continue;
                    int k;
                    for (k=0;b[i][j].need[k]!=-1;k++)
                    {
                        if (!own[b[i][j].need[k]])
                        {
                            break;
                        }
                    }
                    if (b[i][j].need[k]==-1)
                    {
                        dfs(now,i);
                        now=i;
                        printf("talk to %s\n",b[i][j].name.c_str());
                        int k;
                        printf("give");
                        for (k=0;b[i][j].need[k]!=-1;k++)
                        {
                            if (k==0)
                            {
                                printf(" ");
                            }
                            else if (b[i][j].need[k+1]==-1)
                            {
                                printf(" and ");
                            }
                            else
                            {
                                printf(", ");
                            }
                            printf("%s",items[b[i][j].need[k]].c_str());
                        }
                        printf(" to %s\n",b[i][j].name.c_str());
                        printf("take");
                        for (k=0;b[i][j].offer[k]!=-1;k++)
                        {
                            own[b[i][j].offer[k]]=true;
                            if (k==0)
                            {
                                printf(" ");
                            }
                            else if (b[i][j].offer[k+1]==-1)
                            {
                                printf(" and ");
                            }
                            else
                            {
                                printf(", ");
                            }
                            printf("%s",items[b[i][j].offer[k]].c_str());
                        }
                        printf(" from %s\n",b[i][j].name.c_str());
                        b[i][j].need[0]=-1;
                        break;
                    }
                }
                if (b[i][j].name.length()!=0) break;
            }
        }
        if (i!=n) continue;
        for (i=0;i<n;i++)
        {
            if (can_visit[i])
            {
                int j;
                for (j=0;c[i][j].name.length()!=0;j++)
                {
                    if (c[i][j].need[0]==-1) continue;
                    int k;
                    for (k=0;c[i][j].need[k]!=-1;k++)
                    {
                        if (!own[c[i][j].need[k]])
                        {
                            break;
                        }
                    }
                    if (c[i][j].need[k]==-1)
                    {
                        dfs(now,i);
                        now=i;
                        int k;
                        printf("use");
                        for (k=0;c[i][j].need[k]!=-1;k++)
                        {
                            own[c[i][j].offer[k]]=true;
                            if (k==0)
                            {
                                printf(" ");
                            }
                            else if (c[i][j].need[k+1]==-1)
                            {
                                printf(" and ");
                            }
                            else
                            {
                                printf(", ");
                            }
                            printf("%s",items[c[i][j].need[k]].c_str());
                        }
                        printf(" on %s\n",c[i][j].name.c_str());
                        printf("take");
                        for (k=0;c[i][j].offer[k]!=-1;k++)
                        {
                            if (k==0)
                            {
                                printf(" ");
                            }
                            else if (c[i][j].offer[k+1]==-1)
                            {
                                printf(" and ");
                            }
                            else
                            {
                                printf(", ");
                            }
                            printf("%s",items[c[i][j].offer[k]].c_str());
                        }
                        printf(" from %s\n",c[i][j].name.c_str());
                        c[i][j].need[0]=-1;
                        break;
                    }
                }
                if (c[i][j].name.length()!=0) break;
            }
        }
        if (i!=n) continue;
        break;
    }
    freopen("quest.out","w",stdout);
    printf("dead princess\n");
    return 0;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter