- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB

- 描述
- Polygon is a game for one player that starts on a polygon with N vertices, like the one in Figure 1, where N=4. Each vertex is labelled with an integer and each edge is labelled with either the symbol + (addition) or the symbol * (product). The edges are numbered from 1 to N.

On the first move, one of the edges is removed. Subsequent moves involve the following steps:

pick an edge E and the two vertices V1 and V2 that are linked by E; and

replace them by a new vertex, labelled with the result of performing the operation indicated in E on the labels of V1 and V2.

The game ends when there are no more edges, and its score is the label of the single vertex remaining.

Consider the polygon of Figure 1. The player started by removing edge 3. After that, the player picked edge 1, then edge 4, and, finally, edge 2. The score is 0.

Write a program that, given a polygon, computes the highest possible score and lists all the edges that, if removed on the first move, can lead to a game with that score. - 输入
- Your program is to read from standard input. The input describes a polygon with N vertices. It contains two lines. On the first line is the number N. The second line contains the labels of edges 1, ..., N, interleaved with the vertices' labels (first that of the vertex between edges 1 and 2, then that of the vertex between edges 2 and 3, and so on, until that of the vertex between edges N and 1), all separated by one space. An edge label is either the letter t (representing +) or the letter x (representing *).

3 <= N <= 50

For any sequence of moves, vertex labels are in the range [-32768,32767]. - 输出
- Your program is to write to standard output. On the first line your program must write the highest score one can get for the input polygon. On the second line it must write the list of all edges that, if removed on the first move, can lead to a game with that score. Edges must be written in increasing order, separated by one space.
- 样例输入
4 t -7 t 4 x 2 x 5

- 样例输出
33 1 2

- 来源
- IOI 1998

1. STL编程接口：

1）(多道题均可能用到)STL队列中queue.push()是在“队尾”插入，“队头”元素访问用queue.front()，并需要额外调用queue.pop()来删除“队头”元素

2）（dynamic median）STL中声明一个int元素的优先队列（缺省为最大堆）的方法：priority_queue<int> pq; 如果需要最小堆：priority_queue<int, vector<int>, greater<int> > pq; greater<int> 所在的头文件为<functional>

2. 输入输出格式：

(heavy transportation) 题意要求每个case结束之后单独输出一个空行，而样例并未体现这一点

3. 其他需要注意的地方：

（dynamic median/股票买卖）输入数据量较大，应使用scanf而不是cin，否则有可能超时

（polygon）注意 -1 % n (n为正整数) 仍为 -1

其他问题可以到提问板上提问或者直接找助教

- 全局题号
- 181
- 提交次数
- 185
- 尝试人数
- 56
- 通过人数
- 52