Problem K. Expression in Memories

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge

Problem Description
Kazari remembered that she had an expression s0 before.
Definition of expression is given below in Backus–Naur form.
<expression> ::= <number> | <expression> <operator> <number>
<operator> ::= "+" | "*"
<number> ::= "0" | <non-zero-digit> <digits>
<digits> ::= "" | <digits> <digit>
<digit> ::= "0" | <non-zero-digit>
<non-zero-digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
For example, `1*1+1`, `0+8+17` are valid expressions, while +1+1, +1*+1, 01+001 are not.
Though s0 has been lost in the past few years, it is still in her memories. 
She remembers several corresponding characters while others are represented as question marks.
Could you help Kazari to find a possible valid expression s0 according to her memories, represented as s, by replacing each question mark in s with a character in 0123456789+* ?
 
Input
The first line of the input contains an integer T denoting the number of test cases.
Each test case consists of one line with a string s (1≤|s|≤500,∑|s|≤105).
It is guaranteed that each character of s will be in 0123456789+*? .
 
Output
For each test case, print a string s0 representing a possible valid expression.
If there are multiple answers, print any of them.
If it is impossible to find such an expression, print IMPOSSIBLE.
 
Sample Input
5
?????
0+0+0
?+*??
?0+?0
?0+0?
 
Sample Output
11111
0+0+0
IMPOSSIBLE
10+10
IMPOSSIBLE

先考虑运算符不行的情况再考虑前导0的情况

AC代码
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
string s;
vector<string> e;
bool iso( char c ) {
if( c == '+' || c == '*' ) {
return true;
}
return false;
}
int main() {
ll T;
cin >> T;
while( T -- ) {
cin >> s;
bool flag = true;
for( ll i = 0; i < s.length(); i ++ ) {
if( ( i == 0 || i == s.length()-1 ) && iso(s[i]) ) {
flag = false;
break;
}
if( i < s.length()-1 ) {
if( iso(s[i]) && iso(s[i+1]) ) {
flag = false;
break;
}
}
if( s[i] == '?' ) {
if( s[i-1] == '0' && ( i-2 < 0 || iso(s[i-2]) ) && !iso(s[i+1]) ) {
s[i] = '+';
} else {
s[i] = '1';
}
}
}
//debug(s);
e.clear();
string t = "";
for( ll i = 0; i < s.length(); i ++ ) {
if( iso(s[i]) || i == s.length()-1 ) {
if( i == s.length()-1 ) {
t += s[i];
}
e.push_back(t);
t = "";
} else {
t += s[i];
}
}
for( ll i = 0; i < e.size(); i ++ ) {
//cout << e[i] << endl;
if( e[i][0] == '0' && e[i].length() > 1 ) {
flag = false;
break;
}
}
if( flag ) {
cout << s << endl;
} else {
cout << "IMPOSSIBLE" << endl;
}
}
return 0 ;
}

  

杭电多校第四场 Problem K. Expression in Memories 思维模拟的更多相关文章

  1. 杭电多校第四场 E Matrix from Arrays

    Problem E. Matrix from Arrays Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 ...

  2. [2019杭电多校第四场][hdu6623]Minimal Power of Prime

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6623 题目大意为求一个数的唯一分解的最小幂次.即120=23*31*51则答案为1. 因为数字太大不能 ...

  3. [2019杭电多校第四场][hdu6621]K-th Closest Distance(主席树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6621 题意为求区间[l,r]内第k小|a[i]-p|的值. 可以二分答案,如果二分的值为x,则判断区间 ...

  4. [2019杭电多校第四场][hdu6616]Divide the Stones

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6616 题意是说n个数分别为1-n,将n个数分成k堆,能否满足每堆个数相等,数值之和相等.保证n%k=0 ...

  5. [2019杭电多校第四场][hdu6614]AND Minimum Spanning Tree(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6614 题目大意是有一张n个点的完全图,n个点点权为1-n,边权为两点点权按位与(&).求最小生 ...

  6. 2019杭电多校第四场hdu6623 Minimal Power of Prime

    Minimal Power of Prime 题目传送门 解题思路 先打\(N^\frac{1}{5}\)内的素数表,对于每一个n,先分解\(N^\frac{1}{5}\)范围内的素数,分解完后n变为 ...

  7. 杭电多校第四场-H- K-th Closest Distance

    题目描述 You have an array: a1, a2, , an and you must answer for some queries.For each query, you are g ...

  8. 2019杭电多校第四场hdu6621 K-th Closest Distance(二分答案+主席树)

    K-th Closest Distance 题目传送门 解题思路 二分答案+主席树 先建主席树,然后二分答案mid,在l和r的区间内查询[p-mid, p+mid]的范围内的数的个数,如果大于k则说明 ...

  9. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

随机推荐

  1. kubernetes对接第三方认证

    kubernetes对接第三方认证 kubernetes离线安装包地址 概述 本文介绍如何使用github账户去关联自己kubernetes账户.达到如下效果: 使用github用户email作为ku ...

  2. Vmware Exsi使用简要说明

    界面介绍 Exsi的管理工具可以用vSphere Client来管理虚拟机.管理虚拟的网络交换机.管理物理机的内存.物理机的硬盘.物理机的CPU等资源.界面的大致介绍如下图. 资源分配 创建内存.CP ...

  3. 在线图片base64编码

    图片Base64编码https://oktools.net/image2base64 在线工具https://oktools.net JSON格式化https://oktools.net/json U ...

  4. python 之 前端开发(基本选择器、组合选择器、 交集与并集选择器、序列选择器、属性选择器、伪类选择器、伪元素选择器)

    11.3 css 11.31 基本选择器 11.311 id选择器 根据指定的id名称,在当前界面中找到对应的唯一一个的标签,然后设置属性 <!DOCTYPE html> <html ...

  5. spring架构解析--入门一

    Spring 框架中的核心组件只有三个:Core.Context 和 Beans.它们构建起了整个 Spring 的骨骼架构.简单理解: spring core是工具,context是环境,而bean ...

  6. .net软件日常开发规范-基本标准

    一. 基本标准 代码和SQL脚本均不要出现无意义的空格和空行. 所有SQL脚本确保可以重复运行不出错,添加数据的脚本重复运行不会重复添加数据. 能用一行代码或脚本解决的不要写出两行,能用一个方法解决的 ...

  7. 5G标准公布,你很快又要换手机了

    通常,在4G网络环境下,下载一部1G的电影只需要30秒时间,对于经历过2G和3G网络的我们来说已经非常快了. 但是听说,5G环境中下载一部同样的电影,根本不是用秒来计算的,甚至有外媒说,5G的速率会是 ...

  8. 零拷贝Zero copy-linux and java

    背景-几种拷贝方式 方式1:Copying in Two Sample System Calls read(file, tmp_buf, len); write(socket, tmp_buf, le ...

  9. 《Java 8 in Action》Chapter 5:使用流

    流让你从外部迭代转向内部迭代,for循环显示迭代不用再写了,流内部管理对集合数据的迭代.这种处理数据的方式很有用,因为你让Stream API管理如何处理数据.这样Stream API就可以在背后进行 ...

  10. Servlet 获取 数组id进行批量删除

    把获取的复选框选中的 id(一般来说都是根据id 进行批量删除的) 从jsp页面 传值到Servlet中 jsp点击事件中: var array=[];  //先声明一个数组变量 var ids=$( ...