题意:

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

len<=5e2,sumlen<=1e5

思路:

 #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <ctype.h>
#include <limits.h>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
#define fst first
#define snd second
using namespace std;
typedef long long lint; const int MAXN = 5e2 + ; char str[MAXN];
int n;
bool ok[MAXN]; void init(){
for(int i = ; i < MAXN; ++i){
str[i] = '\0';
}
} int main(){
int t; scanf("%d",&t);
while(t--){
init(); scanf("%s",str); int len = strlen(str); bool zero = false;
memset(ok,false,sizeof(ok));
for(int i = ; i < len; ++i){
if(str[i] == '?'){
str[i] = ''; ok[i] = true;
}
} bool can = true; zero = false;
if(str[] == '+' || str[] == '*' || str[len - ] == '+' ||str[len - ] == '*'){
can = false;
}
for(int i = ; i < len - ; ++i){
if((str[i] == '+' || str[i] == '*') && (str[i + ] == '*' || str[i + ] == '+')){
can = false; break;
}
}
for(int i = ; i < len; ++i){
if(isdigit(str[i]) && zero){
if(ok[i] == false){
can = false; break;
}else{
str[i] = '+';
}
}
if(str[i] == '' && (i == || !isdigit(str[i - ]))){
zero = true;
}else{
zero = false;
}
}
if(str[] == '+' || str[] == '*' || str[len - ] == '+' ||str[len - ] == '*'){
can = false;
}
for(int i = ; i < len - ; ++i){
if((str[i] == '+' || str[i] == '*') && (str[i + ] == '*' || str[i + ] == '+')){
can = false; break;
}
}
if(can){
printf("%s\n",str);
}else{
printf("IMPOSSIBLE\n");
}
}
return ;
}

【HDOJ6342】Expression in Memories(模拟)的更多相关文章

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

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6342 Problem K. Expression in Memories Time Limit: 200 ...

  2. HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories

    Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262 ...

  3. 杭电多校第四场 Problem K. Expression in Memories 思维模拟

    Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262 ...

  4. HDU 6342 Expression in Memories(模拟)多校题解

    题意:给你一个规则,问你写的对不对. 思路:规则大概概括为:不能出现前导零,符号两边必须是合法数字.我们先把所有问号改好,再去判断现在是否合法,这样判断比一边改一边判断容易想. 下面的讲解问号只改为+ ...

  5. 【hdu 6342】Expression in Memories

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把所有的问号都改成'1' 然后会发现只有+0?这种情况 需要把?改成+. 看看这样的0后面的1是不是由问号改过来的就好了.是的话 再 ...

  6. HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)

    6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...

  7. 2018 Multi-University Training Contest 4

    累惹. B. Harvest of Apples 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题意:求∑(i=0,m) C(n,m). 分 ...

  8. 2018 Multi-University Training Contest 4 Solution

    A - Problem A. Integers Exhibition 留坑. B - Problem B. Harvest of Apples 题意:计算$\sum_{i = 0}^{i = m}C( ...

  9. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

随机推荐

  1. coursera网站中的VTT字幕的使用

    coursera网站中的VTT字幕的使用 1.https://www.coursera.org/learn/os-virtsecurity/lecture/xuWgP/1-3-cao-zuo-xi-t ...

  2. VCS filelist 文件格式

    VCS在运行仿真一般都会加仿真参数 –f filelist,filelist 是包含其他的仿真参数和整个工程的文件列表.具体格式如下: //file list format, just for exa ...

  3. windows 查看某端口被占用情况

    百度经验 http://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html 基本命令 netstat -ano

  4. COGS 827. [Tyvj Feb11] 网站计划

    输入文件:web.in   输出文件:web.out   简单对比时间限制:1 s   内存限制:128 MB 描述 Description     Tyvj的Admin--zhq同学将在寒假开始实行 ...

  5. About the iOS File System

    两个维度: 1)是否给用户使用: 2)是否持久存储. During installation of a new app, the installer creates a number of conta ...

  6. VINS-Fusion代码阅读(四)

    pts_i和pts_j:具体指什么含义?(分别为第l个路标点在第i, j个相机归一化相机坐标系中的观察到的坐标,P¯¯¯cil \bar{P}^{c_i}_l Pˉ lc i​ ​ 和 P¯¯¯cjl ...

  7. vscode 打开新文件不替换旧文件

    设置 "workbench.editor.enablePreview": false

  8. zk伪集群部署

    jdk 配置 # tar xf jdk-8u161-linux-x64.tar.gz -C /usr/local/ # vim /etc/profile.d/jdk.sh export JAVA_HO ...

  9. attr和prop的区别

    由于prop(property的缩写)和attr(attribute的缩写)翻译成汉语,均有“特性.属性”等意思的原因,导致大家容易混淆分不清. (1)在处理自定义时属性时,用attr(),若用pro ...

  10. python小随笔

    关于pip安装 .\pip.exe install --ignore-installed --upgrade tensorflow-gpu python可视化库 Seaborn:是一个基于matplo ...