cf C. Hacking Cypher
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的更多相关文章
- CodeForces 490C Hacking Cypher
Hacking Cypher Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)
题目链接 C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inp ...
- codeforces 490C. Hacking Cypher 解题报告
题目链接:http://codeforces.com/problemset/problem/490/C 题目意思:给出一个可能有10^6 位长的字符串且没有前导0的整数,问能否一分为二,使得前面的一部 ...
- Codeforces Round #279 (Div. 2) C. Hacking Cypher 机智的前缀和处理
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- cf490 C. Hacking Cypher(无语)
http://codeforces.com/contest/490/problem/C 表示我考场上犯逗.. 这个拆成霍纳边乘边mod即可.. 为毛我考场胡思乱想? #include <cstd ...
- 【Codeforces 490C】Hacking Cypher
[链接] 我是链接,点我呀:) [题意] 让你把一个字符串分成左右两个部分 形成两个正数 使得这两个正数一个能被a整除,一个能被b整除 找到任意一个解就可以 [题解] 枚举分割的断点i 枚举的时候用同 ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #279 (Div. 2) 题解集合
终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...
随机推荐
- 自我理解foreach工作原理
很多时候我们在使用for循环遍历一个数组的时候,我们都知道可以通过下标的索引找到当前数组中所对应的数据.这只对于简单的数组或集合,如果我们存储的数据不止只有数据项,还有一个标识项,就如同Has ...
- MyBatis报错
1.错误描写叙述 2014-11-2 15:03:11 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engin ...
- RESTEasy + JBOSS 7 Hello world application---reference
RESTEasy is JBOSS provided implementation of JAX-RS specification for building RESTful Web Services ...
- [转] restrict关键字用法
PS: 在函数中,指针参数指定了restrict,表示这个指针指向的这段区域只能通过这个指针修改 c99中新增加了一个类型定义,就是restrict. 看了下网上的相关贴子,但还是问题解决的不够.下面 ...
- Java基础知识强化之IO流笔记19:FileOutputStream的三个write方法
1. FileOutputStream的三个write方法: void write(byte[] buffer) Writes the entire contents of th ...
- redis 多实例配置
(redis的安装, 配置, 登陆等基础不再多说, 网上很多资料的, 这里只说个人对redis多实例的理解与配置) 我自己使用的redis版本是 2.8.13, 环境是 ubuntu 个人对多实例的理 ...
- Manacher算法求回文半径
http://wenku.baidu.com/link?url=WFI8QEEfzxng9jGCmWHoKn0JBuHNfhZ-tKTDMux34CeY8UNUwLVPeY5HA3TyoKU2XegX ...
- Android开发--WIFI实现
wifi的基本结构 在Android的官方文档中定义了如下五种状态: WIFI_STATE_DISABLING WIFI网卡正在关闭 0 WIFI_STATE_DISABLED WIFI网卡不 ...
- LINQ to SQL 基础
取得数据库Gateway 要操作数据库,我们首先要获得一个DataContext对象,这个对象相当于一个数据 库的Gateway,所有的操作都是通过它进行的.这个对象的名字是“Linq to SQL ...
- Android之使用json进行网络数据交换
JSON作为一种轻量级的数据交换格式,凭借其易于阅读和编写.易于解析.传输速度快等优点流行了起来.最近正好在学习Android端从服务端端取数据,Json便派上了用场.好,下面开始切入主题. 1.准备 ...