2011年7月20日

gdb 调试程序

摘要: gdb是个强大的调试 器,功能 非常 强大。在linux下,先用vim 写一个c语言文件。。 1 #include <stdio.h> 2 3 int fun( int x , int i) 4 { 5 if ( i == 0 ) 6 return 1; 7 else if (i == 1) 8 return x; 9 else 10 return x * fun ( x , i -1 );11 12 }13 14 int main( )15 {16 int N, t;17 scanf("%d", &N);18 t = fun ( N, 5);19 pr 阅读全文

posted @ 2011-07-20 12:28 more think, more gains 阅读(269) 评论(0) 推荐(1) 编辑

phone list

摘要: #include <stdio.h>#include <string.h>#include <stdlib.h>#include <cstdlib>#include <istream>#define MAX 10struct Trie { Trie *next[MAX]; int v;};Trie *root;void creattrie(char *str){ int i, j, len, t; Trie *p, *q; p = root; len = strlen(str); for (i = 0; i < len; i++ 阅读全文

posted @ 2011-07-20 11:34 more think, more gains 阅读(122) 评论(0) 推荐(0) 编辑

字典树 统计难题

摘要: #include <stdio.h>#include <string.h>#include <stdlib.h>#define MAX 26struct Trie { Trie *next[MAX]; int v;};Trie *root;void creattrie(char *str){ Trie *p, *q; int t, len, i, j; p = root; len = strlen(str); for (i = 0; i < len; i++) { t = str[i] - 'a'; if(p->next[t] = 阅读全文

posted @ 2011-07-20 11:33 more think, more gains 阅读(155) 评论(0) 推荐(0) 编辑

Dating with girls

摘要: 用二分查找。。#include <stdio.h>#include <stdlib.h>#include <algorithm>#include <string.h>#include <istream>using namespace std;int A[100010],visit[100010];//二分 int find(int l, int r, int v){ int mid; while (l <= r) { //printf("****"); mid = (l + r) / 2; if( A[mid 阅读全文

posted @ 2011-07-20 11:30 more think, more gains 阅读(221) 评论(0) 推荐(0) 编辑

排名 模拟题

摘要: #include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;int N, M, G;int g[20];struct node { int num[20]; char name[50]; int n; int sum;}T[1010];/*int cmp(node a, node b){ if (a.sum != b.sum ) return a.sum - b.sum; return strcmp(a.name,b 阅读全文

posted @ 2011-07-20 11:18 more think, more gains 阅读(130) 评论(0) 推荐(0) 编辑

Crixalis's Equipment hdu 3177

摘要: 这题我用的是逆向思维,从洞里把它拿出来,不用考虑先拿什么。。只要满足条件就拿出来。暴力搜索,最后竟然0ms。看了下网上的代码用的是差值排序。。。用时还要15ms#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int V[1010], L[1010];struct node{ int v, l;}T[1010];int main( ){ int P, i, M, N, flag, v, m, flag1; scanf("%d",& 阅读全文

posted @ 2011-07-20 11:15 more think, more gains 阅读(170) 评论(0) 推荐(0) 编辑

排序

