摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=274 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int n; 6 double m,pi=3.1415926; 7 scanf("%d",&n); 8 while(n--) 9 {10 scanf("%lf",&m);11 printf("%.2lf\n",(pi*m*m)/3.0);12 }13 //system
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=273 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 int main() 5 { 6 char a[205]; 7 int n,m,i,count; 8 scanf("%d",&n); 9 while(n--)10 {11 count=0;12 scanf("%s",a);13 m=strlen(a);14 ...
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=32 1 #include<stdio.h> 2 #include<string.h> 3 int n,m; 4 int ok[15];// 5 int num[15];//存放 6 int ac[15];//标记 7 void f(int l) 8 { 9 int a,b;10 if(l==m)11 {12 for(a=0;a<m;a++)13 printf("%d",num[a]);14 printf("\n...
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=366方法;用next_permutation(pɝmjʊ'teʃə)来求解,递归调用代码 1 #include<stdio.h> 2 #include<algorithm> 3 using namespace std; 4 int main() 5 { 6 int a[]={1,2,3,4,5,6,7,8,9}; 7 int k,n,i; 8 scanf("%d",&k); 9 while(k--)10 {11 scanf(&qu
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=469题目大意:给你一个正整数n,序列1,2,3,4,5......n满足以下情况的排列:1、第一个数必须是12、相邻两个数之差不大于2你的任务是给出排列的种数。题目分析:由于第一个只能是1,则第二个数只能是2,3当第二个数是2时,则相当于是对2-n的排列,相当于对1-(n-1)的排列,即s[n-1];当第二个数是3时,第三个数只能是2,4,5此时,当第三个数为2时,则是对3-n的排列,相当于对1-(n-3)的排列,即s[n-3] 当第三个数为4时,此时,第四个数只能是2,除了n等于4时..
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=19算法分析:暴力排列,递归,不太懂 1 #include<stdio.h> 2 int n,a[10]; 3 bool vis[10];//标示数字是否被用过 4 void f(int k,int m)//k用来给a中第k个元素赋值,m表示还需要寻找的数字个数 5 { 6 for(int i=1;i<=n;++i) 7 { 8 if(!vis[i]) a[k]=i; //未被标记赋值 9 else continue;...
阅读全文
摘要:同余定理(a+b)mod m=((a mod m)+(b mod m))mod m;a*b mod m=(a mod m)*(b mod m) mod m;a^b mod m=(a mod m)^b mod m; 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 char num[1000010]; 5 int main() 6 { 7 long int i; 8 int n,temp,t; 9 scanf("%d",&n);10 while(n--)1
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=267 1 //本题是nyoj35与nyoj257的综合 2 #include<stdio.h> 3 #include<stdlib.h> 4 #define N 1010 5 char s[N]; 6 int i; 7 //字符栈的操作 8 typedef struct 9 { 10 char *base; 11 char *top; 12 }SqStack1; 13 int InitStack1(SqStack1 &S) 14 { 15 S.base=(c
阅读全文
摘要:同中缀式转化到后缀式地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=257 1 #include<stdio.h> 2 #include<stdlib.h> 3 #define N 1010 4 //字符栈的操作 5 typedef struct 6 { 7 char *base; 8 char *top; 9 }SqStack; 10 int InitStack(SqStack &S) 11 { 12 S.base=(char *)malloc(N*sizeof(char)); 13 if(!S.bas.
阅读全文
摘要:考虑到1-100的最小公倍数肯定超出__int64.所以需要转化成字符串问题来解仔细观察会发现,【1-n】的最小公倍数,是【1-n-1】的最小公倍数乘以n的所有素因子中没有被【1-n-1】包含的素因子。例如:【1-7】的最小公倍数是2*3*2*5*7,8=2*2*2,(8中2出现3次,【1-7】的素因子中只出现2次)那么【1-8】就是2*3*2*5*7*2 1 //我的代码: 2 #include<stdio.h> 3 #include<string.h> 4 #define N 50 5 int len,a[N]={1}; 6 char tab[100][45]={0
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=325题意:有n个西瓜(n<=20),每个西瓜有一定的重量(w<=10000),将它们分成两堆,问如何使两堆重量之差最小。解题思路:还是看成容量为 sum/2 的背包问题,用搜索枚举所有情况,使背包中的重量尽量大。如此可得到最优解。搜索的效率取决于剪枝。而剪枝一般有两种,可行性剪枝与最优性剪枝。可行性:如果将物品装入背包后,费用超过容量,则不将它放入背包。最优性:1、如果背包已经装满,则不再考虑其他情况。2、如果背包中已有物品加上现有可选物品的总重量都不大于已知的最优解,则剪枝。
阅读全文
摘要:题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=322如果按冒泡排序这些O(n^2)肯定会超时,所以需要找一种更快的方法 --------归并排序。归并排序是建立在归并操作上的一种有效的排序算法。该算法是采用分治法的一个非常典型的应用。将已有序的子序列合并,得到完全有序的序列;即先使每个子序列有序,再使子序列段间有序。若将两个有序表合并成一个有序表,称为2-路归并。这题还可以用树状数组来做 1 法一:用归并排序做 2 #include<stdio.h> 3 int a[1000001],b[1000001]; /*合并排序
阅读全文
摘要:1 #include<stdio.h> 2 int a[1010]; 3 int main() 4 { 5 int i,j,n,t,tmp; 6 while(scanf("%d",&n)!=EOF) 7 { 8 for(i=0;i<n;i++) 9 scanf("%d",a+i);10 for(i=0,t=0;i<=n-1;i++)11 for(j=i+1;j<=n-1;j++)12 if(a[i]>a[j])13 {14 ...
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=163字典树的应用。。。如果字符串Xn=X1X2....Xn是字符串Ym=Y1Y2....Ym的前缀,有在插入的时候有两种情况:Xn在Yn之前插入,Xn在Yn之后插入。(1)如果Xn在Yn之前插入,那么在插入Yn的时候必然经过Xn的路径,此时可以根据判断在这条路径上是否已经有结点被标记已经构成完成的字符串序列来判断是否存在Yn的前缀;(2)如果Xn在Yn之后插入,那么插入完成之后当前指针指向的结点的next数组中的元素必定不全为NULL。 1 #include<cstdio> 2
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 int main() 5 { 6 int n,m,i,t ,s,w;; 7 char str[10]; 8 scanf("%d",&n); 9 while(n--)10 {11 scanf("%d",&m);12 s = 0; w = 1; i= 0;13 while(m--)14 {15 scanf("%s",&str);16 ...
阅读全文
摘要:题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=290经典的字典树的问题,代码几乎可以来当模版来用了,就留下来了~~~,不过貌似用运算符重载排序(不知道是不是)也能过。。。。。。。。需要注意的是开辟一个新的内存时下一个指针一定要指向NULL; 1 #include<cstring> 2 #include<cstdio> 3 #include<iostream> 4 using namespace std; 5 struct node{ 6 node *next[26]; 7 int count; 8
阅读全文
摘要:这个方法超时了TimeLimitExceeded,看来只能用二分查找了,即折半查找法,因为数据太大了,要输出太多的数。。。。你懂的。。。。地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=86 1 #include<stdio.h> 2 #include<stdlib.h> 3 #define max 1000010 4 int a[max],b; 5 int cmp(const void *x,const void *y) 6 { 7 return *(int*)x-*(int*)y; 8 } 9 int main
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=106这道题典型的应用贪心算法。不过有些不同的是这个题目已经告诉你单位价值了,所以我们不需要考虑计算单位价值最高的,从高到低的选择了。我们现在所需要做的就是对单位价值进行排序,然后从高到底取物品,直到重量达到题目中告诉的背包的W。想明白之后,思路也就很清晰了。sort排序,结构体或者二维数组进行储存数据。最后执行计算价值和·······不过这个题目中值得留意就是那个对结构体数据的交换,没有单独定义一个变量,而是用结构体中最
阅读全文
摘要:考查点:简单计算题思路:一直加撒,直到大于等于那个数即可,注意控制下循环变量即可.>提交情况:没的说的,肯定直接AC.> 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int i; 6 double a,sum; 7 while(scanf("%lf",&a),a) 8 { 9 i=1;10 sum=0;11 while(i++)12 {13 sum+=1.0/i;14 i...
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int t,n,i; 6 scanf("%d",&t); 7 while(t--) 8 { 9 i=0;10 scanf("%d",&n);11 while(n)12 {13 n/=5; //看有多少个5的因子,就有多少个0,具体看知识补充14 i+=n; 15 }16 printf("%d\...
阅读全文