上一页 1 2 3 4 5 6 7 ··· 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 阅读全文
posted @ 2012-08-17 08:17 zhongya 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 刚开始题意理解错了,好吧!无情的奉献了一次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;... 阅读全文
posted @ 2012-08-17 08:11 zhongya 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 一开始的想法很简单,本想求出所有直线的交点,然后判断;结果一开数据量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 阅读全文
posted @ 2012-08-16 11:11 zhongya 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 比赛时看着题的太长了,加上又全是英文(英语不太好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 . 阅读全文
posted @ 2012-08-16 11:04 zhongya 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 刚开始用的多重背包写的结果果然超时,后来用别人告诉我的把它用二进制压缩一下,这里附上资料:解题思路:题目给价值为1~6的六种大理石的个数若干,要求我们判断是否能够把石头平分成相等的价值。我的思路是这样的:将大理石的重量看成和价值相等,那么总容量等于总价值数sum,那么如果总容量为sum/2时能装的最大价值也为sum/2,那么说明能拆分也两份相等的价值。注意:此题用背包要压缩,否则会超时。背包九讲的第三讲中提到了压缩方法,我贴出来:P03:多重背包问题每种物品有一个固定的次数上限题目有N种物品和一个容量为V的背包。第i种物品最多有n[i]件可用,每件费用是c[i],价值是w[i]。求解将哪些物品 阅读全文
posted @ 2012-08-15 15:26 zhongya 阅读(270) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int main() 6 { 7 int i,j,k,ncases,n,m,num[110]; 8 int value[110],weight[110],f[110]; 9 10 scanf("%d",&ncases);11 while( ncases-- )12 {13 scanf("%d%d",&n,&m); 14 for(i=1; i< 阅读全文
posted @ 2012-08-13 17:20 zhongya 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 简化的动态规划方程:for i=1..N for v=0..V f[v]=max{f[v],f[v-c[i]]+w[i]}View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define m 200000000 5 6 int main() 7 { 8 int i,j,v,ncases,f[10005]; 9 int empty,full,V,N,P[505],W[505];10 11 scanf("%d",&ncases);12 w 阅读全文
posted @ 2012-08-13 17:19 zhongya 阅读(115) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int main() 6 { 7 int i,j,N,V,v,ncases; 8 int f[1005],c[1005],w[1005]; 9 10 scanf("%d",&ncases);11 12 while( ncases-- )13 {14 scanf("%d%d",&N,&V);15 for(i=1; i<=N; i++)16 s 阅读全文
posted @ 2012-08-13 17:17 zhongya 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 刚看到这题时本想着拿它来练习下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 阅读全文
posted @ 2012-08-10 18:55 zhongya 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 弄两个数组a,b,将a数组复制到b,先把b排序,然后从依次减去b数组的数值,小于0的不能走,看指针是否能从1到达n,当第一个满足条件得数出现时即为听别人说此题也可用动态规划,不过我没想出来。。。T_T.....View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 6 int cmp(const void *a,const void *b) 7 { 8 return *(int *)a - *(int *)b; 9 }10 11 int main()12 {13 阅读全文
posted @ 2012-08-10 11:06 zhongya 阅读(193) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 16 下一页