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

本文针对HDU6342题目的求解进行了详细的代码展示和解析,通过模拟的方式解决将未知字符替换为有效数值的问题,确保多项式表达式的合法性。

 

6342.Problem K. Expression in Memories

 

这个题就是把?变成其他的使得多项式成立并且没有前导零

官方题解:

 

没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的垃圾好多了。。。

HDU 6342(模拟)

 

贴一下一个队友的代码:

  1 //1011-6342-模拟
  2 #include<iostream>
  3 #include<cstdio>
  4 #include<cstring>
  5 #include<algorithm>
  6 #include<bitset>
  7 #include<cassert>
  8 #include<cctype>
  9 #include<cmath>
 10 #include<cstdlib>
 11 #include<ctime>
 12 #include<deque>
 13 #include<iomanip>
 14 #include<list>
 15 #include<map>
 16 #include<queue>
 17 #include<set>
 18 #include<stack>
 19 #include<vector>
 20 using namespace std;
 21 typedef long long ll;
 22 
 23 const double PI=acos(-1.0);
 24 const double eps=1e-6;
 25 const ll mod=1e9+7;
 26 const int inf=0x3f3f3f3f;
 27 const int maxn=1e5+10;
 28 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 29 
 30 int a[maxn];
 31 char c[maxn];
 32 
 33 int main()
 34 {
 35     int t;
 36     scanf("%d",&t);
 37     while(t--){
 38         int flag=0;
 39         scanf("%s",c+1);
 40         int n=strlen(c+1);
 41         for(int i=1;i<=n;i++){
 42             if(c[i]>='0'&&c[i]<='9')
 43                 a[i]=1;
 44             else if(c[i]=='?')
 45                 a[i]=1;
 46             else
 47                 a[i]=0;
 48             if(i!=1){
 49                 if(a[i]==0&&a[i-1]==0){//++
 50                     flag=1;
 51                     break;
 52                 }
 53             }
 54         }
 55         if(c[1]=='0'&&a[2]==1&&n>1){//01
 56             if(c[2]=='?'){
 57                 if(n>2&&a[3]==1)
 58                     c[2]='+',a[2]=0;
 59                 else
 60                     flag=1;
 61             }
 62             else
 63                 flag=1;
 64         }
 65         if(a[n]==0||a[1]==0)//1+ +1
 66             flag=1;
 67         for(int i=1;i<=n;i++){
 68             if(a[i-1]==0&&c[i]=='0'&&a[i+1]==1&&i>1&&i<n){
 69                 if(c[i+1]!='?'){//01
 70                     flag=1;
 71                     break;
 72                 }
 73                 else if(c[i+1]=='?'&&i+1>=n){//0?
 74                     flag=1;
 75                     break;
 76                 }
 77             }
 78             if(a[i-1]==0&&c[i]=='0'&&c[i+1]=='?'&&i>1&&i+1<n){
 79                 if(a[i+2]==1){//0?0
 80                     c[i+1]='+';
 81                     a[i+1]=0;
 82                 }
 83                 else{//0?+
 84                     flag=1;
 85                     break;
 86                 }
 87             }
 88         }
 89         if(flag)
 90             printf("IMPOSSIBLE\n");
 91         else{
 92             for(int i=1;i<=n;i++){
 93                 if(c[i]=='?')
 94                     c[i]='1';
 95                 printf("%c",c[i]);
 96             }
 97             cout<<endl;
 98         }
 99     }
100 }

 

 

 

 

 

我发现我的模拟题都写得相当垃圾。。。

垃圾滚了。。。

 

转载于:https://www.cnblogs.com/ZERO-/p/9464987.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值