02 2012 档案

魔方阵
摘要:群里的朋友问了这道题,刚开始想到的最笨了:枚举,然后就是判断,要是n过大了就。。。。后来参考百度百科给出的分类考虑的方法,尝试了一下,感觉按照方法来一点也不复杂了。。不过百度百科也提到了一种通用的方法,没有尝试。#include<stdio.h># define MAXN 100int a[MAXN][MAXN];void swap(int *x, int *y){ int tmp; tmp = *x; *x = *y; *y = tmp;}void print_odd(int n){ int i, j, t; i = 1; j = (n+1)/2; ... 阅读全文

posted @ 2012-02-29 17:56 getgoing 阅读(271) 评论(0) 推荐(0)

WA:csu1108 Flip Game
摘要:在POJ上提交用的是枚举,刚学了bfs各种混乱,WA了# include <stdio.h># include <string.h> # define MAX 65536 # define INDEX(i) ((i)>>3)# define OFFSET(i) ((i)%8) # define GET_BIT(i) (vis[INDEX(i)]>>OFFSET(i) & 0x1)# define SET_BIT(i) (vis[INDEX(i)] |= 0X1<<OFFSET(i)) char vis[INDEX(MAX)+1 阅读全文

posted @ 2012-02-29 11:59 getgoing 阅读(567) 评论(0) 推荐(0)

[转载]POJ 分类
摘要:转载自:HUJJ, http://www.cnblogs.com/hujj/archive/2012/02/11/2346539.html初期:一.基本算法:(1)枚举.(poj1753,poj2965)(2)贪心(poj1328,poj2109,poj2586)(3)递归和分治法.(4)递推.(5)构造法.(poj3295)(6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:(1)图的深度优先遍历和广度优先遍历.(2)最短路径算法(dijkstra,bellman-ford,floyd,heap+dijkstra)(poj1860,po 阅读全文

posted @ 2012-02-27 08:42 getgoing 阅读(211) 评论(0) 推荐(0)

TLE csu 1236: 删数游戏
摘要:直接做,TLE:View Code /* csu 1236 */# include <stdio.h># include <string.h># define MAXN 2001void del(char *s, int len){ int i; i = 1; while (i < len && s[i-1]<=s[i]) ++i; while (i < len) { s[i-1] = s[i]; ++i; } s[i-1] = '\0';}int main(){ int len, i, S; c... 阅读全文

posted @ 2012-02-26 16:43 getgoing 阅读(282) 评论(0) 推荐(0)

csu 1207: 镇管的难题
摘要:判断一个正整数是不是勾股数(直角边),初等数论。意外:奇数可以构造(2n+1, 2n^2+2n, 2n^2+2n+1),2^n(n>=2)也是(因为4是)。。/* csu 1207 */# include <stdio.h>int main(){ int x; while (~scanf("%d", &x)) if (x<3) printf("NO\n"); else printf("YES\n"); return 0;} 阅读全文

posted @ 2012-02-26 00:51 getgoing 阅读(200) 评论(0) 推荐(0)

csu 1233 病毒的复制
摘要:/* WA,对测试示例结果正确,不解 */已通过,原因是%I64d的使用不符合编译器的要求,百度了一下,这个问题早就有了……非常感谢Staginner大牛的帮助!变量定义输出方式gcc(mingw32)g++(mingw32)gcc(linux i386)g++(linux i386)MicrosoftVisual C++ 6.0long long“%lld”错误错误正确正确无法编译long long“%I64d”正确正确错误错误无法编译__int64“lld”错误错误无法编译无法编译错误__int64“%I64d”正确正确无法编译无法编译正确long longcout非C++正确非C++正确 阅读全文

posted @ 2012-02-25 00:39 getgoing 阅读(617) 评论(0) 推荐(0)

csu 1031 Parsing Real Numbers
摘要:先标记,然后分情况判断,最后一定要多做测试。略显麻烦。/* 1031: Parsing Real Numbers */# include <stdio.h># include <ctype.h># include <string.h># define BITSET(i) ((sign)|=(char)(0x1<<(i)))# define GETBIT(i) ((sign)>>(i) & (0x1))char a[1000];char sign;/* sign: 0 - wrong? 1 - coeff sign 2 - in 阅读全文

posted @ 2012-02-24 15:24 getgoing 阅读(394) 评论(0) 推荐(0)

MLE: 找出出现偶数次的那个数
摘要:位标记,MLE了/* csu 1069 changelong MLE */# include <stdio.h># define MAX 10000000# define INDEX(x) ((x)>>(3))# define OFFSET(x) ((x)%(8))# define GET_BIT(x) (vis[INDEX(x)]>>OFFSET(x) & 0x1)# define SET_BIT(x) (vis[INDEX(x)] |= (char)((0x1)<<OFFSET(x)))char vis[INDEX(MAX)+1]; 阅读全文

