08 2016 档案
摘要:1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 // 矩阵的STL实现 7 typedef vector vec; 8 typedef vector mat; 9 typedef long long ll; 10 const int MOD = 10000; 11 // 矩阵乘法 ...
阅读全文
摘要:1 #include 2 #include 3 const int maxn = 100; 4 typedef struct{ 5 long long Mat[maxn][maxn]; 6 }MAT; 7 long long MOD,d; // d是方阵的行数或者列数 8 // 方阵的乘法,模MOD 9 MAT mul(MAT a,MAT b){ 10 MAT c;...
阅读全文
摘要:10870 RecurrencesConsider recurrent functions of the following form:f(n) = a1f(n 1) + a2f(n 2) + a3f(n 3) + : : : + adf(n d); for n > d;wh
阅读全文
摘要:1 #include 2 #include 3 #include 4 const int maxn = 100; 5 typedef double Matrix[maxn][maxn]; 6 // 要求系数矩阵可逆 7 // 这里A是增广矩阵,A[i][n]表示第i个方程右边的常数bi 8 // 运行结束后A[i][n]是第i个未知数的值 9 void gauss_eli...
阅读全文
摘要:11077 Find the PermutationsSorting is one of the most used operations in real life, where Computer Science comes into act. It iswell-known that the lo
阅读全文
摘要:12103 Leonardo's Notebook| I just bought Leonardo's secret notebook! Rare object col-lector Stan Ucker was really agitated but his friend, specialinve
阅读全文
摘要:10294 Arif in Dhaka (First Love Part 2)Our hero Arif is now in Dhaka (Look at problem 10244 – First Love if you want to know more aboutArif, but that
阅读全文
摘要:11762 Race to 1Dilu have learned a new thing about integers, which is - any positive integer greater than 1 can bedivided by at least one prime number
阅读全文
摘要:11427 Expect the ExpectedSome mathematical background. This problem asks you to compute the expected value of a randomvariable. If you haven’t seen th
阅读全文
摘要:11722 Joining with FriendYou are going from Dhaka to Chittagong by train and you came to know one of your old friends is goingfrom city Chittagong to
阅读全文
摘要:11021 TribblesGRAVITATION, n.“The tendency of all bodies to approach one another with a strengthproportion to the quantity of matter they contain – th
阅读全文
摘要:10561 TreblecrossTreblecross is a two player game where the goal is to get three ‘X’ in a row on a one-dimensional board.At the start of the game all
阅读全文
摘要:11859 Division Game Division game is a 2-player game.In this game, there is a matrix of positive integers with N rows and M columns.Players make their
阅读全文
摘要:考虑一个简单的游戏: 有两个盒子,其中一个装有m颗糖、另一个装有n颗糖,将这样的状态记为(m,n)。每次的移动是将其中一个盒子清空,把另一个盒子的一些糖拿到被清空的盒子里使得两个盒子至少各有一颗糖。两个操作者轮流进行操作,不能操作者败。需要判断一个状态是否先手必败。 按照k=m+n从小到大的顺序进行
阅读全文
摘要:11916 Emoogle GridYou have to color an M N (1 M;N 108) two dimensional grid. You will be provided K(2 K 108) different colors to do so. You
阅读全文
摘要:10253 Series-Parallel NetworksIn this problem you are expected to count two-terminal series-parallel networks. These are electricnetworks considered t
阅读全文
摘要:1 #include 2 #include 3 #include 4 #include 5 typedef long long LL; 6 int mul_mod(int a,int b,int n){ // a、b都小于n 7 return a * b % n; 8 } 9 int pow_mod(int a,int p,int n){ 10 if(p...
阅读全文
摘要: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 =...
阅读全文
摘要: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 =...
阅读全文
摘要:GCD Extreme (II) Given the value of N, you will have to find the value of G. The definition of G is given below: uva 11426 - GCD - Extreme (II)" v:sha
阅读全文
摘要:题意: 判断一个关于n的多项式P(n)能否恒被一个正整数D整除。 输入样例: (n^2-n)/2 (2n^3+3n^2+n)/6 (-n^14-11n+1)/3 输出格式: 如果满足条件就输出“Always an integer”否则输出“Not always an integer”。 分析: 多项
阅读全文
摘要:Investigating Div-Sum Property Aninteger is divisible by 3 if the sum of its digits is also divisible by 3. Forexample, 3702 is divisible by 3 and 12(
阅读全文
摘要:也可以由欧拉定理,对任意a属于Zn,a^(phi(n))=1(modn)。于是a的逆就是a^(phi(n) - 1)。 如果n是素数的话,a的逆就是pow_mod(a,n-2,n)
阅读全文
摘要:1 #include 2 #include 3 #include 4 // 计算欧拉phi函数。phi(n)是不超过n且与n互素的正整数个数 5 int euler_phi(int n){ 6 int m = (int)sqrt(n + 0.5); 7 int ans = n; 8 // phi(n)=n(1-1/p1)(1-1/p2)...(1-1...
阅读全文
摘要: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...
阅读全文
摘要: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 =...
阅读全文
摘要: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] =...
阅读全文
摘要:Exploring Pyramids Archaeologists have discovered a new set of hidden caves in one of the Egyptian pyramids. The decryption of ancient hieroglyphs on
阅读全文
摘要:带标号连通图计数。统计有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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:Cheerleaders In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Their roles are substantial during b
阅读全文
摘要:题意:从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个解 所以
阅读全文
摘要: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
阅读全文
摘要:给定空间里n(n<=1000)个点,假设任意三个点都不共线。 将任意两点之间的连线涂上红色或者黑色。 问3条边同色的三角形个数。 分析: 由于三角形总数C(n,3),所以求出异色三角形个数就求出了同色三角形个数。 我们发现这样的对应关系,一个异色三角形存在两个顶点,该三角形中与它们相邻的两边是不同色
阅读全文
摘要:Minimum Sum LCMLCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is amultiple of all integers of that set. It i
阅读全文
摘要:Choose and divideThe binomial coefficient C(m; n) is defined asC(m; n) =m!(m n)! n!Given four natural numbers p, q, r, and s, compute the the resul
阅读全文
摘要:Colossal Fibonacci Numbers!Oooh...prettyThe i’th Fibonacci number f(i) is recursivelydefined in the following way:• f(0) = 0 and f(1) = 1• f(i + 2) =
阅读全文
摘要:map实例代码: 1 // UVa156 Ananagrams 2 // Rujia Liu 3 // 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排得到输入文本中的另外一个单词 4 // 算法:把每个单词“标准化”,即全部转化为小写字母然后排序,然后放到map中进行统计 5
阅读全文
摘要:以结构体point为例,成员变量x,y,定义加法和输出流方式。
阅读全文
摘要:考虑这样一个题目: 输入的每行是若干整数,要求输出每行所有整数的和。 实例代码:
阅读全文
摘要:1.set集合中如果存储string类,那么集合元素将按照字典序全部排好。 2.set集合的遍历: set<string>::iterator it; for(it = dict.begin() ; it != dict.end() ; it++) cout << *it << endl;
阅读全文
摘要:Andy’s First Dictionary Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words t
阅读全文
摘要:The Blocks Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 101 uDebug The Blocks Problem Submit Stat
阅读全文
摘要:1.Vector数组可以认为是大小的数组。 2.它可以实现排序,函数是sort(v.begin(),v.end() 。 3.它可以实现二分查找功能,函数是lower_bound(v.begin(),v.end(),x)。查找的是值x,返回第一个大于或者等于小的值的指针。如果查找返回的是指针v.end
阅读全文
摘要:Where is the Marble? Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 10474 uDebug Where is the Marble? Submi
阅读全文
摘要:Packets Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Submit Status Practice POJ 1017 Description A factory produces products pac
阅读全文
摘要:524 Prime Ring ProblemA ring is composed of n (even number) circles as shown in diagram. Putnatural numbers 1; 2; : : : ; n into each circle separatel
阅读全文
摘要:Yogurt factory Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 2393 Description The cows hav
阅读全文
摘要:Stall Reservations Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practice POJ 3190 Description Oh those picky N (1
阅读全文
摘要:Radar Installation Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 1328 Description Assume t
阅读全文
摘要:Cleaning Shifts Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 2376 Description Farmer John
阅读全文
摘要:1589 XiangqiXiangqi is one of the most popular two-player board games in China. The game represents a battlebetween two armies with the goal of captur
阅读全文
摘要:We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors.
阅读全文
摘要:Hopscotch Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practice POJ 3050 Description The cows play the child's gam
阅读全文
摘要:213 Message DecodingSome message encoding schemes require that an encoded message be sent in two parts. The first part,called the header, contains the
阅读全文
摘要:In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decided on the following strategy. Every
阅读全文
摘要:Red and Black Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 1979 Description There is a re
阅读全文
摘要:1339 Ancient CipherAncient Roman empire had a strong government system with various departments, including a secretservice department. Important docum
阅读全文
摘要:202 Repeating DecimalsThe decimal expansion of the fraction 1/33 is 0:03, where the 03 is used to indicate that the cycle 03repeats indefinitely with
阅读全文
摘要:1588 KickdownA research laboratory of a world-leading automobile company has received an order to create a specialtransmission mechanism, which allows
阅读全文
摘要:1587 BoxIvan works at a factory that produces heavy machinery. He has a simple job | he knocks up woodenboxes of different sizes to pack machinery for
阅读全文
摘要:Best Cow Line, Gold Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 3377 Description FJ is
阅读全文
摘要:Ants Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice OpenJ_Bailian 1852 Description An army of ants walk o
阅读全文
摘要:227 PuzzleA children’s puzzle that was popular 30 years ago consisted of a 55 frame which contained 24 smallsquares of equal size. A unique letter of
阅读全文
摘要:455 Periodic StringsA character string is said to have period k if it can be formed by concatenating one or more repetitionsof another string of lengt
阅读全文
摘要:Digit Counting Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 1225 uDebug Description Trung is bored with h
阅读全文
摘要:Circular Sequence Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 1584 uDebug Description Some DNA sequences
阅读全文
摘要:B - Palindromes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 401 uDebug Description A regular palindrome
阅读全文
摘要:10082 WERTYUA common typing error is to place the hands onthe keyboard one row to the right of the correctposition. So ‘Q’ is typed as ‘W’ and ‘J’ is
阅读全文