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. Android 4.4(KitKat)中VSync信号的虚拟化

    原文地址:http://blog.csdn.net/jinzhuojun/article/details/17293325 Android 4.1(Jelly Bean)引入了Vsync(Vertic ...

  2. objective-c 加号 减号 - +

    “加号代表static”是错误的说法,可能跟你那样表达的人其实意思是:“前置加号的方法相当于Java 里面的静态方法”. 在Oc中,方法分为类方法和实例方法. 前置加号(+)的方法为类方法,这类方法是 ...

  3. NYOJ 491 幸运三角形

    幸运三角形 import java.util.Scanner; public class Main{//搜索 static int sum=0,n; public static void main(S ...

  4. hdu 4424 Conquer a New Region (并查集)

    ///题意:给出一棵树.树的边上都有边权值,求从一点出发的权值和最大,权值为从一点出去路径上边权的最小值 # include <stdio.h> # include <algorit ...

  5. Nginx优化具体,应对高并发

     nginx指令中的优化(配置文件) worker_processes 8; nginx进程数,建议依照cpu数目来指定.一般为它的倍数. worker_cpu_affinity 00000001 ...

  6. [Angular 2] Passing data to components with @Input

    @Input allows you to pass data into your controller and templates through html and defining custom p ...

  7. 【C语言天天练(二一)】内联函数

            引言:调用函数时,一般会由于建立调用.传递參数.跳转到函数代码并返回等花费掉一些时间,C语言的解决的方法是使用类函数宏.在C99中,还提出了第二种方法:内联函数.         内联 ...

  8. AutoBackupForApps

    This sample demonstrates how to selectively disable Automatic Backups in Android M, either by adjust ...

  9. SpringMVC10数据验证

    /** * @NotBlank 作用在String * @NotEmpty 作用在集合上 * @NotNull 作用在基本数据类型上 * */ public class User { @NotNull ...

  10. codevs3013单词背诵

    /* 手打的哈希+线性的维护 第一问:hash一下 并且用个h记录某个单词要背的 第二问:线性的跑一边 开始队列里装下前一些单词使这一坨符合要求 并且记录出现次数num 然后开始从前面删 删除的条件: ...