Tournament Chart

题目描述

In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events.

JAG is conducted as a knockout tournament. This year, N contestants will compete in JAG. A tournament chart is represented as a string. '[[a-b]-[c-d]]' is an easy example. In this case, there are 4 contestants named a, b, c, and d, and all matches are described as follows:

Match 1 is the match between a and b.
Match 2 is the match between c and d.
Match 3 is the match between [the winner of match 1] and [the winner of match 2].
More precisely, the tournament chart satisfies the following BNF:

<winner> ::= <person> | "[" <winner> "-" <winner> "]"
<person> ::= "a" | "b" | "c" | ... | "z"
You, the chairperson of JAG, are planning to announce the results of this year's JAG competition. However, you made a mistake and lost the results of all the matches. Fortunately, you found the tournament chart that was printed before all of the matches of the tournament. Of course, it does not contains results at all. Therefore, you asked every contestant for the number of wins in the tournament, and got N pieces of information in the form of "The contestant ai won vi times".

Now, your job is to determine whether all of these replies can be true.

输入

The input consists of a single test case in the format below.

S
a1 v1
:
aN vN
S represents the tournament chart. S satisfies the above BNF. The following N lines represent the information of the number of wins. The (i+1)-th line consists of a lowercase letter ai and a non-negative integer vi (vi≤26) separated by a space, and this means that the contestant ai won vi times. Note that N (2≤N≤26) means that the number of contestants and it can be identified by string S. You can assume that each letter ai is distinct. It is guaranteed that S contains each ai exactly once and doesn't contain any other lowercase letters.

输出

Print 'Yes' in one line if replies are all valid for the tournament chart. Otherwise, print 'No' in one line.

样例输入

[[m-y]-[a-o]]
o 0
a 1
y 2
m 0

样例输出

Yes

【题解】

类似于表达式求值,每次都把比赛中较大者减1,最后判断是否全为0即为Yes。

 #include<bits/stdc++.h>
using namespace std; unordered_map <char,int> Hash;
stack <char> Ops;
stack <char> Nums;
bool f ; void Calc( ){
char v = Nums.top() ; Nums.pop();
char u = Nums.top() ; Nums.pop();
/*
if( !( Hash[u] == Hash[v] + 1 || Hash[v] == Hash[u] + 1 ) ){
f = false ; cout << u << " # " << v << endl;
cout << Hash[u] << " # " << Hash[v] << endl;
}
*/
if( Hash[u] > Hash[v] ) Nums.push(u) , Hash[u] -- ;
else Nums.push(v) , Hash[v] -- ;
Ops.pop();
} int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(NULL) , cout.tie(NULL); string s ;
cin >> s ; f = true;
char ch ;
int len = s.length() , v , m = ;
for(int i=;i<len;i++) m += ('a' <= s[i] && s[i] <= 'z' ); for(int i=;i<m;i++){
cin >> ch >> v ;
Hash[ch] = v ;
}
/*
for(int i=0;i<26;i++){
cout << 'a' + i << " " << Hash['a'+i] << endl;
}
*/ for(int i = ; i<len ; i++ ){
if( s[i] == '[' ){
Ops.push(s[i]);
}else if( 'a' <= s[i] && s[i] <= 'z' ){
Nums.push(s[i]);
}else if( s[i] == ']' ){
while( Ops.top() != '[' ) Calc() ;
Ops.pop();
}else if( s[i] == '-'){
Ops.push(s[i]);
}
/*else{
puts(" Invaild Operator \n");
}*/
} /*
for(int i=0;i<26;i++){
cout << char('a' + i) << " " << Hash['a'+i] << endl;
}
*/ //cout << s << endl;
if( f ){
//int t = 0 ;
for(int i=;i<;i++){
if( Hash['a'+i] != )
f = false ;
}
//if( t ) f = false ;
}
if( f ){
printf("Yes\n");
}else{
printf("No\n");
}
return ;
} /* [[[a-b]-c]-[d-e]]
a 3
b 0
c 0
d 1
e 0 */

