自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

菜鸟的程序人生

不做下一个谁,先做第一个我

  • 博客(52)
  • 收藏
  • 关注

原创 旅行商

旅行商Time Limit: 1000 ms   Case Time Limit:1000 ms   Memory Limit: 64 MBTotal Submission: 238   Submission Accepted: 67Description旅行商问题描述如下:在一个无向图中,找到符合条件的最小长度回路,这个回路经过每一个结点一次。Input第一行:一个正整数

2012-07-31 22:14:05 2169

原创 HDU-1520-Anniversary party

HDU-1520-Anniversary partyhttp://acm.hdu.edu.cn/showproblem.php?pid=1520DFS,有些节点具有父子关系,要求具有父子关系的节点不能同时出现#include#include#include#define N 6001struct node //左二子右兄弟法建树{ int parent; in

2012-07-30 10:23:03 1325

原创 HDU-1074-Doing Homework

HDU-1074-Doing Homeworkhttp://acm.hdu.edu.cn/showproblem.php?pid=1074状态压缩DP,我们可以使用一个二进制的数来表示做作业的状态,1表示做了,0表示没做dp[i]表示状态i损失的分数,再做一个作业x可到另一状态dp[j],则要有i&x==0,若要有dp[a],dp[b]均可以到达dp[j],那么选择损失分数最小的,若分

2012-07-29 20:59:03 2253

原创 C#学习1

首先来写个个helloworld吧,代码很短namespace helloworld{ class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); //将指定的字符串值(后跟当前行终止符)写入标准输出流

2012-07-29 01:00:57 2575 4

原创 HDU-1565-方格取数(1)

HDU-1565-方格取数(1)http://acm.hdu.edu.cn/showproblem.php?pid=1565我的第一个状态压缩DP给你一个n*n的格子的棋盘,每个格子里面有一个非负数,从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大375 15 21 75 15 28 34 70 51

2012-07-28 22:11:43 3186

原创 HDU-1501-Zipper

HDU-1501-Zipperhttp://acm.hdu.edu.cn/showproblem.php?pid=1501基本的DFS,注意搜索过的状态要标记,不然会超时#include#include#includechar str1[205],str2[205],str3[405];int flag;int len1,len2,len3;int hash[205][

2012-07-27 21:06:05 1923

原创 HDU-1016-Prime Ring Problem

HDU-1016-Prime Ring Problemhttp://acm.hdu.edu.cn/showproblem.php?pid=1016基本的DFS,先打个素数表即可#include#include#includeint prime[50];int visit[30];int num[30];int n;void init(){ int i,j;

2012-07-27 20:50:14 1072

原创 HDU-1258-Sum It Up

HDU-1258-Sum It Uphttp://acm.hdu.edu.cn/showproblem.php?pid=1258注意每个数只能用一次,且不能出现重复的等式#include#include#includeint a[20],ans[20];int sum,n,flag;void dfs(int x,int count,int m){ int i,last;

2012-07-27 09:30:54 2105

原创 HDU-1195-Open the Lock

HDU-1195-Open the Lockhttp://acm.hdu.edu.cn/showproblem.php?pid=1195基本的BFS,对一个四位数,任选一位加1或减1,或交换相邻的两个数#include#include#include#include#include#includeusing namespace std;int visit[11][11][

2012-07-25 22:55:07 1777

原创 HDU-1253-胜利大逃亡

HDU-1253-胜利大逃亡http://acm.hdu.edu.cn/showproblem.php?pid=1253简单的三维BFS#include#include#include#include#include#includeusing namespace std;char visit[52][52][52];char map[52][52][52];int

2012-07-25 21:55:19 3530

原创 HDU-1548-A strange lift

HDU-1548-A strange lifthttp://acm.hdu.edu.cn/showproblem.php?pid=1548基本的BFS,上下两个方向搜索#include#include#include#include#includeusing namespace std;int n;int visit[205];int num[205];struct

2012-07-25 08:49:37 988

原创 HDU-2717-Catch That Cow

HDU-2717-Catch That Cowhttp://acm.hdu.edu.cn/showproblem.php?pid=2717基本的BFS,朝3个方向搜索即可#include#include#include#include#includeusing namespace std;int n,k;char visit[100005];struct node{

2012-07-25 08:09:38 1015

原创 HDU-1278-逃离迷宫

HDU-1278-逃离迷宫http://acm.hdu.edu.cn/showproblem.php?pid=1728不好想,参考别的代码写的,题目要求转弯的次数不能超过k,BFS,从一个方向搜到底#include#include#include#include#includeusing namespace std;int n1,n2,k;char map[105][10

2012-07-24 22:47:10 2293

原创 HDU-2102-A计划

HDU-2102-A计划http://acm.hdu.edu.cn/showproblem.php?pid=2102今天要到学校的第一天,天气还是挺热的,我的暑假也算是结束了,在家的一个月里,看了一部电视剧《浮沉》,挺喜欢白百合的,也深刻体会了白领阶级的辛酸;还有就是把《闪客2》这个号称是横板鬼泣的游戏玩通关了,自己还是钟情于单机游戏,不多说了这题是BFS,注意处理#即可#in

