HDOJ6342Expression in Memories(模拟)

Posted myx12345

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDOJ6342Expression in Memories(模拟)相关的知识,希望对你有一定的参考价值。

题意:

给定一个由0123456789+* ?组成的表达式,其中?可以被改为任意其它字符,问修改问号后是否有方案使得表达式合法

len<=5e2,sumlen<=1e5

思路:

技术分享图片

 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <stdlib.h>
 4 #include <string.h>
 5 #include <string>
 6 #include <algorithm>
 7 #include <iostream>
 8 #include <ctype.h>
 9 #include <limits.h>
10 #include <set>
11 #include <map>
12 #include <vector>
13 #include <stack>
14 #include <queue>
15 #include <list>
16 #define left (now<<1)
17 #define right ((now<<1)+1)
18 #define mid ((l+r)>>1)
19 #define fst first
20 #define snd second
21 using namespace std;
22 typedef long long lint;
23 
24 const int MAXN = 5e2 + 10;
25 
26 char str[MAXN];
27 int n;
28 bool ok[MAXN];
29 
30 void init(){
31     for(int i = 0; i < MAXN; ++i){
32         str[i] = ;
33     }
34 }
35 
36 int main(){
37     int t; scanf("%d",&t);
38     while(t--){
39         init(); scanf("%s",str); int len = strlen(str); bool zero = false;
40         memset(ok,false,sizeof(ok));
41         for(int i = 0; i < len; ++i){
42             if(str[i] == ?){
43                 str[i] = 1; ok[i] = true;
44             }
45         }
46 
47         bool can = true; zero = false;
48         if(str[0] == + || str[0] == * || str[len - 1] == + ||str[len - 1] == *){
49             can = false;
50         }
51         for(int i = 0; i < len - 1; ++i){
52             if((str[i] == + || str[i] == *) && (str[i + 1] == * || str[i + 1] == +)){
53                 can = false; break;
54             }
55         }
56         for(int i = 0; i < len; ++i){
57             if(isdigit(str[i]) && zero){
58                 if(ok[i] == false){
59                     can = false; break;
60                 }else{
61                     str[i] = +;
62                 }
63             }
64             if(str[i] == 0 && (i == 0 || !isdigit(str[i - 1]))){
65                 zero = true;
66             }else{
67                 zero = false;
68             }
69         }
70         if(str[0] == + || str[0] == * || str[len - 1] == + ||str[len - 1] == *){
71             can = false;
72         }
73         for(int i = 0; i < len - 1; ++i){
74             if((str[i] == + || str[i] == *) && (str[i + 1] == * || str[i + 1] == +)){
75                 can = false; break;
76             }
77         }
78         if(can){
79             printf("%s
",str);
80         }else{
81             printf("IMPOSSIBLE
");
82         }
83     }
84     return 0;
85 }

 

以上是关于HDOJ6342Expression in Memories(模拟)的主要内容,如果未能解决你的问题,请参考以下文章

2018 Multi-University Training Contest 4 Problem K. Expression in Memories 模拟

loj #6342. 跳一跳 期望dp

无法访问 H2 in-mem 数据库 Play!框架

hdoj1171 Big Event in HDU(01背包 || 多重背包)

HDOJ5657 CA Loves Math

hdoj 1025 Constructing Roads In JGShining&#39;s Kingdom 最长递增子序列