【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;
}
【codeforces 765A】Neverending competitions的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 602E】Kleofáš and the n-thlon
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 761B】Dasha and friends
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- 1.14 Python基础知识 - 文件操作
应用程序往往需要从磁盘文件中读取数据,或者把数据存储到磁盘中文件里,以持久的保存数据.文件可以看作是数据的集合,文件的输入与输出通过流来实现.流有5种基本的操作:打开.读取.写入.改变当前位置和关闭. ...
- 谈谈Command对象与数据检索
摘要 到目前为止,我相信大家对于ADO.NET如何与外部数据源建立连接以及如何提高连接性能等相关知识已经牢固于心了.连接对象作为ADO.NET的主力先锋,为用户与数据库交互搭建了扎实的桥梁.它的一生是 ...
- mysql数据库忘记密码时如何修改(转)
当我们忘记mysql数据库密码时我们就无法正常进入数据库,也就无法修改密码,那么这时该怎么修改密码呢,这里教大家一个简单常用修改密码的方式. (如果图简单快速修改密码的话,直接跳过查询步骤,依照图上执 ...
- easy ui 验证
$('#IdentityCertificate').validatebox({required:true}); $('#memberName').validatebox({required:true} ...
- 【习题 6-11 UVA - 10410】Tree Reconstruction
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以先确定当前这棵子树的dfs序的范围. 然后第一个元素肯定是这棵子树的根节点. 那么只要在这棵子树的范围里面枚举节点. 看看有没有 ...
- 【习题 6-1 UVA-673】Parentheses Balance
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 括号匹配. 栈模拟就好. 多种括号也是一样可以做的. [代码] #include <bits/stdc++.h> usi ...
- “-bash: !”: event not found"、echo > sudo permission denied
1. "-bash: !": event not found" 比如当我们在 linux 命令行输入echo "Reboot your instance!&qu ...
- [TypeScript] Define a function type
type DigitValidator = (char) => boolean; -]{}/.test(char); export const digitValidators: {[key: s ...
- android闹钟实现原理
闹钟的原理可用下面我自己画的一幅图来概括:(不对的地方,尽管吐槽) 我们来看看新建闹钟到闹钟响铃的步骤: 1.新建一个闹钟: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- linux 查看 *.a *.so 符号表(zt)
objdump -tT libName.so | grep symbel symbolName nm -D libName.so | grep symbel symbolName 很多非常熟悉wind ...