08 2012 档案

摘要:weak nodeTime Limit : 2000/1000ms (Java/Other)Memory Limit : 65535/32768K (Java/Other)Problem DescriptionCountry C preparing to attack Country J, but the shortage of troops Country C, Country C to find out the location of weak Country J defense.InputLine 1: n m(1<=n<=100,000, 1<=m<=120,0 阅读全文
posted @ 2012-08-24 19:33 Wheat″ 阅读(218) 评论(0) 推荐(0)
摘要:题意:一个有n个元素的数组num[],求所有num[i]~num[i+k]的最小值和最大值。RMQ 算法小心空间,很容易被卡到可以用线段树做,每个结点保存该线段的最大/小值...然后简单查询最大最小值即可RMQ:View Code 1 //Accepted 8008K 6110MS C++ 1577B 超卡空间 2 #include <cstdio> 3 #include <string> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 const int MA 阅读全文
posted @ 2012-08-24 19:23 Wheat″ 阅读(759) 评论(0) 推荐(0)
摘要:我的思路是:把前两个数组枚举合并成一个大数组a,后两个数组枚举合并成一个大数组b,然后a数组从小到大排序,b数组从大到小排序,再循环压缩两个数组用c++交tle 囧 ,g++6672MS 囧View Code 1 //Accepted 49432K 6672MS G++ 1024B 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #define MAX 4001 6 using namespace std; 7 int f[MAX][5],a[MAX*MAX],b[MAX*M 阅读全文
posted @ 2012-08-23 22:08 Wheat″ 阅读(129) 评论(0) 推荐(0)
摘要:求区间最大值与最小值的差,最经典的是RMQ,线段树也能做,第一次写线段树,庆祝^_^线段树代码:View Code 1 //Accepted 1200K 2094MS C++ 1633B 2 #include <stdio.h> 3 #include <string.h> 4 5 #define lson l , m , rt << 1 6 #define rson m + 1 , r , rt << 1 | 1 7 const int maxn = 55555; 8 9 int st_min[maxn<<2],st_max[maxn 阅读全文
posted @ 2012-08-23 12:59 Wheat″ 阅读(150) 评论(0) 推荐(0)
摘要:给定n个区间(l,r),问每个区间被多少个另外的区间所包含。包含的定义(l1,r1),(l2,r2),如果l1<=l2<r2<=r1&&(l1,r1)!=(l2,r2),则(l1,r1)包含(l2,r2)。用节点存储区间,然后给节点排序。l小的区间放在前面,l相同则r大的区间放在前面。为什么这样排序呢?因为对排序之后的节点,节点n只可能被排在它前面的(0--n-1)号节点包含,而不可能被后面的包含。那么(0--n-1)号节点中,又哪些能包含节点n呢?只要ri>=rn即可。(因为li<=ln的)。至于那部分怎么统计,用树状数组可以达到lgn的效率。V 阅读全文
posted @ 2012-08-23 10:52 Wheat″ 阅读(230) 评论(0) 推荐(0)
摘要:思路:使用trie树..将电话号码s插入树中,如果发现s的前缀已存在或者是s是前面的号码的前缀,则输出"NO"..全部都成功插入则"YES"这里的trie树要用数组表态实现,动态建树会TLE….数组要开到100000这个数量级…不然会RUNTIME ERRORView Code 1 //Accepted 4484K 172MS C++ 993B 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 #define M 10 6 using na 阅读全文
posted @ 2012-08-22 21:35 Wheat″ 阅读(155) 评论(0) 推荐(0)
摘要:最基础的字典树…插入一个串的时候,检查它的前缀是否已存在再检查它是否是前面给出的串的前缀…..View Code 1 //poj 1056 Accepted 176K 0MS C++ 1012B 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 #define M 2 6 using namespace std; 7 int ii; 8 bool flag; 9 struct Tree{10 Tree* next[M];11 int val;12 Tree()13... 阅读全文
posted @ 2012-08-22 21:32 Wheat″ 阅读(120) 评论(0) 推荐(1)
摘要:题目大意: 给定一个 N*N 的数组 求以(x1, y1) 为左上角 (x1 + b -1 ,y1 + b -1)为右下角 这个b*b的范围内最大值减最小值看到最大值最小值当然想到RMQ啦View Code //Accepted 27392K 594MS C++ 2416B#include <iostream>#include <stdio.h>#include <cmath>using namespace std;const int maxn = 301;int N;int val[maxn][maxn];int st_min[maxn][maxn][9] 阅读全文
posted @ 2012-08-22 21:28 Wheat″ 阅读(134) 评论(0) 推荐(0)
摘要:题意:给出m个模式和一个文本,求各种模式的出现次数比较裸的AC自动机,成功匹配就计数就是了..View Code 1 //Accepted 3065 281MS 13724K 2340 B C++ 2 3 #include <iostream> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 using namespace std; 9 const int inf=1<<28; 10 const int 阅读全文
posted @ 2012-08-22 20:34 Wheat″ 阅读(143) 评论(0) 推荐(0)
摘要:题目大意:找出匹配串在父串中出现的次数View Code 1 #include <iostream> 2 #include <string.h> 3 const int MAXN = 1000012; 4 char a[MAXN],b[MAXN];//a主串 b匹配串 5 void get_next(char *pstr,int *next) 6 { 7 int i=0; 8 *next=-1; 9 int j=-1;10 while(*(pstr+i)!='\0')11 {12 if(j==-1||*(pstr+i)==*(pstr+... 阅读全文
posted @ 2012-08-22 20:19 Wheat″ 阅读(120) 评论(0) 推荐(0)
摘要:题意:给出m个模式和一个文本,求各种模式的出现次数比较裸的AC自动机,成功匹配就计数就是了..View Code 1 //Accepted 2896 156MS 23516K 2412 B C++ 2 3 #include <iostream> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 using namespace std; 9 const int inf=1<<28; 10 const int 阅读全文
posted @ 2012-08-22 20:17 Wheat″ 阅读(249) 评论(0) 推荐(0)
摘要:递归+两个栈,一个存符号一个存数字,判断符号的优先级 +,- < *,/ < )in(111+999)/20+111(111+333*3)/(20+80)-(111+999)/20+111(1+(2+(3+4*5)-10000out166.50000066.6000000-9974.000000View Code 1 #include <string> 2 #include <fstream> 3 #include <iostream> 4 using namespace std; 5 6 7 bool valid = true, Found = 阅读全文
posted @ 2012-08-20 20:43 Wheat″ 阅读(158) 评论(0) 推荐(0)
摘要:一道很好的字典树题目,用每组第二个单词构造字典树,最后一个节点存第一个单词,其他节点存ch,接着对每个输入进行查询View Code 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #define M 26 5 using namespace std; 6 int ii; 7 struct Tree{ 8 Tree* next[M]; 9 char val[100];10 Tree()11 {12 for(ii=0;ii<M;ii++)13 ... 阅读全文
posted @ 2012-08-20 09:07 Wheat″ 阅读(132) 评论(0) 推荐(0)
摘要:View Code 1 import java.io.IOException; 2 3 4 public class IP1 { 5 public static void main(String[] args) { 6 String str="netsh interface ipv4 set address name=本地连接 source=static addr=172.16.101.145 mask=255.255.255.0 gateway=172.16.101.254 gwmetric=0"; 7 8 try { 9 ... 阅读全文
posted @ 2012-08-19 17:12 Wheat″ 阅读(300) 评论(0) 推荐(0)
摘要:先把字符串翻转过来,再通过sscanf函数的处理,获取A,B,C的值,再做比较,需要注意的是当输入 0+0=0 输出True 然后结束View Code 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 char data[30]; 5 int main() 6 { 7 while (true) 8 { 9 cin >> data;10 if (strcmp(data, "0+0=0") == 0)11 {12 cout... 阅读全文
posted @ 2012-08-19 16:50 Wheat″ 阅读(219) 评论(0) 推荐(0)
摘要:简单的字符串操作,用二维数组回旋处理输入的字符串,然后竖着输出二维字符数组toioynnkpheleaigshareconhtomesnlewx输出:| t o i o y ->|| h p k n n <-| e l e a i ->|| r a h s g <-| | e c o n h ->|| s e m o t <-|∨ n l e w x ->theresnoplacelikehomeonasnowynightxView Code 1 #include <stdio.h> 2 #include <string.h> 阅读全文
posted @ 2012-08-19 15:23 Wheat″ 阅读(143) 评论(0) 推荐(0)
摘要:简单的广搜题目,单广能过,可以拿这题练习双广单广:View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 int n; 5 int x1,y1,x2,y2; 6 int array[2][8] = {{-1, -1, -2, -2, 2, 2, 1, 1},{-2, 2, 1, -1, 1, -1, 2, -2}};//表示马跳的8个方向 7 int q[100000][3]; 8 bool h[310][310]; 9 void bfs()10 {11 int i,sd,ed;12 int x,y,a,b,c; 阅读全文
posted @ 2012-08-18 17:23 Wheat″ 阅读(152) 评论(0) 推荐(0)
摘要:题目意思:骑士游历的问题咯,单向广搜能过,也可以拿来练习双向广搜咯,附双向广搜代码View Code 1 #include <iostream> 2 #include <queue> 3 #include <cstdio> 4 using namespace std; 5 #define MAX 10 6 struct Status // 结构 7 { 8 int x,y; //位置 9 int vis; 10 }; 11 int visited[MAX][MAX];//标记数组 12 int dir[8][2]={{-2, -1}, {-2, 1... 阅读全文
posted @ 2012-08-18 17:13 Wheat″ 阅读(152) 评论(0) 推荐(1)
摘要:按题目的要求做记忆化递归View Code 1 #include <stdio.h> 2 #include <string.h> 3 int vis[21][21][21]; 4 5 int w(int a,int b,int c) 6 { 7 if(a <= 0 || b <= 0 || c <= 0) 8 return 1; 9 else if(a > 20 || b > 20 || c > 20)10 return w(20,20,20);11 else if(vis[a][b][c] > 0)12 return... 阅读全文
posted @ 2012-08-18 17:08 Wheat″ 阅读(118) 评论(0) 推荐(0)
摘要:DFS搜索由大的数往小的数View Code 1 #include <stdio.h> 2 #include <string.h> 3 int ans,n,a[1001]; 4 int b[1010]; 5 bool f; 6 void dfs(int v,int t,int g) 7 { 8 int i; 9 if(v==ans)10 {11 f = true;12 for(i=1;i<t-1;i++)13 printf("%d+",b[i]);14 printf("%d\n",b[t-1]);... 阅读全文
posted @ 2012-08-18 17:07 Wheat″ 阅读(108) 评论(0) 推荐(0)
摘要:一道几何题:设小圆半径为r,大圆为R,有图得 :R = r + r / sin(A);A = 2 * PI / (n * 2) = PI / n;联合得:r == R / ( 1 + ( 1 / sin( 2 * asin(1.0) /n)));PI = 2 * asin(1.0) 可以解决精度的问题View Code 1 #include <stdio.h> 2 #include <math.h> 3 int main(void) 4 { 5 int n,t; 6 double r1,r2; 7 scanf("%d",&n); 8 for( 阅读全文
posted @ 2012-08-18 16:07 Wheat″ 阅读(85) 评论(0) 推荐(0)
摘要:水题:求各个因子的和,再同n比较,小于输出DEFICIENT,等于输出PERFECT,大于输出ABUNDANT,附代码。#include <stdio.h>#include <string.h>int main(void){ int i,sum,n; puts("PERFECTION OUTPUT"); while(scanf("%d",&n)!=EOF && n) { printf("%5d ",n); sum = 0; for(i=1;i<n;i++) if(n%i==0) s 阅读全文
posted @ 2012-08-18 15:19 Wheat″ 阅读(115) 评论(0) 推荐(0)
摘要:本题锻炼字符串的处理 scanf("%s",s) or strstr or strlen 很好的利用,其他没什么好讲的,注意长度刚好80在上一行输出,附代码。View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 char s[100]; 5 6 7 int main(void) 8 { 9 int t,len=0;10 while(scanf("%s",s)!=EOF)11 {12 if(strstr(s,"<br>"))13 {14 pr 阅读全文
posted @ 2012-08-16 10:38 Wheat″ 阅读(124) 评论(0) 推荐(0)