摘要: 可以测试自己的代码用时啦printf("used time = %.3lf\n",(double)clock()/CLOCKS_PER_SEC); 阅读全文
posted @ 2011-04-20 12:12 L.. 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 名称: sscanf() -从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( stringstr, string fmt, mixed var1, mixed var2 ... ); intscanf( const char *format [,argument]... ); 说明: sscanf与scanf类似,都是用于输入的,只是后者以屏幕(stdin)为输入源,前者以固定字符串为输入源。 其中的format可以是一个或多个{%[*] [width] [{h | l | I64 |L}]type | ' ' | '\t' | &# 阅读全文
posted @ 2011-04-20 11:51 L.. 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 1.如果没有重合,总时间为102.影响搬运时间的是两个区间的重合,每次重合时间加103.从整体上看,每10分钟选择全部不冲突的区间搬运,程序上用一个cover数组记录区间被覆盖的次数,最后比较最大值,得到最大时间#include <iostream>#include <string.h>using namespace std;int main(){ int t; int cover[200]; cin >> t; while( t-- ){ memset(cover, 0,sizeof(cover)); int n, s, f; cin >> n 阅读全文
posted @ 2011-04-20 03:43 L.. 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 很CHUO的代码用的是单调队列还有更好的做法 以后补上#include <stdio.h>struct Queue{ int idx, val;}que[1000000];int a[1000000];int head, tail;int main(){ int n, k; scanf("%d%d",&n, &k); for(int i = 0; i < n; ++i){ scanf("%d",&a[i]); } // k 为1时候的特殊情况, 还有更好的做法.. if( k == 1 ){ for(int i 阅读全文
posted @ 2011-04-20 02:32 L.. 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 题意给定一个由NC个字母组成的字符串,求长度为N的不同子串的个数思路:由于只有NC个字母,可以将字母编号,0 ~ NC - 1,转换成数字,就可以将字符串表示成NC进制的数字,这样所有字串代表的数字都是唯一的,转换成10进制的数也是唯一的!就像10的二进制表示只有1010例如3 4daababacd = 3a = 0b = 1c = 2daa = 3 * 4 ^ 2 + 0 * 4 ^ 1 + 0 * 4 ^ 0 = 48#include <stdio.h>#include <string.h>char str[1000000];bool hash[16000000] 阅读全文
posted @ 2011-04-19 16:50 L.. 阅读(669) 评论(0) 推荐(0) 编辑
摘要: 明显的优先队列用了STL,但是不全懂,自己写个堆估计悬... 有工具咱就用!#include <iostream>#include <queue>#include <vector>#include <stdio.h>using namespace std;const int MAXN = 60001;struct message{ char name[20]; int para,pri; int order; bool operator < (const message& m1)const { if(pri == m1.pri) r 阅读全文
posted @ 2011-04-19 16:23 L.. 阅读(433) 评论(0) 推荐(0) 编辑
摘要: 题意判断一组字符串中是否出现自己的前缀子串思路字典树#include <stdio.h>#include <string.h>const int MAXN = 100010;struct dicTree{ int next[10]; bool isWord; void init(){ memset(next,-1,sizeof(next)); isWord = false; }};dicTree tree[MAXN];int num; bool ok;void insert(char *s){ int index = 0 ,level = 1; while( *s ){ 阅读全文
posted @ 2011-04-19 16:14 L.. 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 在逻辑学中,逻辑算符异或(符号为XOR或EOR或⊕)是对两个运算元的一种逻辑析取类型。但与一般的逻辑或不同,异或算符的值为真仅当两个运算元中恰有一个的值为真,而另外一个的值为非真[1]。转化为命题,就是:“两者的值不同。”或“有且仅有一个为真。”两个运算元(命题):A与B的异或一般写成A异或B,或者写成AXORB、、等等。在C语言中,写作A^B。异或运算的真值表如下:AB⊕FFFFTTTFTTTFn是奇数,有一个数出现一次,其它数都是偶次。有因为数据量太大,所以用亦或。亦或满足交换律,相同的两个数亦或为0,任何数和0亦或为其本身。#include <stdio.h>int main 阅读全文
posted @ 2011-04-18 02:16 L.. 阅读(223) 评论(0) 推荐(1) 编辑
摘要: #include<stdio.h>int main(){ char input; while( (input = getchar()) != '#') { switch(input) { case ' ' : printf("%s","%20"); break; case '!' : printf("%s","%21"); break; case '$' : printf("%s","%24"); b 阅读全文
posted @ 2011-04-18 01:03 L.. 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 同POJ 2299 也是利用树状数组求逆序数的应用将x从大到小排序,若x相同,按y从大到小排序,对y建立树状数组,根据逆序数的定义,画图演算一遍就很清楚了#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAXN 1001struct Pair{ int x, y;}p[1000010];int n, m, k;int c[MAXN];int cmp(const void *a, const void *b){ if(((Pair*)a)->x == ((Pair*)b)-& 阅读全文
posted @ 2011-04-17 14:48 L.. 阅读(249) 评论(0) 推荐(0) 编辑