2012-07-24 20:54:51 1449

原创 POJ-2352-Stars

POJ-2352-Starshttp://poj.org/problem?id=2352给出n个星星的坐标,如果一个星星的左下方(包含正左和正下)有k颗星星,就说这颗星星是k级的,统计每个等级有多少个点。这题可用树状数组,对于每个星星按y坐标从小到大排序,相同y坐标按x坐标从小到大排序(题目中数据已经有序),输入顺序已排好序,那么只要依次统计星星i之前x坐标小于等于i.x的星星有多少,即是

2012-07-22 15:15:06 2332

原创 HDU-1166-敌兵布阵(树状数组)

HDU-1166-敌兵布阵(树状数组)http://acm.hdu.edu.cn/showproblem.php?pid=1166这题之前用线段树做的,现在用树状数组先简单说下树状数组吧如上图所示c1 = a1c2 = a1 + a2c3 = a3c4 = a1 + a2 + a3 + a4c5 = a5c6 = a5 + a6c7 = a7

2012-07-22 07:57:14 4693

原创 HDU-4038-Saving Princess Claire

HDU-4038-Saving Princess Clairehttp://acm.hdu.edu.cn/showproblem.php?pid=4308给出的地图中,Y为起点,C为终点,#点不能通过,所有的P为互通的传送门,故可将所有的P看作同一个点BFS即可,从Y点开始搜,搜到的第一个P点为最短的,此时将其他的P点都压入栈内,因为所有的P点都是等价的#include#incl

2012-07-21 22:47:37 1325

原创 HDU-1394-Minimum Inversion Number

HDU-1394-Minimum Inversion Numberhttp://acm.hdu.edu.cn/showproblem.php?pid=1394题意是给出n个数,求其逆序数,并每次将第一个数移至最后,再求其逆序数,求这n个排列中逆序数最小的一个逆序数的简单定义:The inversion number of a givennumber sequence a1, a2, .

2012-07-21 10:05:45 759

原创 HDU-1698-Just a Hook

HDU-1698-Just a Hookhttp://acm.hdu.edu.cn/showproblem.php?pid=1698还是成段更新线段树#include#include#include#define N 100005struct cam{ int x; int y; int sum; int val;}list[N*4];void build(int

2012-07-20 17:32:51 537

原创 POJ-3468-A Simple Problem with Integers

POJ-3468-A Simple Problem with Integershttp://poj.org/problem?id=3468成段更新线段树#include#include#include#define N 100005int num[N];struct cam{ int x; //起点 int y; //终点 __int64 sum; //和

2012-07-20 16:17:06 475

原创 HDU-1166-敌兵布阵(线段树)

HDU-1166-敌兵布阵http://acm.hdu.edu.cn/showproblem.php?pid=1166求区间的和,并可更新,线段树#include#include#include#define N 50005int num[N];struct cam{ int x; //起点 int y; //终点 int sum; //总数}list[N*

2012-07-19 08:10:19 895

原创 HDU-3074-Multiply game

HDU-3074-Multiply gamehttp://acm.hdu.edu.cn/showproblem.php?pid=3074求区间元素的乘积,可以更新元素,线段树即可#include#include#include#define Mod 1000000007#define N 50005int num[N];struct cam{ int x; //起点

2012-07-18 23:34:38 1023

原创 POJ-3264-Balanced Lineup

POJ-3264-Balanced Lineuphttp://poj.org/problem?id=3264线段树,求区间的最大值与最小值之差#include#include#include#define N 50005#define INF 0x7ffffffint num[N];struct cam{ int x; //起点 int y; //终点 int

2012-07-18 22:39:32 571

原创 HDU-1754-I Hate It

HDU-1754-I Hate Ithttp://acm.hdu.edu.cn/showproblem.php?pid=1754查询区间的最大值,并可以更新线段树即可,如图为区间[1,5]的线段树#include#include#include#define N 200005int num[N];struct cam{ int x; //起点 int

2012-07-18 21:52:06 661

原创 HDU-1298-T9

HDU-1298-T9http://acm.hdu.edu.cn/showproblem.php?pid=1298很好的一题,字典树+DFS,思路参考swm8023大牛的题意是模拟手机输入法,给出几个单词即频度,再给出几个数字串,确定对于给定的一个数字串,每输入一个数字,将显示什么字符本题的数字串的每一个数字均代表一个字母,而不是平常的手机,多个数字可能代表一个字母,首先可将给出的

2012-07-17 22:45:30 2791

原创 HDU-2846-Repository

HDU-2846-Repositoryhttp://acm.hdu.edu.cn/showproblem.php?pid=2846题意是给出一些模式串,再给出几个询问,询问给出的字符串在多少个模式串中出现比如字符串abc所含的字串有a,ab,abc,b,bc,c可用字典树解决,字典树能很好的处理前缀出现的次数,所以可将模式串分解,依次插入需要注意的是对于同一个模式串的不同子串可

2012-07-17 09:48:35 1867

原创 HDU-1247-Hats Words