posted @ 2012-02-24 09:32 getgoing 阅读(311) 评论(0) 推荐(0)

用位来代替bool:减小内存使用,提高运行速度
摘要:素数槽问题Description 处于相邻的两个素数p和p + n之间的n - 1个连续的合数所组成的序列我们将其称为长度为n的素数槽。例如,‹24, 25, 26, 27, 28›是处于素数23和素数29之间的一个长度为6的素数槽。 你的任务就是写一个程序来计算包含整数k的素数槽的长度。如果k本身就是素数,那么认为包含k的素数槽的长度为0。Input第一行是一个数字n,表示需要测试的数据的个数。后面有n行,每行是一个正整数k, k大于1并且小于或等于的第十万个素数(也就是1299709)。Output对于输入部分输入的每一个k,都对应输出一个非负整数,表示包含k的素数槽的长度,每个非负整数占 阅读全文

posted @ 2012-02-23 20:19 getgoing 阅读(876) 评论(0) 推荐(0)

csu 1030 素数槽
摘要:筛法求素数,难点在怎样减少内存,使用C++中的bool却是RE/* 素数槽 C */# include <stdio.h># include <string.h>char a[1299710]; // 有点不伦不类。。。void init(void){ int i, j; memset(a, 0, sizeof(a)); for (i = 2; i < 1299710; ++i) { if (a[i]) continue; j = 2*i; while (j < 1299710) { a... 阅读全文

posted @ 2012-02-23 11:41 getgoing 阅读(385) 评论(0) 推荐(0)

csu 1079
摘要:排序# include <stdio.h>typedef struct record{ float h, w; char name[50];} stu;int main(){ int N, i, j; stu st[50], tmp; //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); while (1) { scanf("%d", &N); if (N == 0) break; for (i 阅读全文

posted @ 2012-02-22 00:41 getgoing 阅读(209) 评论(0) 推荐(0)

POJ 1002 487-3279
摘要:/* POJ 1002 487-3279*/# include <stdio.h># include <stdlib.h># include <ctype.h>typedef struct TeleNum{ int num; int rpt; struct TeleNum *next;} tel;const int h[] = {2,2,2,3,3,3, 4,4,4,5,5,5, 6,6,6,7,0,7,7, 8,8,8,9,9,9,0 };int ... 阅读全文

posted @ 2012-02-21 17:40 getgoing 阅读(176) 评论(0) 推荐(0)

POJ 1001 Exponentiation
摘要:已经找到错误:10 100 330 这样10的倍数转换的不对# include <stdio.h># include <string.h>int main(){ int d, n, e, ans[150]; int i, j, tmp, c; char b[6];// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); while (scanf("%s%d", b, &e) != EO 阅读全文

posted @ 2012-02-21 11:23 getgoing 阅读(278) 评论(0) 推荐(0)

KMPmatch 字符串模式匹配
摘要:O(m+n)计算后缀数组时,子串进行的也是模式匹配。/* KMP match */# include <stdio.h># include <string.h># include <stdlib.h>/* P in T */int KMPmatch(char *T, char *P){ int n, m; int i, j, k, *next; n = strlen(T); m = strlen(P); next = (int *)malloc((m-1)*sizeof(int)); /* compute postfix : next[] */ nex... 阅读全文

posted @ 2012-02-20 21:39 getgoing 阅读(328) 评论(0) 推荐(0)

转载:ZOJ POJ 题目分类(lonelycatcher)
摘要:原文链接:http://www.cnblogs.com/lonelycatcher/archive/2011/08/17/2143552.html#ZOJ题目分类初学者题:1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889 1904 1915 1949 阅读全文

posted @ 2012-02-20 13:03 getgoing 阅读(226) 评论(0) 推荐(0)

UVaOj 494 Kindergarten Counting Game
摘要:复习了the C programming language 中的单词记数/*494 - Kindergarten Counting Game*/# include <stdio.h># include <ctype.h># define IN 1# define OUT 0int main(){ int ans,state; char ch; ans = 0; state = OUT; while ((ch=getchar()) != EOF) { if (!isalpha(ch) && ch!='\n') state =... 阅读全文

posted @ 2012-02-19 13:39 getgoing 阅读(326) 评论(0) 推荐(0)

