字符串hash:  base设置为10

枚举'='可能出现的位置,从1/2处开始到大概1/3处结束,当然大概的1/3不用计算,直接到最后就行,因为本题必然有解,输出直接结束即可。

根据'='号位置,'+'最多有四种位置,因为 等式的和位数确定,有进位和不进位,左和右,最多2X2,然后剪掉j的非法位置(这里没计算除了len=3以外的j有无非法位置的可能,剪了再说)

比较需要注意的地方是等式中非个位数字不能以'0'开头,开始只以为不以'0'开头即可,WA在了 1+0=0 ,改了j后又WA了0+0=0

代码

 #include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
using namespace std; typedef long long ll;
map< ll ,ll > done;
map<ll ,int > mp;
const ll MOD=1e9+;
const int maxLen=1e6+;
char s[maxLen];
ll P[maxLen];
ll sum[maxLen]; template<class T>
inline bool scan_d(T &ret){
char c; int sgn;
if(c=getchar(),c==EOF) return ;//EOF
while(c!='-'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret=ret*+(c-'');
ret*=sgn;
return ;
} inline void out(int x){
if(x>) out(x/);
putchar(x%+'');
} ll gcd(ll a,ll b){
return b==?a:gcd(b,a%b);
} ll Qpow(ll a,ll n){
ll ret=;
ll tmp=a%MOD;
while(n){
if(n&) ret=(ret*tmp)%MOD;
tmp=(tmp*tmp)%MOD;
n>>=;
}
return ret;
} ll getF(ll t){
if(t==) return mp[t]=;
if(mp.count(t)) return mp[t];
mp[t]=Qpow(,t-);
for(int i=;i*i<=t;++i){
if(t%i==){
mp[t]=(mp[t]-getF(i)+MOD)%MOD;
if(i*i!=t) mp[t]=(mp[t]-getF(t/i)+MOD)%MOD;
}
}
return mp[t]=(mp[t]-getF()+MOD)%MOD;
} int main()
{
P[]=;
for(int i=;i<maxLen;++i){
P[i]=P[i-]*%MOD;
}
scanf("%s",s+);
int len=strlen(s+);
sum[]=;
for(int i=;i<=len;++i){
sum[i]=(sum[i-]*+s[i]-'')%MOD;
}
//for(int i=1;i<=len;++i)
// printf("%d : %I64d\n",i,sum[i]);
int flag=;
for(int i=len/;i<len;++i){
if(s[i+]==''&&len-i>) continue;
int sumlen=len-i;
for(int j:{sumlen,sumlen-,i-sumlen,i-sumlen+}){
if(j>=i||j<) continue;
if(s[j+]==''&&i-j>) continue; //printf("i : %d j : %d\n",i,j);
ll a=(sum[j]-sum[]*P[j]%MOD+MOD)%MOD;
ll b=(sum[i]-sum[j]*P[i-j]%MOD+MOD)%MOD;
ll c=(sum[len]-sum[i]*P[len-i]%MOD+MOD)%MOD;
if((a+b)%MOD==c%MOD){
for(int k=;k<=j;++k)
putchar(s[k]);
putchar('+');
for(int k=j+;k<=i;++k)
putchar(s[k]);
putchar('=');
for(int k=i+;k<=len;++k)
putchar(s[k]);
puts("");
flag=;
break;
}
}
if(flag) break;
}
return ;
}

F - Restoring the Expression CodeForces - 898F的更多相关文章

  1. Codeforces Round #451 (Div. 2) [ D. Alarm Clock ] [ E. Squares and not squares ] [ F. Restoring the Expression ]

    PROBLEM D. Alarm Clock 题 OvO http://codeforces.com/contest/898/problem/D codeforces 898d 解 从前往后枚举,放进 ...

  2. codeforces 898F Hash

    F. Restoring the Expression time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. Codeforces 898F - Restoring the Expression(字符串hash)

    898F - Restoring the Expression 思路:字符串hash,base是10,事实证明对2e64取模会T(也许ull很费时),对1e9+7取模. 代码: #include< ...

  4. Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression

    题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...

  5. F - Make It Equal CodeForces - 1065C

    题目大意:有n座塔,塔高h[i],每次给定高度H对他们进行削切,要求每次削掉的所有格子数不能超过k个,输出最少削几次才能使所有塔的高度相同. 思路一:差分+贪心 对于每一个高度h,用一个数组让1~h的 ...

  6. Codeforces 884f F. Anti-Palindromize

    题  OvO http://codeforces.com/contest/884/problem/F (Educational Codeforces Round 31 - F) 884f 解 题目标签 ...

  7. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  8. Codeforces Round# 305 (Div 1)

    [Codeforces 547A] #include <bits/stdc++.h> #define maxn 1000010 using namespace std; typedef l ...

  9. Expression Trees

    Expression Trees 只是想简单说下表达式树 - Expression Trees 目录 简介 Lambda 表达式创建表达式树 API 创建表达式树 解析表达式树 表达式树的永久性 编译 ...

随机推荐

  1. redis内部数据结构和外部数据结构揭秘

    Redis有哪些数据结构? 字符串String.字典Hash.列表List.集合Set.有序集合SortedSet. 很多人面试时都遇到过这种场景吧? 其实除了上面的几种常见数据结构,还需要加上数据结 ...

  2. php 中文转拼音,可以只转首字母,可以设置utf8、gbk

    <?php class Pinyin { /** * 默认是gb编码,第二个参数随意设置即为utf8编 * @param type $isInitial 是否只返回首字母 * @return t ...

  3. JAVA企业级快速开发平台,JEECG 3.7.3 新春版本发布

    JEECG 3.7.3新春版本发布 -  微云快速开发平台 导读           ⊙精美Echart报表 ⊙二维码生成功能 ⊙Online接口改造采用JWT机制 ⊙智能菜单搜索 ⊙代码生成器模板优 ...

  4. android除去标题栏或全屏

    想要除去标题栏只要加上下面两句代码在Activity的onCreate方法中即可(要在setContentView之前添加). requestWindowFeature(Window.FEATURE_ ...

  5. 使用ssh密钥登录虚拟主机里的另一台主机报警的解决方案

    提示:Address 192.168.*.* maps to localhost, but this does not map back to the address - POSSIBLE BREAK ...

  6. Cmake 编译opengl开源库glfw工程及使用

    使用的是cmake gui进行编译的,路径输入好之后,点configure配置vs版本,这里是vs2013版本,然后如果画面出现红色的 需要再点击一下 Generate 然后直接点open proje ...

  7. css:长度距离的一个计算函数calc

    .calc-example{ width: calc(100% - 100px);} 可用于宽度,高度,margin,padding等长度或距离的计算 减号两边必须留一个空格

  8. Emac

    https://emacs-china.org/ 启动 console模式的emacs,$emacs -nw 学习参考: 1)<21天精通emacs> 2)Emacs常用命令简集. 3)& ...

  9. linux 内核中一个全局变量引发的性能问题

    为了调试一个功能,在一个内核模块中,增加了一个全局变量,用来统计自有skb池的申请情况. 因为是临时增加,所以没有考虑性能,一开始只是一个fail的统计,数量不多,也不太考虑是否有计数丢失的情况,毕竟 ...

  10. android手机 解锁bootloader 刷recovery 线刷rom 卡刷rom

    1 解锁bootloader 为手机安装官方驱动 按相应的组合键使手机进入fastboot模式 执行命令fastboot oem unlock 123456 (123456为厂家提供的解锁码) 手机重 ...