HDU-1247-Hats Wordshttp://acm.hdu.edu.cn/showproblem.php?pid=1247还是字典树的题目,将每个单词分成两个单词即可,查找是否两个单词均在字典树中注意建树的时和之前略有区别,这题在插入单词时,只需记录单词结尾的节点,不需要记录一个单词的所有前缀#include#include#include#includeusing

2012-07-16 23:45:35 814

原创 POJ-2001-Shortest Prefixes

POJ-2001-Shortest Prefixeshttp://poj.org/problem?id=2001找出能唯一标示一个字符串的最短前缀,如果找不出,就输出该字符串用字典树即可#include#include#include#includeusing namespace std;char list[1005][25];struct node{ int co

2012-07-16 22:09:10 4663 2

原创 HDU-1251-统计难题

HDU-1251-统计难题http://acm.hdu.edu.cn/showproblem.php?pid=1251基本的字典树,字典树又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种。典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:利用字符串的公共前缀来节约存储空间,最大限度地减少无谓的字符串比较,查询效

2012-07-16 16:55:13 5829 4

原创 HDU-1427-速算24点

HDU-1427-速算24点http://acm.hdu.edu.cn/showproblem.php?pid=14274个数通过 +,—,*,/和加括号,计算得24,枚举数字和运算符,DFS即可,注意题目要求计算过程中都不能出现小数,所以做除法时稍作处理枚举数组可用algorithm里的next_permutationThe next_permutation() functi

2012-07-16 15:11:33 5899

原创 POJ-1088-滑雪

POJ-1088-滑雪http://poj.org/problem?id=1088从每一个点深搜,果然超时了,因为这要重复计算很多次,优化一下,将搜索过的点记录下来,避免重复计算即可超时的代码#include#include#includeint map[105][105];int n1,n2,ans;int dir[4][2]={{0,-1},{0,1},{-1,0

2012-07-15 11:38:42 838

原创 HDU-2577-How to Type

HDU-2577-How to Typehttp://acm.hdu.edu.cn/showproblem.php?pid=2577很有趣的一题,给一组字符串,问最少按几次键盘可以打完小写字母可在capslock不亮时打出,也可在capslock亮时,按shift打出大写字母可在capslock亮时打出,也可在capslock不亮时,按shift打出用两个数组,逐步计算每一字母

2012-07-14 23:19:38 827

原创 HDU-1160-FatMouse's Speed

HDU-1160-FatMouse's Speedhttp://acm.hdu.edu.cn/showproblem.php?pid=1160对体重从小到大排序,要求体重越小,速度越快,找一个最长递增子序列即可#include#include#includestruct cam{ int x; int y; int num;}list[1005];int dp[100

2012-07-14 22:12:49 1508 2

原创 POJ-2251-Dungeon Master

POJ-2251-Dungeon Masterhttp://poj.org/problem?id=2251基本的三维BFS,用队列写的#include#include#include#include#includeusing namespace std;int n1,n2,n3;char map[40][40][40];int visit[40][40][4

2012-07-14 20:20:27 852

原创 筛选法

HDU-1215-七夕节http://acm.hdu.edu.cn/showproblem.php?pid=1215#include#include#includeint a[500001];void init(){ int i,j; memset(a,0,sizeof(a)); for(i=1;i<=500000;i++) a[i]=1; for(i=2;i<=2

2012-07-12 22:59:15 799

原创 POJ-2488-A Knight's Journey

POJ-2488-A Knight's Journeyhttp://poj.org/problem?id=2488给一个n1*n2的棋盘,从(0,0)出发,每次走日字形,能否不重复的遍历所有的点用DFS即可,需要注意搜索的方向要按字典序 #include#include#includeint n1,n2;int xx[30],yy[30];int visit[30][30

2012-07-12 22:19:32 2909 1

原创 POJ-1321-棋盘问题

POJ-1321-棋盘问题http://poj.org/problem?id=1321基本的DFS#include#include#includeint n,t,ans;char map[10][10];int visit[10];void dfs(int x,int y){ int i; if(y==t) { ans++; return; } if(x

2012-07-12 19:17:18 948

原创 HDU-1244-Oil Deposits

HDU-1244-Oil Depositshttp://acm.hdu.edu.cn/showproblem.php?pid=1241基本的DFS#include#include#includechar map[105][105];int n,m;int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1

2012-07-12 18:22:58 1206

原创 POJ-3984-迷宫问题

POJ-3984-迷宫问题http://poj.org/problem?id=3984用BFS求最短路劲,记录每一个状态之前的状态,输出路劲即可#include#include#includeint map[5][5];int visit[5][5];int pre[100]; //记录每一个状态的前一个状态struct cam{ int x; int y;}li

2012-07-12 17:10:40 8332

原创 最小路劲覆盖 最小点覆盖 最大独立集

最小路劲覆盖一个不含圈的有向图G 中,G的一个路径覆盖是一个其结点不相交的路径集合P,图中的每一个结点仅包含于P中的某一条路径。路径可以从任意结点开始和结束,且长度也为任意值,包括0。在有向无环图中    最小路径覆盖数 = 顶点总数—最大匹配数POJ-1422-Air Raidhttp://poj.org/problem?id=1422#include#include

2012-07-11 23:03:47 3500

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除