本文主要是介绍POJ 1006 Biorhythms 中国剩余定理/扩展欧几里得,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
先看视频:http://v.youku.com/v_show/id_XMTExNTAzOTIw.html
#include<cstdio>int main()
{int p, e, i, d;int num, cnt = 1;while ( scanf("%d%d%d%d",&p,&e,&i,&d) ){if ( d == -1 ) break;num = (5544*p + 14421*e + 1288*i - d) % 21252;if ( num <= 0 )num += 21252;printf("Case %d: the next triple peak occurs in %d days.\n",cnt++,num);}return 0;
}
#include<cstdio>int ext_gcd ( int a, int b, int &x, int &y )
{int t, ret;if ( b == 0 ){x = 1, y = 0;return a;}ret = ext_gcd ( b, a%b, x, y );t = x, x = y, y = t-a/b*y;return ret;
}int modular_linear_system ( int b[], int w[], int k )
{int d, x, y, a = 0, n = 1, m, i;for ( i = 0; i < k; i++ )n *= w[i];for ( i = 0; i < k; i++ ){m = n / w[i];d = ext_gcd ( w[i], m, x, y );a = ( a + y*m*b[i] ) % n;}return (a+n) % n;
}int main()
{int w[3] = {23,28,33};int b[3], date;int num, cnt = 1;while ( scanf("%d%d%d%d",&b[0],&b[1],&b[2],&date) ){if ( date == -1 ) break;num = modular_linear_system( b, w, 3 ) - date;if ( num <= 0 )num += 21252;printf("Case %d: the next triple peak occurs in %d days.\n",cnt++,num);}return 0;
}
http://www.cnblogs.com/zsboy/archive/2012/01/16/2323244.html
这篇关于POJ 1006 Biorhythms 中国剩余定理/扩展欧几里得的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!