【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) = ...
随机推荐
- Relaxation step(Dijkstra's 最短路径算法)
翻译成中文就是"松弛",属于工程优化的范畴: Dijkstra 的单源最短路径算法,有一个重要的步奏,当访问到新的结点 u (加入到集合 S),然后遍历 u 的邻接顶点(Adj), ...
- ES5比较Jquery中的each与map 方法?
1.each es5: var arr = [1, 5, 7, 8, 9];var arr1 = []; arr.forEach(function (v, i) { arr1.push(v * 4) ...
- COdeVS——T 1082 线段树练习 3 (分块练习)
http://codevs.cn/problem/1082/ 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 题目描述 Descriptio ...
- 程序中图片透明 函数(使用SetBkColor API函数)
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF c ...
- JS实现穿墙效果(判断鼠标划入划出的方向)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- (转)ORA-00257归档日志写满的解决方法
转自:http://www.cnblogs.com/xwdreamer/p/3804509.html 背景: 在前一篇博客中我们提到了如何启动或关闭oracle的归档(ARCHIVELOG)模式,在我 ...
- Android内存优化(使用SparseArray和ArrayMap取代HashMap)
在Android开发时,我们使用的大部分都是Java的api,比方HashMap这个api,使用率非常高,可是对于Android这样的对内存非常敏感的移动平台,非常多时候使用一些java的api并不能 ...
- 微信浏览器跳转外部浏览器 app下载
这个是摘抄的,具体抄的哪里我忘记了,作为记录 2019年5月14日 现在这个好像也不好用了,微信又提示建议下载qq浏览器什么的,显示一个红色感叹号,让用户产生怀疑,很鄙视tx error_report ...
- 15.1 linux操作系统下nand flash驱动框架2
当我们需要在操作系统上读写普通文件的时候,总是需要一层层往下,最终到达硬件相关操作,当然底层设备大多数都是块设备 NAND FLASH就作为一个最底层的块设备. 而写驱动,就是要构建硬件与操作系统之间 ...
- 【t052】冰岛
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 假设你在一个n*n的冰面上,并且你想到达这个冰面的某处,可是由于冰面太滑了,所以当你向某个方向出发后, ...