随笔分类 - 算法入门
摘要:/*Agri-NetTime Limit: 1000MS Memory Limit: 10000K Total Submissions: 29678 Accepted: 11767 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. Farmer John ord...
阅读全文
摘要:/*周期串的求法如果字符串可以由某个字符串重复多次得到,我们说该串以k为周期.输入长度不超过80的串,求最小周期.*/#include<iostream>#include<string.h>using namespace std;int main(){ char word[100]; scanf("%s",word); int len =strlen(word); for(int i=1;i<len;i++)if(len%i==0) { int ok=1; for(int j=i;j<len;j++) if(wor...
阅读全文
摘要:/*GCommando WarInput: Standard InputOutput: Standard Output“Waiting for orders we held in the wood, word from the front never cameBy evening the sound of the gunfire was miles awayAh softly we moved through the shadows, slip away through the treesCrossing their lines in the mists in the fields on ou
阅读全文
摘要:#pragma warning (disable:4786) #include<cstdio>#include<iostream>#include<string>#include<string.h>#include<set>using namespace std;int main(){ set<string> st; string s=""; char c; while((c=getchar())!='#') { s+=c; while(c!='\n') { while(
阅读全文
摘要:#pragma warning (disable:4786) #include <map>#include <string>#include <iostream>using namespace std;int main(){ map<int, string> mapStudent; mapStudent.insert(pair<int, string>(1, "student_one")); mapStudent.insert(pair<int, string>(2, "student_two
阅读全文
摘要:/*Problem D Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 21 Accepted Submission(s) : 3Problem Description 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。是否AC的规则如下:1. zoj能AC;2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空;3. 若azbjc 能
阅读全文
摘要:Input 输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。当m为0时输入结束。 Output 输出格式:每个测试用例的输出占一行,输出A+B的m进制数。 Sample Input8 1300 482 1 70 Sample Output25041000*/#include<iostream>using namespace std;int main(){ int c[20]={0},n,a,b; while(scanf("%d",&n),n) { int i=0; scanf("%d%d",&a,&
阅读全文
摘要:/*Problem A Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 8 Accepted Submission(s) : 6Problem Description 读入两个小于100的正整数A和B,计算A+B.需要注意的是:A和B的每一位数字由对应的英文单词给出. Input 测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出
阅读全文
摘要:/*Problem C Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 1 Accepted Submission(s) : 1Problem Description 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。现在请计算A+B的结果,并以正常形式输出。 Input 输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。 Output 请计
阅读全文
摘要:/*猜想对于任意大于1的自然数n,若n为奇数,则将n变为3n+1,否则将n变为一半,求变换的次数 其中n<10^9开始不用长整形的时候会溢出,但是还可以用double解决这个问题刘汝佳教我的*//*//法1 长整形法#include<iostream>#include<math.h>using namespace std;int main(){ __int64 n,count = 0; while(scanf("%I64d",&n)!=EOF) { while(n>1) { if(n%2==1) ...
阅读全文
摘要:/*最长回文子串*/#include<iostream>#include<string.h>#include<ctype.h>using namespace std;#define Max 5000 +10char buf[Max],s[Max];int p[Max];int main(){ int n,m=0,max=0; int i,j; //int k; int x,y; fgets(buf,sizeof(s),stdin); n=strlen(buf); for(i=0;i<n;i++) if(isalpha(buf[i])) ...
阅读全文
摘要:/*不用数组也行,scanf返回成功输入变量的个数,按回车+ctrl+z+回车*/#include<iostream>using namespace std;int main(){ int x,n=0,min,max,s=0; scanf("%d",&x); s=min=max=x; n=1; while(scanf("%d",&x)==1) { s+=x; if(x<min)min=x; if(x>max)max=x; n++; } printf("%d %d %.3lf\n",min,m..
阅读全文