摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef long long LL; 6 LL pow_mod(LL a,LL p,LL n){ 7 if(p == 0) return 1; 8 LL ans = pow_mod(a,p / 2,n); 9 ans = ans... 阅读全文
posted @ 2016-08-24 23:56 Yan_Bin 阅读(109) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef long long LL; 6 // 求x和y使得ax+by=d并且|x|+|y|最小。其中d=gcd(a,b) 7 void exgcd(LL a,LL b,LL& d,LL& x,LL& y){ 8 if(!b) d = a,x =... 阅读全文
posted @ 2016-08-24 23:50 Yan_Bin 阅读(111) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn = 10000000; 6 const int maxp = 700000; 7 const int MOD = 1e9; 8 typedef long long LL; 9 int vis[maxn]; //vis[i] =... 阅读全文
posted @ 2016-08-24 23:43 Yan_Bin 阅读(154) 评论(0) 推荐(0)
摘要: Exploring Pyramids Archaeologists have discovered a new set of hidden caves in one of the Egyptian pyramids. The decryption of ancient hieroglyphs on 阅读全文
posted @ 2016-08-24 23:02 Yan_Bin 阅读(142) 评论(0) 推荐(0)
摘要: 带标号连通图计数。统计有n(n<=50)个顶点的连通图有多少个。图的顶点有编号。例如n=3时有4个不同的图,n=4时有38个图,n=5时有728个图,n=6时有26704个图。 分析:设f(n)为所求答案,g(n)为有n个顶点的非连通图,则f(n)+g(n)=h(n)=2^n*(n-1)/2。g(n 阅读全文
posted @ 2016-08-24 19:44 Yan_Bin 阅读(958) 评论(0) 推荐(0)
摘要: Ingenuous Cubrency People in Cubeland use cubic coins. Not only the unit of currency is called acube but also the coins are shaped like cubes and thei 阅读全文
posted @ 2016-08-24 18:46 Yan_Bin 阅读(243) 评论(0) 推荐(0)
摘要: Matches We can make digits with matches as shown below: Given N matches, find the number of different numbers representable using the matches. We shal 阅读全文
posted @ 2016-08-24 16:42 Yan_Bin 阅读(318) 评论(0) 推荐(0)
摘要: Cheerleaders In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles are substantial during b 阅读全文
posted @ 2016-08-24 15:27 Yan_Bin 阅读(370) 评论(0) 推荐(0)
摘要: 题意:从1~n中选出3个整数,使得他们三边能组成三角形,给定一个n,问能组成多少个不同的三角形? 分析:n最大能达到1000000,所以只能用O(n)来解决。 设最大边为x的三角形个数为C(x),y+z>x , x-y<z<x,当y=1时 z无解,y=2,z一个解……y=x-1,z有x-2个解 所以 阅读全文
posted @ 2016-08-24 01:04 Yan_Bin 阅读(146) 评论(0) 推荐(0)
摘要: Chess Queen You probably know how the game of chess is played and how chess queen operates. Two chess queens are in attacking position when they are o 阅读全文
posted @ 2016-08-24 00:16 Yan_Bin 阅读(215) 评论(0) 推荐(0)