CodeForces 490C Hacking Cypher
来源:互联网 发布:管家婆软件生产教程 编辑:程序博客网 时间:2024/05/16 15:32
题意:
一串数字 从某个地方分开成两个数字 要求前面的数字被A整除 后面的被B整除 求分开的两个数字
思路:
假设我们将原串S这样分成两个数字XY 则X%A==0 Y%B==0
那么我们可以处理从头到i这个位置%A的值为多少 这样很容易判断第一个条件
对于第二个条件我们可以这样理解 S % B == ( X % B * 10^|Y| % B ) + Y % B
如果Y%B==0 那么 S % B == X % B * 10^|Y| % B
所以我们可以处理从头到i这个位置%B的值为多少 和 10的某次幂%B的值为多少 判断i位置是否满足上述等式
注意:Y的第一个字符不能是‘0’
代码:
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<map>#include<set>#include<vector>#include<queue>#include<cstdlib>#include<ctime>#include<cmath>using namespace std;typedef long long LL;#define N 1000010char s[N];LL a, b;int ans;LL A[N], B[N], T[N] = { 1 };int main() { scanf("%s", s + 1); cin >> a >> b; int len = strlen(s + 1); for (int i = 1; i <= len; i++) { A[i] = (A[i - 1] * 10 + s[i] - '0') % a; B[i] = (B[i - 1] * 10 + s[i] - '0') % b; T[i] = T[i - 1] * 10 % b; } ans = 0; for (int i = 2; i <= len; i++) { if (s[i] != '0' && A[i - 1] == 0) { if (B[i - 1] * T[len - i + 1] % b == B[len]) { ans = i; break; } } } if (ans) { puts("YES"); for (int i = 1; i <= len; i++) { if (i == ans) putchar('\n'); putchar(s[i]); } } else puts("NO"); return 0;}
0 0
- CodeForces 490C Hacking Cypher
- CodeForces 490C - Hacking Cypher
- codeforces 490C Hacking Cypher
- CodeForces 490C Hacking Cypher
- 【CODEFORCES】 C. Hacking Cypher
- Codeforces 490C Hacking Cypher(暴力)
- [CodeForces 490C]Hacking Cypher[math]
- Codeforces 490C Hacking Cypher 暴力
- codeforces 490-C. Hacking Cypher(暴力)
- Codeforces 490C Hacking Cypher【前缀模+后缀模+暴力】
- codeforces 490C Hacking Cypher(大数逆向取模)
- Hacking Cypher(CF--490C
- 【Codefroces 490 C Hacking Cypher】+ dp
- 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
- 第13周项目2-成绩处理
- 第十三周项目四2—字符数组排序
- vmware ubuntu linux tomcat Xshell Xftp 搭建网站后台——(一)环境搭建-vmware安装
- windows MySQL 报“Got a packet bigger than 'max_allowed_packet' bytes”错误,解决过程.
- SQL查询统计表中一列求和
- CodeForces 490C Hacking Cypher
- 在Oracle中执行动态SQL的几种方法
- Android中全屏 取消标题栏,TabHost中设置NoTitleBar的三种方法
- 小车遥控器干扰器--车罩起火殃及爱车 保险公司表示不赔
- Ajax提交回写 form提交
- shfileoperation 提示无法删除文件的有关问题
- 串口编程及实例
- 增加 addDataScheme("file") 才能收到SD卡插拔事件的原因分析 -- 浅析android事件过滤策略
- 小车干扰器--老太车祸后突发白血病 车险和司机赔2.8万