【数据结构】Tournament Chart的更多相关文章

  1. Tournament Chart【模拟+vector+map+string】

    Tournament Chart 传送门:链接  来源:UPC10889 题目描述 In 21XX, an annual programming contest, Japan Algorithmist ...

  2. Chart.js中文文档-雷达图

    雷达图或蛛网图(Radar chart) 简介 A radar chart is a way of showing multiple data points and the variation bet ...

  3. 数据结构与算法 Big O 备忘录与现实

    不论今天的计算机技术变化,新技术的出现,所有都是来自数据结构与算法基础.我们需要温故而知新.        算法.架构.策略.机器学习之间的关系.在过往和技术人员交流时,很多人对算法和架构之间的关系感 ...

  4. 一款开源且功能强大的C#甘特图控件.NET Winforms Gantt Chart Control

    甘特图在项目管理中非常重要,甘特图的思想比较简单,即以图示的方式通过活动列表和时间刻度形象地表示出任何特定项目的活动顺序与持续时间.它直观地表明任务计划在什么时候进行,及实际进展与计划要求的对比.管理 ...

  5. jQuery 实现Bootstrap Chart 图表

    很多时候我们制作报表的时候需要图表,如果你使用bootstrap开发你的网站,如果你需要使用图表,那么最简单的方法就是就是使用bootstrap 的chart.js来实现图表,下面介绍方法 1.引入c ...

  6. Winfrom Chart实现数据统计

    简介 Chart图标根据实际使用情况,部分图表适用于多组数据的数据分析统计功能,例如柱状图:部分图表适用于单组数据的数据分析统计,例如饼状图. 主要属性 注意使用: Chart图表的如下属性:Lege ...

  7. [DT] 数据结构术语中英文对照

    数据结构术语中英文对照 数据 Data 数据元素 Data element 数据项 Data item 数据结构 Data structure 逻辑结构 Logical structure 数据类型 ...

  8. 推荐一个学习Flex chart的好网站

    推荐一个学习Flex chart的好网站 2013-03-04 14:16:56|  分类: Flex |  标签: |字号大中小 订阅     推荐一个学习Flex chart的好网站 最近在做一个 ...

  9. Chart.js docs

    原文链接:http://www.bootcss.com/p/chart.js/docs/ 引入Chart.js文件 首先我们需要在页面中引入Chart.js文件.此工具库在全局命名空间中定义了Char ...

随机推荐

  1. C#MD5方法

    不同形式,一样结果 /// <summary> /// 获取大写的MD5签名结果 /// </summary> /// <param name="encypSt ...

  2. 简易版最长序列(map映射)

      题目描述 给你一组数(未排序),请你写设计一个程序:求出里面个数最多的数.并输出这个数的长度. 例如:给你的数是:1. 2. 3. 3. 4. 4. 5. 5. 5 .6, 其中只有6组数:1, ...

  3. 走进JavaWeb技术世界7:Tomcat中的设计模式

    . 门面设计模式 门面设计模式在 Tomcat 中有多处使用,在 Request 和 Response 对象封装中.Standard Wrapper 到 ServletConfig 封装中.Appli ...

  4. ML_Homework_Porject_1_KMeans

    第一次机器学习的作业完成了,按照先前做实作的习惯来写一下总结和思考. 作业要求:对COIL20,Yale_32x32,data_batch_1(Cifar)三个数据集,分别运用KMeans对其中的图片 ...

  5. easyUI的datagrid表格的使用

    实现easyUI表格的里面数据的增删改查功能.SQL使用Oracle和mybatis. 话不多说,直接上代码. 首先是前段部分的. var session = GetSession(); var pa ...

  6. Mininet系列实验(一):Mininet使用源码安装

    1 实验目的 掌握Mininet使用源码安装的方法. 2 实验原理 Mininet 是一个轻量级软件定义网络和测试平台:它采用轻量级的虚拟化技术使一个单一的系统看起来像一个完整的网络运行相关的内核系统 ...

  7. window.postMessage 跨窗口,跨iframe javascript 通信

    同源通信 执行它们的页面位于具有相同的协议(http/https),端口(80/443),主机(通常为域名) 时,这两个脚本才能相互通信 大多数情况下,网站就是内部的域名,所以是同源通信,可以相互访问 ...

  8. patch工具的使用

    1. 最简用法 patch -p1 < jello.patch

  9. 123457123456#0#-----com.threeapp.XianshiDaDiShu03-----现实版打地鼠03

    com.threeapp.XianshiDaDiShu03-----现实版打地鼠03

  10. 【Leetcode_easy】804. Unique Morse Code Words

    problem 804. Unique Morse Code Words solution1: class Solution { public: int uniqueMorseRepresentati ...