随笔分类 -  北大OJ

poj 3274 Gold Balanced Lineup (神奇的哈希)
摘要:题意理解有误狠狠的把自己骗了,每个牛有K个属性,我理解成选出K中属性的,由于思维定势看看题报告没有发现这个问题。纠结,这几天总犯这种错误。。。Farmer John's有n头cow,共k个属性,每个属性用一位2进制表示。求最长连续的段,满足段里的每个属性出现的次数一样多。sum[][]记录从上之下的和,c[][]记录sum[][]从左到右的差值,把每个牛的各个属性用哈希处理即可,从上向下贪心即可。哈希数值 prime = 99983, 跑了 875MS ,prime =1000000,只跑了250MS 。至于110000 直接 TLE#include <stdio.h>#i 阅读全文

posted @ 2012-03-26 20:35 skyming 阅读(335) 评论(0) 推荐(0)

2012春季ACM内部测试赛5(水版解题报告)
摘要:A:字符串处理和 poj 上的一道题很相似,不过很长时间才明白题意,由于处理上的小错误,贡献了1WA。代码~~太丑了见不得人啊。G:简单的贪心题,从前向后贪即可,理解上有误,但是看见A的队越来越多,而且4,5百B,瞬间把小高我俩秒了,自杀啊.F:官方说是用the Pollard Rho算法做的,不是太理解。比赛的时候,由于数据太大,int 型超内存,pc 用char ,把校内的oj 水 了赛后,别的队用哈希做的10^9 --》10^6 ,映射View Code #include<stdio.h>#include<string.h>#define HASHLEN 2000 阅读全文

posted @ 2012-03-25 21:40 skyming 阅读(245) 评论(0) 推荐(0)

poj 1094 Sorting It All Out (拓扑排序)
摘要:效率太低了,反思~~~~1:题意理解错误where xxx is the number of relations processed at the time either a sorted sequence is determined or an inconsistency is found, whichever comes first, and yyy...y is the sorted, ascending sequence.明明没说是按它列的顺序求解--关系的数量,2:对环的处理上没有搞好#include<stdio.h>#include<string.h>#de 阅读全文

posted @ 2012-03-22 01:32 skyming 阅读(264) 评论(0) 推荐(0)

poj 1273 Drainage Ditches ( 最大流--Edmonds_karp算法)
摘要:终于搞定了第一网络流的题~~看了好久啊才理解题意: 求排水沟的最大流量,最大流的模版题,EK算法 若没听说过网络流,直接pass 吧.用g++提交 加上 string.h#include<iostream>#include<cstdio>#include<queue>using namespace std;const int N =210;const int inf =0x7fffffff;int map[N][N],path[N],flow[N];int start,end,m,n;queue<int> q;int bfs(){ while(! 阅读全文

posted @ 2012-03-21 02:02 skyming 阅读(272) 评论(0) 推荐(0)

poj 3278 Catch That Cow (BFS)
摘要:题意: 牛逃跑了,主人用最短的时间追到牛(在直线上) 很裸的bfs ,郁闷啊忘了判断重复了,RE ,WA !#include<stdio.h>#define N 100005int n,k;int stack[N],vis[N];int main(){ scanf("%d%d",&n,&k); int di=0,top=1,first=0,last=1; int sum=0;stack[0]=n,vis[n]=1; while(di!=top) { last--; int num=stack[di++]; if(num!=... 阅读全文

posted @ 2012-03-09 00:39 skyming 阅读(251) 评论(0) 推荐(0)

poj 1068 Parencodings (模拟)
摘要:题意: 先输入右括号前左括号的数量 输出每个括号所含括号的数量(从左至右)思路: 由于以前模拟题留下太大的阴影,比较凌乱:没想到今天 模拟1Y 虽然题简单点,就是用-1 1 模拟 括号 ,向前搜索即可#include<stdio.h>int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int flag[50],top=0; int first,m; scanf("%d",&m);first=m; w... 阅读全文

posted @ 2012-03-06 21:53 skyming 阅读(171) 评论(0) 推荐(0)

poj 1035 Spell checker(字符串)
摘要:题意: 检测输入字符串和库里的字符串是否相符 相符按要求输出即可,若不符;分三种情况讨论 1;字符串长度相等 处理很简单,掠过 2;字符串不等时,分别设两个指针,从前向后,从后向前移动判断即可 注意判断边界条件 top1>di !!!#include<stdio.h>#include<math.h>#include<string.h>struct node{ char str[20];}map[10005];int main(){ int top=0; while(gets(map[top++].str)&&map[top-1].str 阅读全文

posted @ 2012-03-05 20:24 skyming 阅读(270) 评论(0) 推荐(0)

poj 2299 Ultra-QuickSort(归并排序)
摘要:维基百科:动画很帅 ,很简明说明归并排序http://en.wikipedia.org/wiki/Merge_sort 一看这题 7000MS ,果断 暴力, 结果TLE 。。。。 然后用归并写了一个,WA ,弱爆了,后来看了下解题报告, 判断条件考虑不全面。。。。。#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;const int N=500005;__int64 sum,n;int num[N],stack[N];void mergesort(int lo 阅读全文

posted @ 2012-03-01 12:29 skyming 阅读(972) 评论(0) 推荐(0)

poj 2506 Tiling
摘要:哈哈~~第一个自己写的大整数~~纪念一下#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;int num[255][100];int main(){ int n; while(scanf("%d",&n)==1) { if(n==0||n==1) { puts("1");continue ; } int digit=1; num[0][0]=nu... 阅读全文

posted @ 2012-02-23 20:20 skyming 阅读(418) 评论(0) 推荐(0)

poj 1753 Flip Game
摘要:先写个暴搜+位运算的: 对于位运算的应用有所帮助,希望对于像偶一样的菜鸟有所帮助;这里对与位运算的理解还是 i 到 a[4][4] 的转换:举个例子吧: i=1 a[][]={0,0,0,0,0 0 0 0 ,0 0 0 0 ,0 0 0 1} 至于详细的思路参考:http://blog.sina.com.cn/s/blog_63509b890100pm7b.htmlView Code //poj 1753#include <iostream>#define MAX 0x7ffffffusing namespace std;int flip[16] = {0x13,0x27, 78 阅读全文

posted @ 2011-11-27 20:48 skyming 阅读(316) 评论(0) 推荐(0)

poj 3767 I Wanna Go Home
摘要:题目分析: 这个题属于典型的dijkstra 算法的题; n个村庄,m 条路 和两村庄之间所用时间 最后是各个城市所属阵营;题意分析: 分为两个阵营,1,2城市分别属于1,2阵营(题意简单化题目)求从城市1到城市2 的最短时间重点: 可以从城市1到2,反则不行:因此,在这加上判断条件,套用dijkstra算法就ok了#include<stdio.h>#define max 0x7fffffffint grah[601][601];int root[601];int n;void dij(){ int d[601]; bool vis... 阅读全文

posted @ 2011-08-16 17:26 skyming 阅读(369) 评论(0) 推荐(0)