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. Tips--8080端口被占用了怎么办

    下面以win7为例: 打开任务管理器   ctrl+alt+. 找到8080端口对应的PID 停止相应PID的进程即可:

  2. android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)

    shape使用.渐变色.分割线.边框.半透明.半透明阴影效果. 首先简单了解一下shape中常见的属性.(详细介绍参看  api文档 ) 转载请注明:Rflyee_大飞: http://blog.cs ...

  3. Linux磁盘管理:LVM逻辑卷的拉伸及缩减

    ①查看当前VG的信息,保证VG中有足够的空闲空间 通过 vgdisplay 或者 vgs 命令 [root@rusky ~]# vgs rusky-vg VG #PV #LV #SN Attr VSi ...

  4. 码表 ASCII Unicode GBK UTF-8

    2017-1-3 [ASCII]一个字节(7位,128个字符,2个16进制) 不包含中文 ASCII(American Standard Code for Information Interchang ...

  5. codevs 1183 泥泞的道路 (二分+SPFA+差分约束)

    /* 二分答案(注意精度) 对于每一个答案 有(s1+s2+s3...)/(t1+t2+t3...)>=ans 时符合条件 这时ans有变大的空间 对于上述不等式如果枚举每一条路显得太暴力 化简 ...

  6. js求字符长度

    </script> <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  7. Sql Server跨服务器导出特定表数据

    --连接服务器 exec sp_addlinkedserver 'Test',' ','SQLOLEDB', '192.168.0.7'; exec sp_addlinkedsrvlogin 'Tes ...

  8. MySQL 插入数据

    MySQL 插入数据 MySQL 表中使用 INSERT INTO SQL语句来插入数据. 你可以通过 mysql> 命令提示窗口中向数据表中插入数据,或者通过PHP脚本来插入数据. 语法 以下 ...

  9. vim 支持gb2312

    vi  /etc/vimrc 中添加如下,并保存. set termencoding=encodingset fileencodings=utf-8,gbk,ucs-bom,cp936set shif ...

  10. 【USACO 1.2.1】挤牛奶

    [问题描述] 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300时刻(从5点开始计时,秒为单位)给他的牛挤奶,一直到1000时刻.第二个农民在700时刻开始,在 1200时刻结束.第 ...