UVaOJ458 - The Decoder
摘要:看出来了,ascll -7WA:/*458 - The Decoder*/# include <stdio.h>int main(){ char ch; while ((ch=getchar()) != EOF) if (ch != '\n') putchar((ch+121)%128); else putchar('\n'); return 0;}AC:/*458 - The Decoder*/# include <stdio.h>int main(){ char ch; while ((ch=getchar()) != EOF) .. 阅读全文

posted @ 2012-02-19 12:35 getgoing 阅读(323) 评论(0) 推荐(0)

UVaOJ 10300 Ecological Premium
摘要:理解错误:Do not output any blank lines.注意: No integer in the input is greater than 100000 or less than 0./*10300 - Ecological Premium*/# include <stdio.h>int main(){ int n, f; long long s, a, e, ans; scanf("%d", &n); while (n > 0) { ans = 0; scanf("%d", &f); while (. 阅读全文

posted @ 2012-02-19 11:18 getgoing 阅读(328) 评论(0) 推荐(0)

UVaOJ10071 - Back to High School Physics
摘要:初速度与加速度恒定,已知经 t 时间后速度为 v, 求经 2t 后位移为多少?/*10071 - Back to High School Physics*/# include <stdio.h>int main(){ int v0, t; while (scanf("%d%d", &v0, &t)!=EOF) printf("%d\n",2*v0*t); return 0;} 阅读全文

posted @ 2012-02-19 10:34 getgoing 阅读(279) 评论(0) 推荐(0)

UvaOJ10055 hashmat the brave warrior
摘要:3WA。。。/* UVa10055 Hashmat */# include <stdio.h>int main(){ unsigned long a, b; while (scanf("%ld%ld", &a, &b) != EOF) printf("%ld\n", (a<b ? b-a:a-b)); return 0;} 阅读全文

posted @ 2012-02-19 10:10 getgoing 阅读(377) 评论(0) 推荐(0)

poj 1753 flip game
摘要:直接枚举//2011-11-1#include <iostream>#include <cstdio>using namespace std;void Replace(char a[], int b[]);int Search(int a[]);bool Judge(int a[]);void Flip(int b[], int k);int main(){ char a[16], c; int b[16]; int i = 0; while ((c = getchar()) != EOF && i < 16) if (c == 'b 阅读全文

posted @ 2012-02-19 00:11 getgoing 阅读(214) 评论(0) 推荐(0)

zoj 2988
摘要:/* zoj 2988 */# include <stdio.h># include <string.h>int main(){ int n, i, len; double m; char ch[2]; scanf("%d", &n); i = 0; while (n > 0) { scanf("%lf %s", &m, ch); len = strlen(ch); if(len == 2) { if (ch[0] == 'k') printf(... 阅读全文

posted @ 2012-02-18 22:41 getgoing 阅读(252) 评论(0) 推荐(0)

zoj 2987
摘要:/* zoj 1987 */# include <stdio.h># include <string.h>int main(){ int T, len, i, k, cnt; char ch[1<<9]; cnt = 0; scanf("%d", &T); while (T > 0) { i = 0; scanf("%d %s", &k, ch); len = strlen(ch); printf("%d ", ++cnt); for (i = 0; i < len; + 阅读全文

posted @ 2012-02-18 22:39 getgoing 阅读(206) 评论(0) 推荐(0)

zoj 2132 the most frequent number
摘要:the most frequent numberCE: Gcc注释 用/**/MLE: 快排 取中位数/*zoj 2132 the most frequent number quick sort */# include <stdio.h># include <stdlib.h># define MAXN 250005int compare (const void * a, const void * b){ return ( *(int*)a - *(int*)b );}int main(){ int a[MAXN]; int L, i; while (scanf(&qu 阅读全文

posted @ 2012-02-18 21:18 getgoing 阅读(303) 评论(0) 推荐(0)

csu1022 菜鸟和大牛 dp
摘要:第一次做dp, 一次就ac了, 体验了一把大牛的感觉。。题目描述:一个由n行数字组成的三角形,第i行有2i-1个正整数(小于等于1000),如下: 3 7 1 4 2 4 3 6 28 5 2 9 3 6 2 要求你用笔从第1行画到第n(0 < n ≤ 100)行,从当前行往下画的时候只能在相邻的数字经过,也就是说,如果从一行的一个数往下画,只能选择其左下或者正下或者右下三个数中的一个(如果存在的话),把所有被画起来的数字相加,得到一个和,求能得到的最大的和的值是多少。上例中能得到的最大的和为3 + 7 + 4 + 9 = 23.// 1022 dp# include <stdio 阅读全文

posted @ 2012-02-18 10:30 getgoing 阅读(342) 评论(0) 推荐(0)

