HDU 6342 Expression in Memories(模拟)多校题解
题意:给你一个规则,问你写的对不对。
思路:规则大概概括为:不能出现前导零,符号两边必须是合法数字。我们先把所有问号改好,再去判断现在是否合法,这样判断比一边改一边判断容易想。
下面的讲解问号只改为+或1...
对于(null)0?,+0?,*0?一律只能改为+,否则必是前导零,其他情况问号改为1,判断情况的时候注意一下i的范围,比如i==0时,s[i - 1]越界。
判断对错时对++,(null)+,+(null)符号两边没数字的判错,如果01前是null或者+*判错。
给几个样例:
0??0 0?0?0 01?+0 0?*0
代码:
#include<cstdio>
#include<set>
#include<stack>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 560+5;
const int INF = 0x3f3f3f3f;
char s[maxn];
int main(){
int T;
scanf("%d",&T);
while(T--){
int flag = 0;
scanf("%s",s);
int len = strlen(s);
for(int i = 0;i < len;i++){
if(s[i] == '?'){
if(i == 1 && s[i - 1] == '0') //(null)0?
s[i] = '+';
else if(i >= 2 && s[i - 1] == '0' && (s[i - 2] == '+' || s[i - 2] == '*')) //+0?,*0?
s[i] = '+';
else
s[i] = '1';
}
}
for(int i = 0;i < len;i++){
if(s[i] == '0' && (s[i + 1] >= '0' && s[i + 1] <= '9' && i < len - 1) && (i == 0 || (s[i - 1] < '0' || s[i - 1] > '9'))){
//01前是null或者+*
flag = 1;
break;
}
if((s[i] == '*' || s[i] == '+') && (s[i + 1] == '*' || s[i + 1] == '+') && i < len - 1){
//++
flag = 1;
break;
}
if(s[i] == '+' || s[i] == '*'){
if(i == 0 || i == len - 1){ //(null)+,+(null)
flag = 1;
break;
}
if(s[i - 1] < '0' || s[i - 1] > '9'){ //++
flag = 1;
break;
}
if(s[i + 1] < '0' || s[i + 1] > '9'){ //++
flag = 1;
break;
}
}
}
if(flag) printf("IMPOSSIBLE\n");
else printf("%s\n",s);
}
return 0;
}
HDU 6342 Expression in Memories(模拟)多校题解的更多相关文章
- HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)
6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...
- 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 ...
- 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 ...
- 杭电多校第四场 Problem K. Expression in Memories 思维模拟
Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 【hdu 6342】Expression in Memories
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把所有的问号都改成'1' 然后会发现只有+0?这种情况 需要把?改成+. 看看这样的0后面的1是不是由问号改过来的就好了.是的话 再 ...
- HDU 5402 Travelling Salesman Problem(多校9 模拟)
题目链接:pid=5402">http://acm.hdu.edu.cn/showproblem.php?pid=5402 题意:给出一个n×m的矩阵,位置(i.j)有一个非负权值. ...
- 多校第六场 HDU 4927 JAVA大数类+模拟
HDU 4927 −ai,直到序列长度为1.输出最后的数. 思路:这题实在是太晕了,比赛的时候搞了四个小时,从T到WA,唉--对算组合还是不太了解啊.如今对组合算比較什么了-- import java ...
- 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)
题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...
随机推荐
- LeetCode——Add and Search Word - Data structure design
Description: Design a data structure that supports the following two operations: void addWord(word) ...
- LeetCode——Valid Anagram
Description: Given two strings s and t, write a function to determine if t is an anagram of s. For e ...
- CSS 3D的应用记录
为父元素添加以下样式后,子元素即可使用3D属性,例如translateZ /*设置子元素也应用3D效果*/-webkit-transform-style: preserve-3d;-moz-trans ...
- hibernate在Oracle中插入数据,默认字段被设置为null的问题解决
参考内容: http://blog.sina.cn/dpool/blog/s/blog_90629d5301014a5w.html 在数据库中一个字段的默认值为1,但是在插入数据后,本来该字段为空,值 ...
- 树链剖分-点的分治(dis[i]+dis[j]==k的点对数量)
poj2114 Boatherds Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1195 Accepted: 387 ...
- Common Subsequence 最大公共子序列问题
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- 160226、js常用的验证
/*** 特殊符号 */ function specialCharacter(carNo){ var st=/^[^/@#$%^&*()—''_()!¥~·..,-<><&g ...
- VS2012/2013引用对话框的糟糕设计
先看两张图: 1. 首次打开引用对话框(Reference Manager),Name显示不全: (图1) 2. 然后双击或拖动splitter,让Name显示全: (图2) 3. 下次再打开引用对话 ...
- acceptorThreadCount
Apache Tomcat 7 Configuration Reference (7.0.92) - The HTTP Connector https://tomcat.apache.org/tomc ...
- mybatis-spring-boot-autoconfigure
mybatis-spring-boot-autoconfigure – MyBatis Sring-BootStarter | Reference Documentation http://www.m ...