摘要: 字符串处理,刚开始又出错了。。以后还是慎用for ,用while好点。。 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <algorithm> 5 6 using namespace std; 7 char ch[1010]; 8 char str[10]; 9 int dp[1010];10 11 int main( )12 {13 int i, j, t, len, k, flag;14 while(scanf("%s" 阅读全文

posted @ 2011-07-20 11:12 more think, more gains 阅读(88) 评论(0) 推荐(0) 编辑

考试排名

摘要: 模拟题啊,wa了好几次,原来是没有看清题意,悲剧啊。。不过做模拟题还是有意思啊。。还有通过这道题发现自己真的不太擅长字符串处理,开始搞错了,最后为了出错,写得代码有点多。。#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>struct node { int ac; char name[40]; int sum;}T[1010];char mark1[10],mark2[10];int x;int find ( char *s ){ int i, k 阅读全文

posted @ 2011-07-20 11:10 more think, more gains 阅读(172) 评论(0) 推荐(0) 编辑

产生冠军

摘要: 这题处理下字符串,判断下入度为零的点就可以了。。#include <stdio.h>#include <string.h>#include <stdlib.h>char name[2011][100];char str1[100],str2[100];//int map[2021][2211];int dp[2022];int N, M, flag;int find( char *s ,int x){ int i; for ( i = 0; i < x; i++) if(strcmp(s,name[i]) == 0) return i; return 阅读全文

posted @ 2011-07-20 11:04 more think, more gains 阅读(184) 评论(0) 推荐(0) 编辑

确定比赛名次 最简单的拓朴排序

摘要: #include <stdio.h>#include <string.h>#include <stdlib.h>#include <stack>using namespace std;int N, M, dp[510], visit[510];int map[510][510]; int main( ){ int i, j, a, b, t, flag, k; while (scanf("%d%d", &N, &M) != EOF) { flag = 0; k = 0; stack<int>q; m 阅读全文

posted @ 2011-07-20 11:00 more think, more gains 阅读(253) 评论(0) 推荐(0) 编辑

reward

摘要: 关键点是每一次点度数减1后,要即时更新其奖金值。。 用邻接矩阵写超时,学了下用STL vector写邻接表。用stl真的非常方便但是非常要时间啊 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <vector> 5 #include <stack> 6 7 using namespace std; 8 9 int N, M, i, j ,t1, t2, sum ,l, a, b;10 int dp[10010],exp[10010] 阅读全文

posted @ 2011-07-20 10:59 more think, more gains 阅读(234) 评论(0) 推荐(0) 编辑

Legal or Not

摘要: //用邻接矩阵写的,加 stl 栈,自己写栈也好简单的,直接开个数组,一个指针就可以了。。用stl太废时间了。//有些题目很容易超时 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <stack> 5 using namespace std; 6 7 int N, M, dp[110], visit[510]; 8 9 int map[110][110];10 11 int main( )12 {13 int i, j, a, b, t, fl 阅读全文

posted @ 2011-07-20 10:55 more think, more gains 阅读(211) 评论(0) 推荐(0) 编辑

The area 积分

摘要: 思路就是用顶点式求抛物线的方程,然后再再求出其原函数,积分减去梯形面积即可 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 5 double a, b, c, x1, x2, x3, p1, p2, p3; 6 7 double fun (double x ) 8 { 9 return (1.0 / 3 ) * a * ( x - x1 ) * (x - x1 ) * (x - x1 ) + p1 * x; 10 }11 12 int main( )13 {14 int T, 阅读全文

posted @ 2011-07-20 10:29 more think, more gains 阅读(225) 评论(0) 推荐(0) 编辑

找新朋友 hdu 1286 筛选法

摘要: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 #include <string.h> 5 6 int A[400000]; 7 8 int prime(int N) 9 {10 int i, j, k = 0;11 12 for (i = 2; i < N ; i++) {13 if (N % i == 0 ) {14 for (j = i; j < N; j += i)15 A[j] = 1;16 }17 }18 for (i = 1; i < 阅读全文

posted @ 2011-07-20 10:25 more think, more gains 阅读(144) 评论(0) 推荐(0) 编辑

hdu 1164 Eddy's research I 素数筛选法

摘要: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 6 int A[80000], dp[20000]; 7 8 const int inf = 65535; 9 10 int prime( )11 {12 int i, j, k = 0;13 A[1] = 1;14 for( i = 2; i <= sqrt(inf); i++)15 for ( j = 2 * i; j <= inf; j += i)16 A[ 阅读全文

posted @ 2011-07-20 10:21 more think, more gains 阅读(149) 评论(0) 推荐(0) 编辑

数论学习之素数

摘要: 数论学习之素数1.相关定义:整除: 设a, b是两个整数,且b != 0 如果存在整数c ,使 a = bc, 则称a被b整除, 或b 整除a , 记作b|a;带余除法:a = qb + r;这个式子称为带余除法 记余数 r = a mod b;2.整除性质1. 如果a |b 且 a | c,则对任意正整数x, y ,有a | bx + c y;2.如果 a| b 且 b|c, 则a | c;3.设m != 0,则a | b,当且仅当 ma | mb;4.如果 a | b且b | a,则a = +_b;5.如果a| b,且 b!= 0,则 |a| <= |b|;3.素数定义:如果正整数a 阅读全文

posted @ 2011-07-20 10:18 more think, more gains 阅读(240) 评论(0) 推荐(1) 编辑

数论学习之最大公约数与最小公倍数

摘要: 数论学习之最大公约数与最小公倍数最大公约数 定义:设a,b是两个整数,如果d|a,且d|b,则称d是a和b的公因子,或公约数,除0之外,任和整数只有有限个因子,其中最大的叫做最大公约数。 记做: gcd( a, b)最小公倍数 定义:设a, b 是两个整数,如果a|d,b|d,则称d是a,b的公倍数,a,b的公倍数有无穷个,最小的那个称做最小公倍数。 记做 :lcm (a,b); 显然对于任意的正整数a:gcd(0,a) = a; gcd(1,a)=1; lcm(1,a) = a;最小公倍数与最大公约的数两条性质:1.a|m , b|m, lcm(a,b) l m;2.m|a,m|b, m | 阅读全文

posted @ 2011-07-20 09:44 more think, more gains 阅读(543) 评论(0) 推荐(0) 编辑

linux下常用命令

摘要: linux下常用命令cd 改变目录cd空格目录dirtopkillsudo apt-get installman info qlssu//下面三个查看文本文件catheadtail忘记root密码ways:1.进入recovery mode2.root3.passwd4输入新密码linux下删除sudo apt-get remove *sudo apt-get purge scimlinux下查找find -name d*linux下编程1.vim2.gvim3.gedit4.codeblocks编译器c gccc++ g++都可以通过sudo apt-get install 软件名下载还有一 阅读全文

posted @ 2011-07-20 08:53 more think, more gains 阅读(333) 评论(0) 推荐(0) 编辑

导航