csu1217: 奇数个的那个数
摘要:给定些数字,这些数中只有一个数出现了奇数次,找出这个数。本来用了STL set,MLE了,改为手写式的set(链表),注意一点:插入操作与删除操作不会并存。别人的代码真短。。//1217# include <stdio.h># include <stdlib.h>typedef struct atom{ int key; struct atom *next;} atom; int main(){ int n, t; atom *set, *tmp, *x, *y; while (scanf("%d", &n)==1) { if (n > 阅读全文

posted @ 2012-02-17 22:24 getgoing 阅读(331) 评论(1) 推荐(1)

csu1003: UC Browser
摘要:循环周期为5天,只要知道连续的天数,就可以计算出经验值。// 1003 UC Browser# include <stdio.h># define MAXN 105short int expr[] = {0,1,3,6,10,15};int main(){ int T, n, tot, cnt, i; char a[MAXN]; scanf("%d", &T); while (T > 0) { scanf("%d%s", &n,a); tot = 0; for (i=0; i<n; ++i) { ... 阅读全文

posted @ 2012-02-17 22:10 getgoing 阅读(405) 评论(0) 推荐(0)

csu1212: 中位数
摘要:给出两个长为n的升序序列S1和S2,求两序列合并并排序后的中位数。1 <= n <= 10 ^ 5类似于merge sort的merge过程(可以省掉一个数组,边输入边计算)// 1212# include <stdio.h># define MAXN 100000int a[MAXN+2],b[MAXN+2];int main(){ int n, i, j, k, cnt; while (scanf("%d", &n)==1) { cnt = 0; for (i=0;i<n;++i) scanf("%d",& 阅读全文

posted @ 2012-02-17 22:06 getgoing 阅读(265) 评论(0) 推荐(0)

csu1021: 组合数末尾的零
摘要:C(m,n) =m!/((m-n)!n!)将组合数C(m,n)写成二进制数,这个二进制数末尾有多少个零?* 自然数可以进行质因数分解,质因子2的指数即相应二进制末尾零的个数; 将各个数二进制末尾0的个数累加,得到阶乘数末尾0的个数。优化:# include <stdio.h>int f[] = {0,1,3,7,15,31,63,127,255,511};int main(){ int T, m, n, i, ans; scanf("%d", &T); while (T-- > 0){ ans = 0; scanf("%d%d" 阅读全文

posted @ 2012-02-17 21:58 getgoing 阅读(593) 评论(0) 推荐(2)

STL set常用操作
摘要:// 使用占用空间可能会很大 iterator begin ( ); iterator end ( ); void clear ( );size_type count ( cont key_type& x ) const; bool empty ( ) const; void erase ( iterator position );size_type erase ( const key_type& x ); void erase ( iterator first, iterator last ); iterator find... 阅读全文

posted @ 2012-02-17 21:37 getgoing 阅读(373) 评论(0) 推荐(0)

PE: 行末不留空格 BST 插入与遍历
摘要:PE了一早上——就是因为行末空格的问题想过用链表在遍历过程中存储节点,然后打印;想过用静态变量保存;最后,回到了指针,传递计数器的地址。View Code //1005 BST 建树、遍历# include <stdio.h># include <stdlib.h>typedef struct Tnode{ int key; struct Tnode *left; struct Tnode *right;}node;node *BST_insert(node *root, node *p);void preorder(node *x, int *p);void inor 阅读全文

posted @ 2012-02-17 13:05 getgoing 阅读(269) 评论(0) 推荐(0)

C语言的一个关于类型的小陷阱
摘要:类型的差别造成奇怪的运行结果——输出错误、无法继续输入等新增:找出下面代码的错误:# include <stdio.h># include <string.h> # define MAXN 10005 int main(){ short m, n, i, ans, tmp, t[MAXN]; while (~scanf("%d%d", &n, &m)) { memset(t, 0, sizeof(t)); for (i = 1; i <= m; ++i) { scanf("%d", &tmp); .. 阅读全文

posted @ 2012-02-16 18:37 getgoing 阅读(316) 评论(0) 推荐(0)

csu1002 A+B(III)
摘要:RE 阅读全文

posted @ 2012-02-16 16:29 getgoing 阅读(460) 评论(0) 推荐(0)

bfs poj2965
摘要:TLE了 不知道怎么办 还是用枚举?// poj 2965 bfs & STL queue# include <iostream># include <cstring># include <queue>using namespace std;const unsigned short flip[] = {0x111f, 0x222f, 0x444f, 0x888f, 0x11f1, 0x22f2, 0x44f4, 0x88f8, 0x1f11, 0x2f22,... 阅读全文

posted @ 2012-02-16 00:07 getgoing 阅读(220) 评论(0) 推荐(0)

导航