codeforces 117B B. Very Interesting Game(同余模定理+取模导致的循环节)
来源:互联网 发布:嘲讽知乎 编辑:程序博客网 时间:2024/04/28 06:28
题目链接:
codeforces 117B
题目大意:
给出三个数a,b,m,将不大于a,b的两个数连接后得到一个新的数,如果这个新的数能够整除m,那么2赢,否则2赢。
题目分析:
因为取模会导致出现循环节,所以如果给出的数据范围大于mod,那么我们可以只考虑一个循环节,那么我们只需要预处理出b能够通过得到的值,然后枚举A,判断是否能出现一个A不能和任何一个B组合除能被mod整除的情况,那么这个数就是最小解,如果循环节中都没有出现可行解,那么就是误解了。
AC代码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;typedef long long LL;const LL MAX = 1e7+7;const LL xx = 1e9;LL a,b,m;int dp[MAX];char s[12];int main ( ){ while ( ~scanf ( "%lld%lld%lld" , &a , &b , &m ) ) { memset ( dp , 0 , sizeof ( dp ) ); LL lim = min ( b , m ); for ( int i = 0 ; i <= lim ; i++ ) dp[i%m] = 1; lim = min ( a , m); LL ans = -1; for ( LL i = 0 ; i <= lim ; i++ ) { LL x = i*xx%m; x = (m-x)%m; if ( !dp[x] ) { ans = i; break; } } if ( ans == -1 ) puts ( "2" ); else { printf ( "1 " ); s[9] = 0; int n = 8; for ( int i = 0 ; i < 9 ; i++ ) s[i] = '0'; while ( ans ) { s[n--] = ans%10+48; ans /= 10; } puts ( s ); } }}
0 0
- codeforces 117B B. Very Interesting Game(同余模定理+取模导致的循环节)
- 同余模定理
- 同余模定理
- 同余模定理
- 同余定理 应用于大整数取模
- 取余的特点(+同余定理)
- hdoj2035 人见人爱A^B(快速幂+同余定理)
- hdu 2024(同余基本定理) 人见人爱A^B
- Codeforces 687B - Remainders Game (剩余定理)
- 同余与取模
- 【codeforces 681B】【优化循环】Economy Game
- CodeForces 482 B. Interesting Array
- CodeForces 482B Interesting Array
- codeforces 482B Interesting Array
- CodeForces 706B Interesting drink
- CodeForces 706B Interesting drink
- 【codeforces 706B Interesting drink】
- CodeForces-706B. Interesting drink
- U-Boot 第一阶段代码分析
- 快速幂求模
- POJ-1695-Magazine Delivery-dp
- Date日期工具类
- 北大ACM题目分类
- codeforces 117B B. Very Interesting Game(同余模定理+取模导致的循环节)
- 【原创】new year resolution
- Oracle数据库基础之SQL概述
- 影响未来物联网商业的三种表现
- hibernate关系映射--单向多对多@ManyToMany
- 浅谈算法和数据结构: 九 平衡查找树之红黑树
- TextView的折叠展开(动画效果)
- 关于Android4.4以下版本Webview执行LoadUrl加载js导致键盘隐藏的问题(富文本编辑器)
- MySQL5.6之后默认root密码的问题