C#设计模式[2] - 工厂方法模式 ????24个C#设计模式目录 ????源码地址概述仍然使用上一篇简单工厂模式中的例子,在水果农场中,FruitFactory可以返回具体的水果实例,包括????和????等等,但是如果这个水果农场新增了一种水果,比如????,那么我们除了新增????类以外,还需要修改FruitFactory的代码,使得整个设计违反了开闭原则。因此我们不再使用一个FruitFactory来统一负责所有水果实例的创建,...
博客搬家通知! 从我2016年以来加入CSDN到现在,已经获得了28万+的访问和313位粉丝,非常高兴我的疏浅的博文对你有所帮助,????感谢各位的关注!不过为了更好的阅读体验(广告,自定义UML等),我还是决定自建博客,希望各位可以偶尔来看看:新博客地址。同时,现有博客地址不再独立更新文章,仅供搬运已在新博客地址发布的文章。当然,现有的文章我也不会将其删除。...
C#设计模式[1] - 简单工厂模式 ????24个C#设计模式目录 ????源码地址概述一个水果农场,用户需要某一种水果时,农场能够根据用户所提供的水果名称返回该水果。在此,水果农场被称为工厂(Factory),而生产出的水果被称为产品,水果的名称被称为参数,工厂可以根据参数的不同返回不同的产品,这就是简单工厂的动机。简单工厂模式:定义一个工厂类,它可以根据参数的不同返回不同类的实例,被创建的实例通常都具有共同...
Libevent学习笔记 Libevent 学习笔记为了准备实习,提前学习一下Libevent,由于官方文档主要都是在介绍库的内容,有很多坑还是得自己踩,所以开一篇文章记录一下安装&&部署安装还是比较容易,安装github上的步骤就可以顺利完成,就是make install这一步是需要root权限的,不然会出现拒绝访问的情况。安装完成之后按照官方文档的教程写了一个很简单的log代码#include...
深信服面试准备题库 sangfor面试准备(已拿offer)Linux网络编程1.域套接字比流式套接字快的原因?UNIX域套接字用于同一台pc上运行的进程之间通信,它仅仅复制数据,不执行协议处理,不需要增加删除网络报头,无需计算校验和,不产生顺序号,无需发送确认报文。unix域套接字地址结构如下定义:#include <sys/un.h>struct sockaddr_un { s...
2018深信服秋招C++笔试题 1.有N个木板,问能容下多少水比如下面的木板长度就是2,1,3,可以容下5单位水 ||---||-|-|思路:用一个前缀数组,一个后缀数组记录分别当前位置左右最高的木板,那么这两者取最小值就是当前位置能容下的水了#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std;const int maxn = 1e5 + 5;int a...
【网络编程入门】使用socket在Linux下实现即时通信软件 使用C++在Linux下实现的即时通信软件 在前一篇文章中讲到了如何使用winsock:【网络编程入门】在C++中使用Windows TCP Sockets,也算是勉强入门了吧,接下来自己写一下在Linux下的网络编程,代码架构参考了实验楼的C++ 实现即时通信软件使用C++在Linux下实现的即时通信软件介绍进程、端口、Socket、IP地址字节顺序介...
【网络编程入门】在C++中使用Windows TCP Sockets 在C++中使用Windows TCP SocketsProgramming Windows TCP Sockets in C++ for the Beginner 译者注:本文于作者创作于2006年,在Word文档中能找到的作者名为Cameron Flint。对初次接触网络编程的新手,这是一篇非常好的入门教程,本文从理论到代码,都阐述的非常清楚。在阅读本文前,几乎不需要什么基础,如果懂...
PAT (Advanced Level)1020 Tree Traversals (25) 树的遍历 题目链接1020 Tree Traversals (25)题意前序遍历:Preorder Traversal中序遍历:Inorder Traversal后序遍历:PostorderTraversal层次遍历:level order traversal已知中序和后序,求层次遍历解题思路由中序和后序来建树,因为中序的最后一个必定是根节点,只要再该根节点左右继续构建...
PAT甲级 1017 Queueing at Bank (25) 模拟 题目链接1017 Queueing at Bank (25)题意银行有n个顾客,k个窗口,求顾客的平均等待时间解题思路每次取最早可以使用的窗口就行了Code#include <bits/stdc++.h>using namespace std;struct Time{ int hh, mm, ss; bool frien...
数据挖掘中的数据 数据挖掘中的数据数据挖掘中的数据属性的类型标称(=,≠)序数(>,<)区间(+,-)比率(×,÷)数据集数据集的一般特性遗漏值出现遗漏值的原因处理遗漏值的策略数据预处理聚集抽样维规约维灾难相似度和相异性简单属性的相似度和相异度标称的序数的区间或比率的简单匹配系数Jaccard系数余弦相似度欧几里得距离...
死锁的产生、避免与解除 死锁的产生原因因为系统资源不足。 进程运行推进的顺序不合适。 资源分配不当等。 四个必要条件互斥条件:一个资源每次只能被一个进程使用。请求与保持条件:一个进程因请求资源而阻塞时,对已获得的资源保持不放。不剥夺条件:进程已获得的资源,在末使用完之前,不能强行剥夺。 循环等待条件:若干进程之间形成一种头尾相接的循环等待资源关系。避免死锁死锁的预防是通过破坏产生...
C++设计模式笔记 参考:https://blog.csdn.net/liang19890820/article/details/66974516创建型模式单例模式抽象工厂模式创建型模式创建型模式(Creational Patterns),用于构建对象,以便它们可以从实现系统中分离出来。单例模式抽象工厂模式抽象工厂模式(Abstract Factory Pattern)是所...
三种内存分配算法总结及代码实现 首次适应算法最坏适应算法最佳适应算法代码实现首次适应算法 找第一个满足大小的空闲分区该算法从空闲分区链首开始查找,直至找到一个能满足其大小要求的空闲分区为止。然后再按 照作业的大小,从该分区中划出一块内存分配给请求者,余下的空闲分区仍留在空闲分区链中优点: 该算法倾向于使用内存中低地址部分的空闲区,在高地址部分的空闲区很少被利用,从而保留了高...
CF#482:C Kuro and Walking Route(DFS) 题目链接Kuro and Walking Route题意无向图,n个点,n-1条边,每两个点都可以到达,但是从依次经过u,v两点的道路不能走,问有多少个x->y可以到达解题思路根据题意可知这是一个最小生成树,那么u到v只有一条道路可走 结果用总数减去A的数量×B的数量就可以了 确定数量用DFSCode#include "bits/stdc++.h"...
Wannafly挑战赛15:A-最小化价格(贪心) 题目链接1013. Battle Over Cities (25)Time limit:1000 ms Memory limit:65536 kBProblem Descrpition现有n组人,m个地点,给出每组人的人数,每个地点可容纳的最大人数和选择的价格 要求一种方式,使得每组人都到一个各不相同的地点,最小化选择的价格 每个队伍的人都要在同一个地方每个地方只能有一个...
CF#479 D:Divide by three, multiply by two(DFS) 题目链接Divide by three, multiply by two题意有一个数x,经过一下两种操作×2÷3结果记录在黑板上,但顺序是乱的,现在要我们求正确的顺序解题思路直接搜索,搜到结果回溯时记录就可以了Code#include "cstdio"#include "iostream"#include "cstring"#includ...
PAT (Advanced Level) 1013. Battle Over Cities (25) DFS求连通分量 题目链接1013. Battle Over Cities (25)Time limit:400 ms Memory limit:65536 kBProblem DescrpitionIt is vitally important to have all the cities connected by highways in a war. If a city is o...
DFA转化为NFA DFA的确定化 代码实现 #include <iostream>#include <map>#include <set>#include <queue>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;const int max
CSU 2088: Pigs can't take a sudden turn(简单的计算几何) 题目链接Pigs can’t take a sudden turnTime limit:1000 ms Memory limit:65536 kBProblem DescrpitionYou maybe have ACed a question about computational geometry,which describes two dogs’ journey and...
2018 第九届蓝桥杯省赛总结 + 解题报告(C语言B组) 2018/4/1,我参加了蓝桥杯C语言B组湖南省赛,今年第三次参加蓝桥杯了,虽然会的东西比去年多了不少,但是发挥却不如上次,最大的总结就是要细心啊!1.第几天2.明码3.乘积尾零4.测试次数5.快速排序6.递增三元组7.标题:螺旋折线8.日志统计8.全球变暖1.第几天2000年的1月1日,是那一年的第1天。 那么,2000年的5月4日,是那一年...
PAT (Advanced Level)1009. Product of Polynomials (25) 水 题目链接1009. Product of Polynomials (25)Time limit:400 ms Memory limit:65536 kBProblem DescrpitionThis time, you are supposed to find A*B where A and B are two polynomials.InputEach ...
C++中new和malloc的区别 参考原文new/delete和malloc/free的区别malloc和free是库函数,而new和delete是C++操作符#inlcude <stdlib.h>new自己计算需要的空间大小,malloc需要指定大小int* a = new int;int* b = (int*)malloc(sizeof(int));new在动态分配内存的时候...
PAT (Advanced Level) 1007. Maximum Subsequence Sum (25) dp 题目链接1007. Maximum Subsequence Sum (25)Time limit:400 ms Memory limit:65536 kBProblem DescrpitionGiven a sequence of K integers { N1, N2, …, NK }. A continuous subsequence is defined to...
C++中const关键字的作用 参照原文 const是constant的简写,只要一个变量前面用const来修饰,就意味着该变量里的数据可以被访问,不能被修改。也就是说const意味着“只读”readonly规则:const离谁近,谁就不能被修改; const修饰一个变量,一定要给这个变量初始化值,若不初始化,后面就无法初始化。 本质:const在谁后面谁就不可以修改,const在最前面则将其后移一位,二者等效...
C++ 中的引用 引用与指针的区别 引用即别名基本用法int a=5;int &amp;b=a;这里b就是a的一个引用,我们对a或b的修改都会影响对方,因为两者实际上是一个对象,只不过有不同的名字引用的类型需要和与之绑定的对象严格匹配,除了以下两种情况const的引用 double a = 3.14; const int b = a; //把 b 输出得到 3 此处对 b 的操...
PAT (Advanced Level) 1004. Counting Leaves (30) BFS 题目链接Counting LeavesTime limit:1 seconds Memory limit:256 megabytes Problem DescriptionA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members w...
C++ extern 变量声明与定义的关系 声明(declaration):告诉程序有这么一个名字,一个文件如果想使用从别处定义的名字则必须包含对那个名字的声明 定义(definition):创建与名字关联的实体变量声明规定了变量的类型和名字,这一点在上定义与之相同。但除此之外,定义还申请存储空间,也可能为变量赋初始值 extern int i; //声明i而非定义i int j; //声明...
C++基本算术类型 C++基本类型包括算术类型和空类型(void) 算数类型包含整型(包括字符和布尔类型)和浮点型C++标准规定尺寸的最小值如下 类型 含义 大小 bool 布尔类型 未定义 char 字符 8位 int 整型 16位 long 长整型 32位 long long 长整型 64位 flo...
PAT(Advanced Level) 1003. Emergency(25) 最短路 + DFS 题目链接EmergencyTime limit:1 seconds Memory limit:256 megabytes Problem DescriptionIAs an emergency rescue team leader of a city, you are given a special map of your country. The map shows...
解决 Ubuntu 下 网易云音乐 1.2 无法运行的问题 1.2版本我试了各种方法反正是启动不了了 还好看来apt-get的包还没更新,回退到1.1版本完美运行~sudo apt-get remove netease-cloud-musicsudo apt-get install netease-cloud-music
MyEclipse 2017 整合SSH三大框架 到登录功能的实现(附源码) 本来以为学完Java EE之后用个三大框架没什么难度,结果昨天搭环境就搞了一晚上,还是靠室友找了半天才找出错误在哪,为了避免重复踩坑,而且目前网上用myeclipse2017做环境的教程还是蛮少的,就写篇博客记录一下点我查看源码先看一下最终的架构 整个流程参考了很多大佬的博客,就不一一摆出来了,我这里主要用的刘伟老师给的步骤0.环境版本 IDE:MyEclip...
Struts 2提交form表单执行action后不跳转(ajax) 今日写项目写到一个商品加入购物车功能,原本设计是点击按钮之后,存储数据,并弹出一个div告知用户添加成功,页面不跳转,看似很简单的功能,却在“不跳转”这点上卡住,我不想跳转咋就这么难呢?查了很多资料,知道了要用ajax,因为本人愚钝,并没有能够解决我的小问题,一度想要放弃,特别感谢熊世唯同学不耐其烦的指导,让我解决了这个小难题本篇博客旨在还没有深入理解ajax的情况下,实现一个提交form表单后不
总结:Hibernate关联关系映射——七种映射的实现(更新中) 一对一关联共享主键方式唯一外键方式多对一单向关联一对多双向关联多对多单向关联多对多双向关联一对一关联 Hibernate映射实体的一对一关联方式有共享主键方式和唯一外键方式。共享主键就是两个表的主键完全相同,保证一对一。唯一外键就是一个表的唯一外键对应另一个表的唯一主键,来保证一对一。共享主键方式唯一外键方式现实中一个人住一个房间,一个房间是可以多个人住的,这就是多对一的关系,但我
Tomcat启动报错: StandardServer.await: create[8005] 简单解决方案 错误信息 org.apache.catalina.core.StandardServer await 严重: StandardServer.await: create[8005]: java.net.BindException: Address already in use at java.net.PlainSocketImpl.socketBind(Native Metho
Codeforces 894C:Marco and GCD Sequence(构造) 题目链接Marco and GCD SequenceTime limit:1 seconds Memory limit:256 megabytes Problem DescriptionIn a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality a
Struts 2实现文件的上传下载(解除文件大小限制) Struts 2实现文件的上传下载上传: 下载:环境 MyEclipse 2014 Tomcat:apache-tomcat-8.0.46 JDK:1.7 Sturts版本:2.1 上传文件1.上传文件界面index.jsp<%@ page language="java" pageEncoding="utf-8"%><%@ taglib uri="/struts-t
Struts 2+Hibernate实现完整登录注册(带验证) Struts 2+Hibernate实现完整登录注册(带验证)环境 MyEclipse 2014 数据库:SQL sever 2016 Tomcat:apache-tomcat-8.0.46 JDK:1.6 Sturts版本:2.1 Hibernate版本:4.1前期准备 创建项目以后,为项目添加Sturts和Hibernate能力 连接数据库并生成
Hibernate框架连接SQL sever 2016完整详细步骤 前期准备0.所需软件:myeclipse 2014,SQL Sever Management Studio,sqljdbc4.jar1.启用协议2.打开服务2.登录SSMS建立数据库 如图:数据库名为Bookstore,有一张表为userInfo,其中列userID为主键且为标识id3.打开MyEclipse创建Web项目 创建两个包,如图(我的项目名为Ex5)创建数据库连接1.修改视图2.右键
Codeforces 888C:K-Dominant Character 题目链接K-Dominant CharacterTime limit:2 seconds Memory limit:256 megabytes Problem DescriptionYou are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each sub
Codeforces 887C:Solution for Cube(模拟) 题目链接Solution for CubeTime limit:2 seconds Memory limit:256 megabytes Problem Description During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For
Struts 2中自定义类型转换器 TypeConverter 的应用 0.建立项目建立项目并使用myeclipse自带的工具配置Struts 2。我的项目名为Ex4 1.构造模型Tel类package org.vo;public class Tel { private String sectionNo;//区号 private String telNo;//电话号 public String getSectionNo() {
(LIS)最长递增/递减子序列(带路径)模板 O(NlogN) 最长递增(非严格) //top为长度,stack中的值为路径 int top = 0,temp; stack[0] = -1; for (int i = 0; i < n; i++) { temp=a[i]; if (temp >= stack[top])
模板:线段树求区间最大/最小值及下标 #include<cstdio>#include <iostream>using namespace std;const int maxn=10010;int a[maxn];struct node{ int left,right,min,max;}num[maxn<<2];int buildmin(int left,int right,int cnt){ int mid
总结——Java大数模板应用 Java大数模板应用 在处理高精度问题和大数问题中,long long和double已经存不下了,比起在C++中自己用String手写运算过程,Java中的BigInteger类和BigDecimal类用起来就很方便了0.创建大数类import java.math.BigDecimal;import java.math.BigInteger;import java.util.Scanner
ZCMU 1985:小C的数学问题(线段树+分治) 小C的数学问题Time limit:1000ms Memory limit:128 MBProblem Description小C是个云南中医学院的大一新生,在某个星期二,他的高数老师扔给了他一个问题。 让他在1天的时间内给出答案。 但是小C不会这问题,现在他来请教你。 请你帮他解决这个问题。 有n个数,每个数有权值。 数学老师定义了区间价值为区间和乘上区间内的最小值。 现在要你找出有最
Wannafly模拟赛4:A -Laptop(后缀) 题目链接LaptopTime limit:1000ms Memory limit:262144K Problem DescriptionFST是一名可怜的小朋友,他很强,但是经常fst,所以rating一直低迷。 但是重点在于,他非常适合ACM!并在最近的区域赛中获得了不错的成绩。 拿到奖金后FST决定买一台新笔记本,但是FST发现,在价格能承受的范围内,笔记本的内存和速度是不可兼得的。 可
计蒜客:热爱工作的蒜蒜(最短路) 题目链接热爱工作的蒜蒜Time limit:1000ms Memory limit:262144K Problem Description众所周知,蒜蒜是一名热爱工作的好员工,他觉得时间就是金钱,做事情总是争分夺秒。这天晚上,蒜蒜一个人去吃晚饭。不巧的是,吃完饭以后就开始下雨了,蒜蒜并没有带雨伞出来。但是蒜蒜热爱工作,工作使他快乐,他要尽快赶回去写代码。蒜蒜的公司在中关村,中关村这边地形复杂,有很
Wannafly挑战赛1:B-Xorto(前缀+思维) XortoTime limit:1000ms Memory limit:32768K Problem Description给定一个长度为n的整数数组,问有多少对互不重叠的非空区间,使得两个区间内的数的异或和为0。Input第一行一个数n表示数组长度; 第二行n个整数表示数组; 1<=n<=1000,0<=数组元素<100000。Output一行一个整数表示答案。Sample Input30
Wannafly挑战赛1:A-Treepath(DFS或BFS) TreepathTime limit:1000ms Memory limit:32768K Problem Description给定一棵n个点的树,问其中有多少条长度为偶数的路径。路径的长度为经过的边的条数。x到y与y到x被视为同一条路径。路径的起点与终点不能相同。Input第一行一个数n表示点的个数; 接下来n-1行,每行两个整数x,y表示边; 保证输入数据形成一棵树; 1<=n<=10
hihoCoder 1338 : A Game(dp) A GameTime limit:1000ms Memory limit:256MB Problem DescriptionLittle Hi and Little Ho are playing a game. There is an integer array in front of them. They take turns (Little Ho goes first) to select a
Struts 2中<s:generator>标签的用法 将一个字符串按照指定的分隔符分割成多个字符串<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><h
Struts 2中<s:subset>标签的用法 例1下面的代码subset.jsp截取了原集合从第二个元素(start=1)开始的三个元素(count=3)<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD
Struts 2中<s:sort>标签的用法 0.建立项目建立项目并使用myeclipse自带的工具配置Struts 2。我的项目名为Ex31.创建Student类包含姓名和年龄两个属性,自动生成其getter和setter,再自己写一个构造函数package org.vo;public class Student { private String name; private int age; public Studen
Struts 2中<s:append>标签的用法 0.建立项目建立项目并使用myeclipse自带的工具配置Struts 2。我的项目名为Ex31.编写下面的append.jsp页面使用append标签合并两个param的集合,然后使用iterator标签遍历append中的内容<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib uri="/
Struts 2中<s:iterator>标签的用法 0.建立项目建立项目并使用myeclipse自带的工具配置Struts 2。我的项目名为Ex31.编写下面的iterator.jsp页面<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUBLI
Struts 2中<s:include>标签的用法 0.建立项目建立项目并使用myeclipse自带的工具配置Struts 2。我的项目名为Ex31.准备被导入的页面 includer.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib uri="/struts-tags" prefix="s" %><!DOCTYPE HTML PUB
Struts 2中<s:bean>标签的用法 0.建立项目建立项目并使用myeclipse自带的工具配置Struts 2。我的项目名为Ex31.建立一个Student类(VO)这里Student类一个有两个属性,自动生成其getter和setterpackage org.vo;public class Student { private String name; private int age; public Strin
Struts 2中<s:action>标签的用法 0.建立项目建立项目并使用myeclipse自带的工具配置Struts 2。我的项目名为Ex31.建立Action类package org.action;import com.opensymphony.xwork2.ActionSupport;public class TagAction extends ActionSupport{ public String excute() throws
POJ 1276:Cash Machine (多重背包) Cash MachineTime limit:1000 ms Memory limit:10000 kB Problem DescriptionA Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash a
SPFA算法模板 const int INF=0x3f3f3f3f;const int maxm=511111;const int maxn=111111;struct EdgeNode{ int to; int w; int next;};EdgeNode edges[maxm];int N,M;int head[maxn],edge;bool vis[maxn];queue
hihoCoder 1336:Matrix Sum(二维树状数组) Matrix SumTime limit:1000 ms Memory limit:256MB Problem DescriptionYou are given an N × N matrix. At the beginning every element is 0. Write a program supporting 2 operations:1. Add x y value: Add val
hihoCoder 1054:滑动解锁(DFS) 滑动解锁Time limit:2000 ms Memory limit:256MB Problem Description滑动解锁是智能手机一项常用的功能。你需要在3x3的点阵上,从任意一个点开始,反复移动到一个尚未经过的”相邻”的点。这些划过的点所组成的有向折线,如果与预设的折线在图案、方向上都一致,那么手机将解锁。两个点相邻当且仅当以这两个点为端点的线段上不存在尚未经过的点。此外,这条折线还需
POJ 3349:Snowflake Snow Snowflakes(Hash) Snowflake Snow SnowflakesTime limit:4000 ms Memory limit:65536 kB Problem DescriptionYou may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is
[备战软考]操作系统 操作系统操作系统进程进程的三态图进程的五态图进程死锁进程1.进程的三态图就绪状态:进程已得到运行所需资源,只等待CPU的调度便可运行;运行状态:进程已得到运行所需资源,并且得到了CPUd调度;等待状态:不具备运行条件、等待时机的状态。也称阻塞状态。2.进程的五态图就绪→运行:条件是被调度程序选中的运行→就绪:条件是时间片刻到(超时),或被更高优先级的进程剥夺运行→等待:条件是不
HDU 1016:Prime Ring Problem(基础DFS) Prime Ring ProblemTime limit:2000 ms Memory limit:65536 kB OS:Linux Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, …, n into each circle separately, an
POJ 2367:Genealogical tree (拓扑排序) Genealogical tree Time limit:1000 ms Memory limit:65536 kB OS:Linux Problem DescriptionThe system of Martians’ blood relations is confusing enough. Actually, Martians bud when they want and where they
HDU 6208:The Dominator of Strings(字符串匹配) Here you have a set of strings. A dominator is a string of the set dominating all strings else. The string S is dominated by T if S is a substring of T.The input contains several test cases and the first l
POJ 1094:Sorting It All Out (拓扑排序) Sorting It All OutTime limit:1000 ms Memory limit:65768 kB Problem DescriptionAn ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the ele
Dijkstra算法模板 Dijkstra作者:刘伟#include <iostream>#include <stdlib.h>#include <algorithm>#define MAX 100#define INF 100000using namespace std;struct Graph{ int edges[MAX][MAX]; //邻接矩阵 int n;
Kruskal算法模板 Kruskal作者:刘伟#include <iostream>#include <algorithm>using namespace std;/* 定义边(x,y),权为w */struct edge{ int x, y; int w;};const int MAX = 26;edge e[MAX * MAX];int rank[MAX];/* rank[x]表示x的秩
HDU 4007:Dave (枚举) Recently, Dave is boring, so he often walks around. He finds that some places are too crowded, for example, the ground. He couldn't help to think of the disasters happening recently. Crowded place is not safe.
[C++::STL]之stcak的用法 stack#include < stack >,堆栈这个就是咱们数据结构中学的栈,栈的操作只有几种方法声明 stack<int> s;入栈 s.push(8);出栈 s.pop();取栈顶元素(但不删除) s.pop();例题:HDU 1022:Train Problem I(堆栈的基本应用)
[C++::STL]之set的用法 set#include< set > 集合 Sets are containers that store unique elements following a specific order.类似于Java中的TreeSet,set就是数学上的集合——每个元素最多出现一次,其中的元素自动排序,自定义类型构造set时,必须定义”小于”运算符。一个集合通过一个链表来组织,在插入操作和删除操作上比向
[C++::STL]之map的用法 map#include< map > 映射,键值对容器。 map就是从键(key)到值(value)的映射。因为重载了 [ ] 运算符,map更像是数组的“高级版”。例如可以用一个map< string,int>month_name来表示“月份名字到月份编号”的映射,然后用 month_name[“July”]=7 这样的方式来赋值。类似于Python中的字典Dictionary与Java中的
[C++::STL]之vector的用法 vector#include < vector > 向量,不定长数组。 与数组的区别在于声明时不需要指定长度,vector动态分配空间(线性连续地址)。插入和删除都比数组要方便很多。vector可以直接赋值,还可以作为函数的参数或者返回值,而无须像传递数组那样用另一个变量指定元素个数。
[备战软考]数据结构与算法基础 : 数据结构与算法基础数据结构与算法基础线性表顺序表链表链表的操作顺序表与链表的比较广度优先BFS最小生成树Prim算法Kruskal算法拓扑排序关键路径线性表1.顺序表顺序的存储结构,元素在内存中以顺序存储。内存中占用连续的一个区域。顺序表的删除 把要删除的元素后面每个元素向前移动一位顺序表的插入 把要插入的位置后面的(包括自己)所有元素向后移动一位,再把要插入的元素
Count primes (模板题) Count primesTime limit:1000 ms Memory limit:65768 kB Problem DescriptionEasy question! Calculate how many primes between [1…n]!InputEach line contain one integer n(1 <= n <= 1e11).Process to end of fi
素数算法总结 素数算法总结转载自:_Wilbert 在平时做题目或者进行预算的时候,素数的出现次数总是十分频繁。今天我们就来一点一点的说一说关于素数的一些算法。素数算法总结朴素判断素数算法Miller_Rabin素性测试筛选法容斥原理Meissel-Lehmer算法朴素判断素数算法就判断素数而言,事实上是非常简单的了。根据定义,判断一个整数n是否是素数,只需要去判断在整数区间[2, n-1]之内
HDU 4006:The kth great number(数据结构?) The kth great numberTime limit:1000 ms Memory limit:65768 kB Problem DescriptionXiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask
The Frog's Games (二分) The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. T
HDU 1058:Humble Numbers (水) A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers.
HDU 1025:Constructing Roads In JGShining's Kingdom(DP) JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.
2017湖南省第十三届ACM省赛总结 2017年9月2日,我,涛哥,学弟张灿,组队参加了2017年的湖南省赛,这里写个总结,作为以后参赛的经验。经过浙江中医药大学的罗杰老师指导,比赛前我们三人做了这样的分工,涛哥经验丰富,实力最强,作为队长;我的话实力很一般,好在编程基础较为扎实,心态稳定,愿意做苦力,作为本队的主键盘手,负责模拟和简单题;而张灿知识面广,模板熟悉,主要负责图论题。当然,题目并不是按照我们预想的套路出的,所以在比赛过程
Bad Hair Day(单调栈) Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows
Equations(Hash) Consider equations having the following form: a*x1^2+b*x2^2+c*x3^2+d*x4^2=0 a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0. It is consider a solution a system ( x1,x2,x
Flying to the Mars(Hash) In the year 8888, the Earth is ruled by the PPF Empire . As the population growing , PPF needs to find more land for the newborns . Finally , PPF decides to attack Kscinow who ruling the Mars . Here the probl
The Suspects (并查集) Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate th
Virtual Friends (并查集) These days, you can do all sorts of things online. For example, you can use various websites to make virtual friends. For some people, growing their social network (their friends, their friends' friends, their
CodeForces 416C:Booking System(贪心) Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!A restaurant called "Dijkstra's Place" has started thinking about optimizing the bookin
CodeForces 607B:Zuma(区间DP) Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as po
2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP) 度度熊为了拯救可爱的公主,于是与邪恶大魔王战斗起来。邪恶大魔王的麾下有n个怪兽,每个怪兽有a[i]的生命值,以及b[i]的防御力。度度熊一共拥有m种攻击方式,第i种攻击方式,需要消耗k[i]的晶石,造成p[i]点伤害。当然,如果度度熊使用第i个技能打在第j个怪兽上面的话,会使得第j个怪兽的生命值减少p[i]-b[j],当然如果伤害小于防御,那么攻击就不会奏效。如果怪兽的生命值降为0或以下,那么怪兽就会被消灭。
POJ 1651:Multiplication Puzzle(区间DP) Multiplication PuzzleTime limit:1000 ms Memory limit:65536 kB Problem DescriptionThe multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move pla
HDU 4283:You Are the One(区间DP) The TV shows such as You Are the One has been very popular. In order to meet the need of boys who are still single, TJUT hold the show itself. The show is hold in the Small hall, so it attract a lot of boys an
POJ 2955:Brackets(区间DP) We give the following inductive definition of a “regular brackets” sequence:the empty sequence is a regular brackets sequence,if s is a regular brackets sequence, then (s) and [s] are regular brackets sequen