2012年2月26日

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 阅读(190) 评论(0) 推荐(0) 编辑

2012年2月25日

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 阅读(596) 评论(0) 推荐(0) 编辑

2012年2月24日

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 阅读(379) 评论(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 阅读(299) 评论(0) 推荐(0) 编辑

2012年2月23日

用位来代替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 阅读(848) 评论(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 阅读(373) 评论(0) 推荐(0) 编辑

2012年2月22日

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 阅读(199) 评论(0) 推荐(0) 编辑

2012年2月21日

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 阅读(166) 评论(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 阅读(262) 评论(0) 推荐(0) 编辑

2012年2月20日

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 阅读(318) 评论(0) 推荐(0) 编辑

2012年2月19日

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 阅读(309) 评论(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 阅读(314) 评论(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 阅读(314) 评论(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 阅读(271) 评论(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 阅读(368) 评论(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 阅读(200) 评论(0) 推荐(0) 编辑

2012年2月18日

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 阅读(240) 评论(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 阅读(194) 评论(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 阅读(280) 评论(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 阅读(328) 评论(0) 推荐(0) 编辑

导航