C. Hacking Cypher
来源:互联网 发布:山东理工大学知乎 编辑:程序博客网 时间:2024/05/18 03:08
http://codeforces.com/contest/490/problem/C
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int MAX = 1000010;char str[MAX];int a,b;int ma[MAX],mb[MAX];long long Pow(long long x, int y, int mod){///快速幂 long long res = 1; while(y >= 1){ if(y & 1) res = res * x, res %= mod; y >>= 1; x = ((x % mod)*(x % mod)) % mod; } return res;}int main(){ scanf("%s",str); scanf("%d%d",&a,&b); int len = strlen(str); memset(ma, 0, sizeof(ma)); memset(mb, 0, sizeof(mb)); ma[0] = (str[0] - '0') % a; for(int i=1; i<len; i++) ma[i] = (ma[i-1] * 10 + str[i] - '0') % a; mb[len - 1] = (str[len-1] - '0') % b; for(int i=len-2; i>=0; i--){ int tmp = len - 1 - i; mb[i] = ((str[i] - '0') * Pow(10, tmp, b) + mb[i+1]) % b; }///预先记录取模之后的值 不要每次都计算 不然会TLE bool flag = false; for(int i=0; i<=len-2; i++){///暴力枚举切开的位置 if(str[i+1] == '0') continue; if(!ma[i] && !mb[i+1]){ flag = true; puts("YES"); for(int j=0; j<=i; j++) printf("%c",str[j]); printf("\n"); for(int j=i+1; j<len; j++) printf("%c",str[j]); printf("\n"); break; } } if(!flag) puts("NO"); //system("pause"); return 0;}
0 0
- C. Hacking Cypher
- 【CODEFORCES】 C. Hacking Cypher
- CodeForces 490C Hacking Cypher
- CodeForces 490C - Hacking Cypher
- codeforces 490C Hacking Cypher
- CodeForces 490C Hacking Cypher
- Hacking Cypher(CF--490C
- Codefroces 279 div2 C. Hacking Cypher
- Codeforces 490C Hacking Cypher(暴力)
- [CodeForces 490C]Hacking Cypher[math]
- Codeforces 490C Hacking Cypher 暴力
- 【Codefroces 490 C Hacking Cypher】+ dp
- codeforces 490-C. Hacking Cypher(暴力)
- Codeforces Round #279 (Div. 2)C. Hacking Cypher
- Codeforces Round #279 (Div. 2) C. Hacking Cypher
- Codeforces Round #279 (Div. 2) C. Hacking Cypher
- Codeforces Round #279 (Div. 2)C. Hacking Cypher
- Codeforces 490C Hacking Cypher【前缀模+后缀模+暴力】
- 项目三-成绩处理函数版
- zookeeper(一)———>>>>>zookeeper的最简单了解
- PS滤镜功能详解
- 第四章 字符串和多维数组
- UIImageView 处理动画
- C. Hacking Cypher
- 0012算法笔记——【动态规划】最长公共子串问题
- IDL读取grib数据为tiff文件
- 第十三周项目5-2-3:字符串复制
- java编程思想11.9-set
- [leetcode]Plus One(int数组)
- rails+apache2+passenger+ssl实现https双向认证通信
- Jbpm续结
- Android如何同时安装相同应用程序不同版本