随笔分类 -  ZOJ

摘要:1 仔细分析题目可得到当反射次数为奇数时光想从上面射出, 2 当反射次数为偶数时光线从下面射出。所以分奇数和偶数 3 两种情况考虑。 4 奇数:每个面的光线数目等于本平面上个反射点的光线数目; 5 偶数:每个面的光线树木等于本平面下面的那个反射点的数目; 6 所以有递推关系式可以得到L[i][j] += L[i-1][k];表示i个光线 7 反射的线路数目。 8 #include<stdio.h> 9 #include<string.h>10 11 long long L[60][4], sum;12 int main()13 {14 int i, j, k, n; 1 阅读全文
posted @ 2012-02-25 16:30 zhongya 阅读(178) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 int i, len; 7 long long num[5]; 8 char str[10002]; 9 while(scanf("%s",str) != EOF)10 {11 len = strlen(str);12 for(i=0; i<5; i++)13 num[i] = 0; 14 for(i=0; i<len; i++)15 {16 switc... 阅读全文
posted @ 2012-02-23 22:21 zhongya 阅读(151) 评论(0) 推荐(0)
摘要:1 在c++中qsort()排序函数的使用qsort函数应用大全 2 七种qsort排序方法 3 <本文中排序都是采用的从小到大排序> 4 一、对int类型数组排序 5 int num[100]; 6 Sample: 7 int cmp ( const void *a , const void *b ) 8 { 9 return *(int *)a - *(int *)b; 10 } 11 qsort(num,100,sizeof(num[0]),cmp); 12 二、对char类型数组排序(同int类型) 13 char word[100]; 14 ... 阅读全文
posted @ 2011-11-15 22:44 zhongya 阅读(528) 评论(0) 推荐(0)
摘要:1 int cost[Maxn][Maxn]; 2 int dist[Maxn], pre[Maxn];//初始化时一般先将cost[][]初始化为无穷大,pre[]存放结点前驱,s[]标记数组,标记S中走过的结点 3 void Dijkstra(int n) 4 { 5 int v,i,j,k,min,s[Maxn]; 6 v = n; 7 for(i=1; i<=n; i++) 8 { 9 dist[i] = cost[v][i]; 10 s[i] = 0;11 if (dist[i] < Ma... 阅读全文
posted @ 2011-11-08 14:54 zhongya 阅读(427) 评论(0) 推荐(1)
摘要:1 int dist[Max][Max], path[Max][Max], cost[Max][Max]; 2 void Floyd(int n) 3 { 4 int i, j, k; 5 for (i=1; i<=n; i++) 6 for (j=1; j<=n; j++) 7 { 8 dist[i][j] = cost[i][j]; 9 if(i!=j && dist[i][j]<Maxint) 10 path[i][j] = i;11 else 12 pa... 阅读全文
posted @ 2011-11-06 17:02 zhongya 阅读(169) 评论(0) 推荐(1)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define Maxint 9999999 5 #define Max 101 6 7 int main() 8 { 9 int M, N, hotel[101], a, C, b, t;10 int i, j, k, r, sum, dist[101][101];11 12 while (scanf("%d%d",&N, &C) != EOF)13 {14 for (i=1; i<=N; 阅读全文
posted @ 2011-11-06 16:54 zhongya 阅读(204) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define MAX 90000000 5 6 int count = 0; 7 char name[201][40]; 8 int find(char *a) //此函数实现将字符串转化为数字,剽窃党姐的呵呵>_< 9 { 10 int i; 11 for( i = 1; i <= count; i++ ) 12 if( strcmp(a,name[i]) == 0 ) 13 retur... 阅读全文
posted @ 2011-10-19 16:53 zhongya 阅读(310) 评论(0) 推荐(1)
摘要:1 #include<stdio.h> 2 #include <string.h> 3 4 int main() 5 { 6 int t=0, a, b, l, n, m, i, j, k, now, maxs, x, y; 7 int cost[501][501], dist[501], s[501]; 8 float time, temp; 9 10 while(scanf("%d%d", &n, &m), n) 11 { 12 for(a=1; a<=n; a++)... 阅读全文
posted @ 2011-10-16 18:12 zhongya 阅读(271) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 int ncases, i, j, k=1, n; 7 char a[16][30], b[16][30]; 8 9 while(scanf("%d", &ncases) != EOF)10 {11 if (ncases == 0) break;12 for (i=1; i<=ncases; i++) 13 {14 scanf("%s", a[i]); 15 }16 p... 阅读全文
posted @ 2011-09-24 22:30 zhongya 阅读(155) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 7 char s1[105], s2[105]; 8 9 while(scanf("%s%s", s1, s2) != EOF)10 { 11 int i, j,len1, len2, t=0, a[105]={0}; /*也可以写到外面*/ 12 len1 = strlen(s1);13 len2 = strlen(s2);14 for(i=0,j=0; i... 阅读全文
posted @ 2011-09-20 23:22 zhongya 阅读(203) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 int num[102], num2[102], low[102], high[102]; 5 int cmp(int x[], int y[])//判断函数用作判断超过区域范围。 6 { 7 int i, lenx, leny; 8 lenx = leny = 101; 9 while(x[lenx] == 0) 10 { 11 lenx--; 12 } 13 while(y[leny] == 0) 14 { 1... 阅读全文
posted @ 2011-09-17 21:02 zhongya 阅读(259) 评论(0) 推荐(0)
摘要:1 #include <stdio.h> 2 int main() 3 { 4 long x1, y1, x2, y2; 5 long x, y; 6 7 while(1) 8 { 9 scanf("%ld%ld",&x, &y); 10 if(x==0&&y==0) break;11 x1 = x; x2 = x;12 y1 = y; y2 = y;13 14 while(scanf("%ld%ld",&x,&y) != EOF)15 {... 阅读全文
posted @ 2011-09-09 18:59 zhongya 阅读(279) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 3 int main() 4 { 5 int i, n, a[101], t; 6 7 while(scanf("%d", &n) != EOF) 8 { 9 if(n == 0) break; 10 for(i=0; i<n; i++)11 {12 scanf("%d", &a[i]);13 }14 t = a[0]*6;15 for (i=1; i<n; i++)16 ... 阅读全文
posted @ 2011-09-08 14:24 zhongya 阅读(151) 评论(0) 推荐(1)
摘要:1 #include <stdio.h> 2 #include <math.h> 3 #include <string.h> 4 #include <stdlib.h> 5 6 int cmp(const void *a,const void *b) 7 { 8 return *(int *)a - *(int *)b; 9 }10 11 int main()12 {13 int i, n, a[3002], b[3002], count, k;14 15 while(scanf("%d", &n) != EOF)16 阅读全文
posted @ 2011-09-08 14:22 zhongya 阅读(162) 评论(0) 推荐(0)
摘要:1 #include <stdio.h> 2 3 int main() 4 { 5 long n, ncases, sum; 6 7 while(scanf("%ld", &ncases) != EOF) 8 { 9 while(ncases--)10 {11 sum = 0;12 scanf("%ld", &n); 13 while ( n/5 )14 {15 sum += n/5;16 ... 阅读全文
posted @ 2011-09-07 21:09 zhongya 阅读(145) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 int i, ncases, len, c[102]; 7 char a[100], b[100]; 8 9 while(scanf("%d", &ncases) != EOF)10 {11 12 while(ncases--)13 {14 memset(c,0,sizeof(c)); 15 ... 阅读全文
posted @ 2011-09-06 21:59 zhongya 阅读(214) 评论(0) 推荐(0)
摘要:1 大体思路是这样,由于括号必定是偶数,每一个P前面都有P个左括号 2 W就是与左括号到与它匹配的右括号之间右括号的个数。 3 可设立一个数组用W[21]于存放标记,初始化为0,从P处开始向前当有 4 匹配的右括号时就记录下来W[i]=1,最后P-i+1就是所要求的值。 5 6 #include <stdio.h> 7 #include <string.h> 8 9 int main()10 { 11 int i, n, ncases;12 int w[21], k, p;13 14 scanf("%d", &ncases); 15 whil 阅读全文
posted @ 2011-09-05 22:09 zhongya 阅读(231) 评论(0) 推荐(0)
摘要:1 #include <stdio.h> 2 #include <string.h> 3 #define N 100001 4 5 char s[N+10];//字符数组开大一点以免发生段错误 6 struct 7 { 8 int data[N+10]; 9 int top;10 }st; //建立一个数值栈用于存放字符的下标。 11 12 int match(int m,int n)//判断是否匹配13 {14 if (s[st.data[m]]=='('&& s[n]==')')15 return 1;16 if (s 阅读全文
posted @ 2011-09-05 21:17 zhongya 阅读(260) 评论(0) 推荐(0)
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<queue> 5 6 using namespace std; 7 8 queue<int>q; 9 int main() 10 { 11 int a, x, b, y; 12 int visit[9][9]; 13 char c1, c2, r1, r2; 14 15 while(cin>>c1>>r1>>c2>>r2) 16 { 17 mems 阅读全文
posted @ 2011-08-29 22:47 zhongya 阅读(362) 评论(0) 推荐(0)
摘要:1 先灌满A和先灌满B效果一样。 2 #include<stdio.h> 3 4 int main() 5 { 6 int ca, cb, n, i; 7 while(scanf("%d%d%d",&ca,&cb,&n) != EOF) 8 { 9 if(ca==1)//做一个判断,为1时直接灌n次即可10 {11 for(i=1; i<=n; i++)12 {13 printf("fill A\n");14 printf(... 阅读全文
posted @ 2011-08-25 17:03 zhongya 阅读(204) 评论(0) 推荐(0)