摘要: View Code 1 //Accepted 1248 93MS 2332K 512 B Java 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(String[] args) { 7 8 Scanner sc = new Scanner(System.in); 9 int b[] = {150,200,350};10 int ans[] = new int [10001]... 阅读全文
posted @ 2012-09-07 17:29 Wheat″ 阅读(183) 评论(0) 推荐(0)
摘要: View Code 1 //Accepted 3342 31MS 260K 1002 B G++ 2 #include <stdio.h> 3 #include <string.h> 4 #define M 110 5 int g[M][M]; 6 int q[M]; 7 bool useif[M]; 8 int n,m; 9 int topo()10 {11 int i,j,k,t;12 memset(useif,0,sizeof(useif));13 t = 0;14 for(i=1;i<=n;i++)15 {16 ... 阅读全文
posted @ 2012-09-07 17:18 Wheat″ 阅读(180) 评论(0) 推荐(0)
摘要: 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″ 阅读(216) 评论(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″ 阅读(758) 评论(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″ 阅读(228) 评论(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″ 阅读(154) 评论(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)