07 2012 档案
摘要://graph.h头文件typedef int InfoType;#define MAXV 100//最大顶点个数//定义邻接矩阵类型typedef struct{ int no;//顶点标号 InfoType info;//顶点其他信息,这里用于存放权值}VertexType;//顶点类型typedef struct//图的定义{ int edges[MAXV][MAXV];//邻接矩阵 int n,e;//顶点数,弧数 VertexType vexs[MAXV];//存放顶点信息}MGraph;//图的邻接矩阵类型//以下定义邻接表类型typedef stru...
阅读全文
摘要:Eddy's digital RootsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2433 Accepted Submission(s): 1391 Problem DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single
阅读全文
摘要:/*Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem Description某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下: 从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数, 凡报到三的出列,剩下的向小序号方向靠拢,继续从头开始进行一至二报数。。。,以后从头开始轮流进行一至二报数、 一至三报数直到剩下的人数不超过三人为止。 Input本题有多个测试数据组,第一行为组数N,接着为N行新兵人数,新兵人数不超过5000。 Output共有N行,分..
阅读全文
摘要:归并(Merge)排序法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的。然后再把有序子序列合并为整体有序序列。如 设有数列{6,202,100,301,38,8,1} 初始状态: [6] [202] [100] [301] [38] [8] [1] 比较次数 i=1 [6 202 ] [ 100 301] [ 8 38] [ 1 ] 3 i=2 [ 6 100 202 301 ] [ 1 8 38 ] 4 i=3 [ 1 6 8 38 100 202 301 ] 4 总计: 11次#include <stdio.h>#inclu
阅读全文
摘要:#include <stdio.h>#define N 10int main(){ int a[N]; int i,j,temp; for(i=0;i<N;i++) scanf("%d",&a[i]); for(i=0;i<N-1;i++) //冒泡排序的核心代码,通过比较相邻两个,达到排序效果. for(j=1;j<N-i;j++)//可以自己举例子按算法过程来实现 if(a[j]<a[j-1]) { temp=a[j]; a[j]=a[j-1]; a[j-1]=temp; } for(i=0;i<N;i++) print
阅读全文
摘要:插入排序,就像好多书上讲的像抓牌时将刚抓的新牌插入手里已经排好序的牌。a数组像牌堆,b数组像已经抓到我们手里的牌#include <stdio.h>#define N 10 //这里是定义要排序的数目int main(){ int a[N],b[N]; //定义数组,a数组用来存输入的数,b数组用来存排序的结果 int i,j; for(i=0;i<N;i++) scanf("%d",&a[i]); b[0]=a[0]; for(i=1;i<N;i++) { j=i; while(j&&b[j-1]>a[i])//这里作
阅读全文
摘要:/*Problem ETime Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 1 Accepted Submission(s) : 1Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem DescriptionMatrix multiplication problem is a typical example of dynamical programming.Suppose you
阅读全文
摘要:Problem FTime Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 3 Accepted Submission(s) : 2Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem Description“Point, point, life of student!” This is a ballad(歌谣)well known in colleges, and you must
阅读全文
摘要:Problem GTime Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 7 Accepted Submission(s) : 3Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem DescriptionIn millions of newspapers across the United States there is a word game called Jumble. Th
阅读全文
摘要:Problem HTime Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 6 Accepted Submission(s) : 2Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem Description The most important part of a GSM network is so called Base Transceiver Station (BTS). Th
阅读全文
摘要:/*2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6738 Accepted Submission(s): 2022Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.Input One positive integer on each line, the value of n.
阅读全文
摘要:A+B ComingTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3359 Accepted Submission(s): 2087 Problem DescriptionMany classmates said to me that A+B is must needs. If you can’t AC this problem, you would invite me for night meal. ^_^InputInpu...
阅读全文
摘要:初等数论昨晚写到凌晨近一点,终于把自己目前会的数论知识做了下终结,最后发现原来只有这么点东西。。。路还好远O(∩_∩)O哈!一.求最大公约数:gcd(a,b)代表a,b的最大公约数,设为d;(1)朴素算法:暴力枚举咯.,先比较a,b大小,然后从1开始直到较小的那个数,算出最大可以被2数同时整除的数,...
阅读全文
摘要:除了2以外,素数都是奇数,这是关键1.快速查找素数(范围大所以用数组)#include #include #include #include #define N 1000000using namespace std;bool hash[N];int main(){ int i,j=0;(最快)0.3sfor(j=4;j#include#include#includeusing namespace std;const int M1=2000100,M2=1000000;bool NotPrime[M1]={1,1,0};int Prime[M2];int PrimeNum=0;int main(
阅读全文
摘要:#include<iostream>#include<stdio.h>#include<cstring>#include<iomanip>usingnamespacestd;intmain(){inti,sum,l,k,j,h;charc[1000],c1[1000][1000];while(cin.getline(c,999)){sum=0;if(strcmp(c,"#")==0)break;l=strlen(c);k=0;j=0;for(i=0;i<l;i++){if(c[i]!='')c1[k][j
阅读全文
摘要:*Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7012 Accepted Submission(s): 4968Problem Description "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166
阅读全文
摘要:此算法可以求任意两点的最短距离,其中边权值可以为负数,而dijkstra只能是固定的点间的距离,并且边全值不能为负数。保存的是后面的点(更好)#include#include#includeusing namespace std;#define N 100#define MAX 1000000int...
阅读全文
摘要:/*排列组合 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1130 Accepted Submission(s): 467Problem Description 有n种物品,并且知道每种物品的数量。要求从中选出m件物品的排列数。例如有两种物品A,B,并且数量都是1,从中选2件物品,则排列有"AB","BA"两种。Input 每组输入数据有两行,第一行是二个数n,m(1<=m,n<=10
阅读全文
摘要:Dijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止。Dijkstra算法能得出最短路径的最优解,但由于它遍历计算的节点很多,所以效率低。 Dijkstra算法是很有代表性的最短路算法,在很多...
阅读全文
摘要:Problem DescriptionA simple mathematical formula for e iswhere n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.OutputOutput the approximations of e generated by the above formula for the values of n from 0 to 9. The begi...
阅读全文
摘要:Input输入数据的第一行是一个整数C,表示测试实例的个数,然后是C 行数据,每行包含一个整数n(0<n<=10000),表示折线的数量。Output对于每个测试实例,请输出平面的最大分割数,每个实例的输出占一行。Sample Input2 1 2Sample Output2 7主要是找规律#include<stdio.h>#include<iostream>#include<algorithm>#include<cmath>using namespace std;int main(){ int t,ans,n; scanf(&quo
阅读全文
摘要:/*不容易系列之(4)——考新郎 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12511 Accepted Submission(s): 4740Problem Description 国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的:首先,给每位新娘打扮得几乎一模一样,并盖上大大的红盖头随机坐成一排; 然后,让各位新郎寻找
阅读全文
摘要:/*Binomial Showdown Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15798 Accepted: 4839DescriptionIn how many ways can you choose k elements out of n elements, not taking order into account? Write a program to compute this number. InputThe input will contain one or more test cases. Each
阅读全文
摘要:/*Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27679 Accepted: 7638DescriptionA single positive integer i is given. Write a program to find the digit located in the position i in the sequence of number groups S1S2...Sk. Each group Sk consists of a sequence of positive i
阅读全文
摘要:Happy 2006Time Limit: 3000MSMemory Limit: 65536KTotal Submissions: 6940Accepted: 2192DescriptionTwo positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1. For instance, 1, 3, 5, 7, 9...are all relatively prime to 2006. Now your job is easy: for the g.
阅读全文
摘要:#include#include#include#includeusing namespace std;int main(){int i,a[3]={2,1,3};//sort(a,a+3);//没有这个的话,只能从当前排列。for(int j=0;j#include#include#includeusing namespace std;int main(){ int l,i;char a[15];scanf("%s",a);l=strlen(a);//sort(a,a+l,);//没有这个的话,只能从当前排列。printf("%s\n",a);//必须
阅读全文
摘要:AnagramTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 15507Accepted: 6331DescriptionYou are to write a program that has to generate all possible words from a given set of letters. Example: Given the word "abc", your program should - by exploring all different combination of the t
阅读全文
摘要:/*ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4928 Accepted: 2964DescriptionIt is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and thereby to counter a chronic breakdown in law and order, t
阅读全文
摘要:int x,y,d;void exp_gcd(int a,int b){int temp;if(b==0){x=1;y=0;d=a;//最大公约数为d}else//必须有{ exp_gcd(b,a%b); temp=x; x=y; y=temp-(a/b)*y;}} int x,y;int exp_gcd(int a,int b)//返回值为最大公约数{int temp,p;if(b==0){x=1;y=0;return a;}else//这里的else可以不要,因为return了就不会做下面。{ p=exp_gcd(b,a%b); temp=x; x=y; y=temp-(a/b)*y;re
阅读全文
摘要:Problem Description要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。Input数据的第一行是一个T,表示有T组数据。 每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。Output对应每组数据输出(A/B)%9973。Sample Input2 1000 53 87 123456789Sample Output7922 6060#include<iostream>#include<stdio.h>#incl
阅读全文
摘要:Description两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。 我们把这两只青蛙分别叫做青蛙A和青蛙B,并且规定纬度线上东经0度处为原点,由东往西为正方向,单位长度1米,这样
阅读全文
摘要:/*Raising Modulo NumbersTime Limit: 1000MSMemory Limit: 30000KTotal Submissions: 3555Accepted: 1964DescriptionPeople are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathem
阅读全文
摘要:/*DescriptionGiven n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz. InputThere are several test cases. For each test case, standard inp
阅读全文
摘要:DescriptionTen mathematicians are flying on a balloon over the Pacific ocean. When they are crossing the equator they decide to celebrate this event and open a bottle of champagne. Unfortunately, the cork makes a hole in the balloon. Hydrogen is leaking out and the balloon is descending now. Soon it
阅读全文
摘要:Description题目描述: 大家知道,给出正整数n,则1到n这n个数可以构成n!种排列,把这些排列按照从小到大的顺序(字典顺序)列出,如n=3时,列出1 2 3,1 3 2,2 1 3,2 3 1,3 1 2,3 2 1六个排列。 任务描述: 给出某个排列,求出这个排列的下k个排列,如果遇到最后一个排列,则下1排列为第1个排列,即排列1 2 3…n。 比如:n = 3,k=2 给出排列2 3 1,则它的下1个排列为3 1 2,下2个排列为3 2 1,因此答案为3 2 1。 Input第一行是一个正整数m,表示测试数据的个数,下面是m组测试数据,每组测试数据第一行是2个正整数n( 1...
阅读全文
摘要:DescriptionWhile skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University,noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits of that number was equal to the sum of the digits of the prime fact
阅读全文
浙公网安备 33010602011771号