Codeforces Round #279 (Div. 2) C. Hacking Cypher

没做出三个题。 掉分了。 坑了。


这个题首先 自己交了一次。 被HACKED 超时了。 一想。 自己是 n^2 的复杂度。 超时也是必然的。


然后改算法。  nlogn 或者  n的复杂度才行。


正着判断好说。 直接模拟就好。 但是问题就在于 怎么判断 后半段 对于 b取余是否为0。 也就是自己的问题所在。


其实 对于 123 对 3取余。 正常思路肯定是 1 对3 取余 不行 然后 12对 3 取余 得到0,  再到了 3, 再对 3取余。 这是我们所知道的过程。


但是也可以这样 先 3 对3 取余 得到 0  然后 到了 2 对3取余 得到 2   然后 12 对 3取余 得到0. 这样也是可以的 


原理就是  123 % 3 = (100%3 + 20%3 + 3%3)%3 然后递推写就好了。 这次掉分就掉吧~  


只要学到知识就好。 


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 1000000+10
#define INF (1<<30)
#define mod 123456789
int aa[MAXN] = {0};
int bb[MAXN] = {0};
int main (){
    char s[MAXN];
    scanf("%s",s);
    int d = 0;
    int len = strlen(s);
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i = 0; i < len; i++){
        d = d*10+s[i]-'0';
        d %= a;
        if(d == 0){
            aa[i] = 1;
        }
    }
    d = 0;
    LL t = 1;
    for(int i = len-1; i >= 0; i--){
        d = (d%b+(s[i] - '0')%b*t%b)%b;
        d %= b;
        t = t*10%b;
        if(d == 0){
            if(s[i] == '0')
                continue;
            else
                bb[i] = 1;
        }
    }
    int wh = -1;
    for(int i = 0; i < len; i++){
        if(aa[i] && bb[i+1]){
            wh = i;
            break;
        }
    }
    if(wh != -1){
        printf("YES\n");
        for(int i = 0; i <= wh; i++)
            printf("%c",s[i]);
        printf("\n");
        for(int i = wh+1; i < len; i++)
            printf("%c",s[i]);
        printf("\n");
    }
    else
        printf("NO\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值