随笔分类 - ZOJ
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 6 int ascore, bscore; 7 8 int DFS(int m, int n, int p) 9 {10 if(ascore == 1) return 0; 11 if(m==1 && n==1)12 {13 bscore = 1;14 ascore = 1;15 return 0; 16 } ...
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 6 char a[5002],b[4]="NOP"; 7 8 int ok(int l) 9 {10 int i, j;11 for(i = 0; i < (l+1)/2; i++) 12 {13 for(j = 0; j <= i; j++) 14 {15 if(a[l-i+j] != a[l-2*i+j-1])16 ...
阅读全文
摘要:咋一看此题有点不知所措,后来看了别人的题解,感悟良多用你自己的四轮现在草稿纸上画画,边入栈边匹配,匹配则出栈,不匹配则入栈,如此下去。。。View Code 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<stack> 6 #include<iostream> 7 #include<string> 8 9 using namespace std;10 11 int i,j,k,ans;
阅读全文
摘要:题意是求七段数码管的显示,可将显示分为五个部分,垂直方向三个,水平方向两个;最后再求五个部分的组合。。。。好麻烦呐,不过思路简单,可能模拟题都这样吧。。。。View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 6 void printv1(int s,int a) 7 { 8 int i; 9 printf(" "); 10 switch(a) 11 { 12 case 1: case 4: 13
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<math.h> 5 6 7 int main() 8 { 9 int i, t, j, m, ncases;10 int num, k, flag,a[18];11 12 while(scanf("%d",&num) != EOF)13 {14 if(num == 0) break;15 flag = 0;16 for(i=2; i<=16; ...
阅读全文
摘要:比赛时这道题没做出来,后来在网上搜了一种简单的方法,把0,1,2,。。。。20,30,。。90存到一个数组里,n1,n2,n3代表每三位的数,刚开始自动匹配,n3开始计算,遇到million,thousand,hundred,再乘以10^n最后把n1,n2,n3加在一起就是所求结果。View Code 1 #include<stdlib.h> 2 #include<stdio.h> 3 #include<string.h> 4 5 char str[28][15]={"zero", "one", "two&q
阅读全文
摘要:刚开始题意理解错了,好吧!无情的奉献了一次WA,去网上搜了下,这才把题意完全弄明白,N个人站成一排,每次奇数位或是偶数位出列,直到最后剩下的数的个数小于等于3,求总共有多少种方法View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int find(int n) 5 { 6 if(n < 3 ) return 0; 7 else if(n == 3) return 1; 8 else 9 {10 if(n%2 == 0) 11 return find(n/2)*2;...
阅读全文
摘要:一开始的想法很简单,本想求出所有直线的交点,然后判断;结果一开数据量10000,超时啊!好吧,用了逆序对。将每条直线与L和R的的交点求出,分别放在结构体数组的P的下,x和y中,然后根据题意就是求线段的交点个数,也就是求结构体数组的逆序对的个数。View Code 1 #include<stdio.h> 2 #include<math.h> 3 #include<stdlib.h> 4 #define N 10001 5 6 typedef struct 7 { 8 double x,y; 9 }Node;10 Node p[N]; 11 long long
阅读全文
摘要:比赛时看着题的太长了,加上又全是英文(英语不太好T_T.....)题意没理解,就放弃了,后来听说是求他的最长上升子序列,我勒个去啊!一个简单的DP搞这么麻烦的题目。。。。要用O(n*logn)方法过。。。。View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define N 40005 5 6 int stack[N]; 7 int main() 8 { 9 int i,temp,ncases;10 int top,n,low,mid,high; 11 12 .
阅读全文
摘要:刚开始用的多重背包写的结果果然超时,后来用别人告诉我的把它用二进制压缩一下,这里附上资料:解题思路:题目给价值为1~6的六种大理石的个数若干,要求我们判断是否能够把石头平分成相等的价值。我的思路是这样的:将大理石的重量看成和价值相等,那么总容量等于总价值数sum,那么如果总容量为sum/2时能装的最大价值也为sum/2,那么说明能拆分也两份相等的价值。注意:此题用背包要压缩,否则会超时。背包九讲的第三讲中提到了压缩方法,我贴出来:P03:多重背包问题每种物品有一个固定的次数上限题目有N种物品和一个容量为V的背包。第i种物品最多有n[i]件可用,每件费用是c[i],价值是w[i]。求解将哪些物品
阅读全文
摘要:刚看到这题时本想着拿它来练习下DFS来着可是被坑了一下午让我与苦无泪,回来检查代码时,发现自己吧0这个特殊的数忘记考虑了,T_T。。。。思路:用DFS搜索出所有可能的情况然后打表输出。View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define N 1000005 5 6 int fac[11] = {0,1,1,2,6,24,120,720,5040,40320,362880};//这里数组要注意。。fac[0] = 0,fac[1]代表了0的阶乘,fac
阅读全文
摘要:题意叫你求交叉点的个数,转换一下思维,把第一个数看作是i,和它相连接的第二个数看作是ai,当i < j 且 ai > aj时这时才有交叉点,这样就转换为求逆序对的个数;首先,把他x从小到大排序,x相同的按y从大到小排序,排完序后,在使用合并排序,计算逆序对的个数。View Code 1 #include<stdio.h>//从网上搜的都是用树状数组解的,这个我暂时还不会,等以后学了在看吧。 2 #include<stdlib.h> 3 #define MAX 1000005 4 5 typedef struct NODE 6 { 7 int x,y; 8 }
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define N 500000 5 6 int a[N],b[N]; 7 long long count; 8 void mergearray(int a[], int first, int mid, int last, int temp[]) 9 { 10 int i = first, j = mid + 1; 11 int m = mid, n = last; 12 int k = 0; 13 ...
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 从第一种开始搜索,搜索完毕后回溯,搜索下一个 4 int n,m,count,sum,val[11],num[11]; 5 void DFS(int x) 6 { 7 int i; 8 if(sum == n) 9 {10 count++; 11 return ;12 }13 if(sum > n || x > m) 14 return ; 15 for(i=1; i<=num[x]...
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 char s1[1001],s2[1001]; 6 int cmp (const void *a,const void *b) 7 { 8 if( *(char*)a < *(char *)b ) 9 return 1;10 return -1;11 }12 13 int main()14 {15 int i,j,k,len;16 17 while(scanf("%s",s1)...
阅读全文
摘要:View Code 1 #include<stdio.h>//二分搜索技术运用。此题在排序后应用减法从右往左。 2 #include<stdlib.h> 3 #include<string.h> 4 5 int a[1001],i,j,k,ncases; 6 int search(int num,int from,int end) 7 { 8 int mid; 9 while(from <= end) 10 { 11 mid = (from+end)/2; 12 if(num == a[mid])13 return...
阅读全文
摘要:思路很简单,给你n个数和一个sum要求从n个数中选出所有加和为sum的数值串:肯定是先用DFS找出所有的情况然后再删掉重复的;这里我从课件里学到一种判断重复的方法,把核心代码附上:void findSum (int sum, int iEnd, int numSkipped) { if (iEnd == listlength) return; int newsum = sum - list[iEnd]; //取第iEnd个数 if ((numSkipped != list[iEnd])&&(newsum >= 0)) { used[iEnd] = 1; //标记第iEnd
阅读全文
摘要:求周长,一开不知道怎么求,最后钻到POJ讨论区内,看到一种方法,就是‘X"周围全换成0,最后只要求0的个数就好了嗯,这种方法真好,反正我们想起来,膜拜啊!这题过了从网上搜了下发现可以用BFS做,想想也是,本身用那一种都行View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 #include<ctype.h> 6 7 int map[25][25],f[25][25],visit[25][25],
阅读全文
摘要:View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 #include<ctype.h> 6 7 char map[101][101]; 8 int visit[101][101],m,n; 9 int dx[] = {0,1,-1, 0,1, 1,-1,-1}; 10 int dy[] = {1,0, 0,-1,1,-1,-1, 1};11 12 void DFS(int x,int y)13 {14
阅读全文
摘要:一开始做图形遍历的题都是用链表做的,这次用数组体会到了方便但就是有点浪费。不过题目给的内存限制已经足够了。View Code 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<queue> 5 #include<iostream> 6 7 using namespace std; 8 9 typedef struct10 {11 int v;12 int step; 13 }Point;14 Point P[21];15 int visit[21
阅读全文

浙公网安备 33010602011771号