【codeforces 765A】Neverending competitions

【题目链接】:http://codeforces.com/contest/765/problem/A

【题意】

给你一个人的n个行程
行程都是从家到某个地方或从某个地方到家;
且是无序的,且如果到了非家的地方,它的下一个目的地就是家;
问你这n个行程过后这个人在家里还是不在家里;

【题解】

直接模拟这个行程就好;
对于从家到x的,cnt[x]++
对于从x到家的,cnt[x]–;
看看所有的cnt是不是都等于0;
是的话在家里
否则在外面;

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;

map <string,int> dic;
int n,tot,cnt[N*2];
string s;

int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    rei(n);
    cin >> s;
    dic[s]=++tot;
    rep1(i,1,n)
    {
        cin >> s;
        int po = s.find("-",0);
        string s1 = s.substr(0,po),s2="";
        int len = s.size();
        rep1(j,po+2,len-1)
            s2+=s[j];
        if (!dic[s1]) dic[s1] = ++tot;
        if (!dic[s2]) dic[s2] = ++tot;
        int a = dic[s1],b = dic[s2];
        if (a==1)
            cnt[b]++;
        else
            if (b==1)
                cnt[a]--;
    }
    rep1(i,1,tot)
        if (cnt[i]!=0)
            return puts("contest"),0;
    puts("home");
    return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626618.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值