Nội dung Bài tập
- Mã:
- ACM2016_North_K
- Tên:
- Missing mutex (ACM 2016 Miền Bắc)
- Dạng thi:
- acm
- Thang điểm:
- 1 điểm
- Giới hạn thời gian:
- 2 giây
- Giới hạn bộ nhớ:
- 64 MB
- Được tạo bởi:
- admin
Hieu is an famous competitive programmer in Vietnam. Tired of winning matches, he started to study a new programming language called X+*. This language is very simple with one variable X that hold an integer and several operations:

In the beginning of the program, X is default to be 0. After writing a program consists of several operations, he tested it and it had operated as expected. However, after deploying this program to the server and he realized that he did not handle the concurrency problem. When two programs are executed at the same time, operations of the same program still keep order but the operations between two programs might merge together.
For example, consider this program.
INCDOUBLE
When this program is called twice in parallel, we can have very different outcomes:


Given the program, your task is to find how many different results we could get when 2 programs are running at the same time.
Input
The input starts with the number of test - T (T ≤ 20) Then T tests follow.• The first line is N the number of operations in the code. (N ≤ 10)• The next N lines, each represents an operation.
Output
SampleFor each test in the input, print the number of different results we can get.
input12INCDOUBLEoutput2
John có một chiếc máy tính có hai bộ chip cùng xử lý đồng thời một hoặc
một vài tác vụ. John định nghĩa một số toán tử sẽ dùng cho biến X như
sau (X ban đầu bằng 0)
INC: Cộng X lên 1 đơn vị (X=X+1)
DOUBLE: Gấp đôi X (X=X*2)
TRIPLE: Gấp ba X (X=X*3)
SQR: Bình phương X (X=X*X)
SET y: Gán X bằng y (0<=y<=255) (X=y)
Vấn
đề ở đây là hai bộ chip có thể xen kẽ nhau xử lý biến X. Nhiệm vụ của
bạn là tìm ra xem có bao nhiêu kết quả X có thể có sau khi thực hiện hết
các toán tử mà John đưa vào.
Dữ liệu vào: Số nguyên T là số lượng test (T<=20)
- Số nguyên n là số lượng toán tử
- n dòng tiếp theo là các toán tử
Dữ liệu ra: mỗi dòng là số nguyên duy nhất là số kết quả có thể có của X ứng với test tương ứng
Ví dụ:
Giải thích:input12INCDOUBLEoutput2
Với các thứ tự có thể xảy ra bên dưới thì số kết quả có thể có của X là 2 (X=6 và X=8)
Theme :
Mời bạn soạn code
Ai có thể xem bài này :
Thông tin
Phần thảo luận