【NYOJ】[1124]盗梦空间

文章字数:201

问题描述

问题分析

出的挺有意思的一个题目

中间卡住了一点点
不过整体来看还不算难

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		int M,fl=0,sum=0;
		char s[20];
		scanf("%d",&M);
		while(M--) {
			scanf("%s",s);
			if(s[0]=='I')
				fl++;
			else if(s[0]=='O')
				fl--;
			else {
				int t;
				scanf("%d",&t);
				t*=60;
				int cnt=fl;
				while(cnt--) {
					t/=20;
				}
				sum+=t;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

标程的简化是直接用可运算的数字来代表梦境层数
从而简化运算

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<string>
using namespace std;
int main() {
	int m;
	string s;
	cin>>m;
	while(m--) {
		int p=1,n,t=0,tt;
		cin>>n;
		while(n--) {
			cin>>s;
			if(s=="STAY") {
				cin>>tt;
				t+=tt*60/p;
			} else if(s=="IN") p*=20;
			else p/=20;
		}
		cout<<t<<endl;
	}
}

题目地址:盗梦空间

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...