随笔分类 -  南阳理工

摘要:View Code 1 #include<cstdio> 2 #include<cstdlib> 3 #include<iostream> 4 #include<queue> 5 #include<malloc.h> 6 #include<cstring> 7 #define N 100001 8 9 using namespace std;10 11 typedef struct city12 {13 int v;14 struct city *next;15 }City;16 17 City c[N];18 int n 阅读全文
posted @ 2012-05-15 22:21 zhongya 阅读(162) 评论(0) 推荐(0)
摘要:解题思路:1 如果图中所有的点连通且度都为偶数则可以一笔画成。 2 如果图中有不超过2个点的度为奇数则可以一笔画。 3做法显然先通DFS判断图是否连通过,然后在判断图中奇数点度的个数即可。 View Code 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<iostream> 5 #define N 1010 6 7 using namespace std; 8 9 int G[N][N], vis[N], num[N];10 int P, Q, ok;1 阅读全文
posted @ 2012-04-25 22:25 zhongya 阅读(181) 评论(0) 推荐(0)
摘要:View Code 1 #include<cstdio> 2 #include<cstdlib> 3 #include<queue> 4 #include<iostream> 5 #include<cstring> 6 7 using namespace std; 8 9 typedef struct 10 { 11 int x, y; 12 int step; 13 }Point; 14 15 priority_queue<Point> q; 16 bool operator<(Point a, Point b) 阅读全文
posted @ 2012-04-24 21:18 zhongya 阅读(152) 评论(0) 推荐(0)
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int c[10001],w[10001],f[10001]; 6 int main() 7 { 8 int i, j, n, v; 9 10 while(scanf("%d%d",&n,&v)&&n&&v)11 {12 memset(f,0,sizeof(f)); 13 for(i=0; i<n; i++)14 ... 阅读全文
posted @ 2012-03-30 22:41 zhongya 阅读(143) 评论(0) 推荐(0)
摘要:看了两个多小时的01背包问题,这是做出来的第一道,Happy~!提议可以这样来理解,要求邮票的分值之差最小,就是邮票分成两堆即两个容器,而每张邮票只有选和不选两种状态,所以只要求出每个容器的最大装载量即可,这样就转化为01背包问题了。这和zb的生日那道题一样只要代码稍作休改就能过。score[j]代表的是容量为j的容器所能装载邮票的最大分值。得出递推关系式:score[j] = score[j] > score[j-a[i]]+a[i] ? score[j] : score[j-a[i]]+a[i];其中a[i]是第i个邮票的分值View Code 1 #include<stdio 阅读全文
posted @ 2012-03-30 22:10 zhongya 阅读(525) 评论(0) 推荐(0)
摘要:此题是数字三角形的变形,有些细节要注意,当KK走倒最后一列是只能向下走,当KK走到最后一行时,只能向右走;这两种情况要单独考虑。d[i][j]指在i,j这个位置走到右下角所能吃的虫子数目。View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int main() 6 { 7 int i,j,N,M; 8 int a[25][25],d[25][25]; 9 10 scanf("%d%d",&N,&M);11 for(i=1; 阅读全文
posted @ 2012-03-29 14:58 zhongya 阅读(283) 评论(0) 推荐(0)
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 int i, j, ncases, n; 7 int a,b,sum; 8 scanf("%d",&ncases); 9 while( ncases-- )10 {11 b=-1, sum = -9999; //其中的值会有负数,所以b,sum要先设负值12 scanf("%d",&n); 13 for(i=1; i<=n; i++)14 ... 阅读全文
posted @ 2012-03-23 22:52 zhongya 阅读(176) 评论(0) 推荐(0)
摘要:题目的本质就是叫你求图中连通分支的数目。 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 5 int dx[4] = {1,-1, 0, 0}; 6 int dy[4] = {0, 0,-1, 1}; 7 int map[101][101]; 8 int visit[101][101],num,col,row; 9 10 void DFS(int x,int y)//求出图中所有的连通分支简单DFS遍历11 {12 int i, j, x1, y1;13 if(visit[x][ 阅读全文
posted @ 2012-03-16 21:40 zhongya 阅读(165) 评论(0) 推荐(1)
摘要:1 #include<stdio.h> 2 #include<math.h> 3 4 int w[25], min, ncases, total, i; 5 void dfs(int cur, int sum, int a[]) 6 { 7 int t; 8 if(cur == ncases) return ; 9 t =(int)fabs(total-sum-sum);10 if(t < min) min = t;11 dfs(cur+1, sum, a);12 dfs(cur+1, sum+a[cur], a);13 } 14 15 in... 阅读全文
posted @ 2012-03-07 22:29 zhongya 阅读(221) 评论(0) 推荐(1)
摘要:1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<queue> 6 7 using namespace std; 8 9 int dx[4] = {1,-1, 0, 0};10 int dy[4] = {0, 0, 1,-1};11 int visit[9][9];12 int map[9][9] = {{1,1,1,1,1,1,1,1,1},{1,0,0,1,0,0,1,0,1},{1,0,0,1,1, 阅读全文
posted @ 2012-03-04 22:28 zhongya 阅读(167) 评论(0) 推荐(1)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int main() 6 { 7 int i, T, length_a, length_b, j, k; 8 char a[1000], b[1000],c[1000]; 9 scanf("%d", &T);10 for (i=0; i<T; i++)11 {12 scanf("%s%s",a,b);13 length_a = strlen(a);14 length_b = 阅读全文
posted @ 2011-12-18 23:25 zhongya 阅读(119) 评论(0) 推荐(0)
摘要:1 #include<stdio.h> 2 #include<math.h> 3 int Prime(int x) 4 { 5 int i=2, flag=1; 6 if(x==1) return 0; 7 while(i<=sqrt(x)) 8 { 9 if(x%i == 0) flag = 0;10 i++;11 }12 return flag;13 }14 15 int main()16 {17 int ncases,m,i,j,distl,distr,temp1,temp2;18 scanf("%d", &ncases);19 阅读全文
posted @ 2011-12-17 22:15 zhongya 阅读(190) 评论(2) 推荐(1)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 5 int prime(int x) 6 { 7 int i, flag=1; 8 for(i=2; i<=sqrt(x); i++) 9 {10 if(x%i == 0) flag=0;11 } 12 return flag; 13 } 14 15 int main()16 {17 int ncases, n, i, m, sum;18 19 scanf("%d",&ncases);20 for(i= 阅读全文
posted @ 2011-12-16 11:59 zhongya 阅读(196) 评论(1) 推荐(1)