http://codeforces.com/contest/490/problem/C

题意:把一个很大的数分成两部分,前一部分可以被a整除,后一部分可以被b整除,如果存在输出这两部分,两部分都不能含有前导0;

思路:从左到右求出在每一位对a的余数记录在aa数组里面,再从右向左在每一位对b的余数记录在bb数组里面。在aa[i]==0&&bb[i+1]==0&&bb[i+1]!='0'的情况下,就存在答案。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std; char str[];
int a,b;
int aa[],bb[]; int main()
{
while(scanf("%s",str)!=EOF)
{
scanf("%d%d",&a,&b);
int k=strlen(str);
int t=;
for(int i=; i<k; i++)
{
t+=(str[i]-'');
aa[i]=t%a;
t%=a;
t*=;
}
int s=,t1=;
for(int i=k-; i>=; i--)
{
bb[i]=((str[i]-'')*s+t1)%b;
t1=((str[i]-'')*s+t1)%b;
s=(s*)%b;
}
bool flag=false;
int pos=-;
for(int i=; i<k-; i++)
{
if(aa[i]==&&bb[i+]==&&str[i+]!='')
{
pos=i;
flag=true;
break;
}
}
if(flag)
{
printf("YES\n");
for(int i=; i<=pos; i++)
{
printf("%c",str[i]);
}
printf("\n");
for(int i=pos+; i<k; i++)
{
printf("%c",str[i]);
}
printf("\n");
}
else
{
printf("NO\n");
}
}
return ;
}

cf C. Hacking Cypher的更多相关文章

  1. CodeForces 490C Hacking Cypher

    Hacking Cypher Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

  2. Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀

    C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)

    题目链接 C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inp ...

  4. codeforces 490C. Hacking Cypher 解题报告

    题目链接:http://codeforces.com/problemset/problem/490/C 题目意思:给出一个可能有10^6 位长的字符串且没有前导0的整数,问能否一分为二,使得前面的一部 ...

  5. Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理

    #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...

  6. cf490 C. Hacking Cypher(无语)

    http://codeforces.com/contest/490/problem/C 表示我考场上犯逗.. 这个拆成霍纳边乘边mod即可.. 为毛我考场胡思乱想? #include <cstd ...

  7. 【Codeforces 490C】Hacking Cypher

    [链接] 我是链接,点我呀:) [题意] 让你把一个字符串分成左右两个部分 形成两个正数 使得这两个正数一个能被a整除,一个能被b整除 找到任意一个解就可以 [题解] 枚举分割的断点i 枚举的时候用同 ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #279 (Div. 2) 题解集合

    终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...

随机推荐

  1. 面向GC的Java编程

    转自http://hellojava.info/?p=341 HelloJava微信公众账号网站 面向GC的Java编程 Leave a reply 这是内部一个同事(沐剑)写的文章,国外有一家专门做 ...

  2. Windows环境下python多版本配置方案

    系统环境 Windows,安装了msys2,windows和msys2都安装了python,且版本比较多,使用shell/bash聚合工具conemu64 配置方案 配置msys2环境用户目录下的.b ...

  3. JVM运行数据区

    1.java虚拟机在运行的时候会把内存分为以下几个区域,如图:

  4. 雅虎NCP:网络黄页的终结者

    雅虎NCP是什么,NCP能做什么,为什么NCP能够成为网络黄页的终结者.NCP在颠覆既有市场格局的同时,其真实目的时什么?是成为网络化操作系统还是图谋最大化长尾广告.笔者相信,过不了多久,市场将会告诉 ...

  5. SpringMVC 学习笔记(一) Hello World

    springMVC概述: Spring MVC 是眼下最主流的MVC 框架之中的一个 Spring MVC 通过一套 MVC 注解.让 POJO 成为处理请 求的控制器,而无须实现不论什么接口. 支持 ...

  6. 多线程下的NSOperation和NSOperationQueue的使用

    多线程下的NSOperation和NSOperationQueue的使用 NSOperation和NSOperationQueue的介绍: NSOperation是Cocoa中的一个抽象类,用来封装单 ...

  7. [转] C++11带来的move语义

    PS: 通过引入接收右值的函数形参,可以通过接收右值来实现高效 PS在C++11中,标准库在<utility>中提供了一个有用的函数std::move,这个函数的名字具有迷惑性,因为实际上 ...

  8. [转] C++指针加整数、两个指针相减的问题

    http://blog.csdn.net/onlyou930/article/details/6725051 说来惭愧,写C++有一段时间了.这个问题从来没有认真考虑过,此次标记于此: 考虑如下问题: ...

  9. 判断textview是否被截断

    Layout l = textview.getLayout(); if ( l != null){ int lines = l.getLineCount(); if ( lines > 0) i ...

  10. 【分享】w32service table XPsp2

    Ord   Address   fnAddr   Symbols-------------------------------- [  0] BF999280: BF93569A (win32k!Nt ...