自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(32)
  • 收藏
  • 关注

原创 51nod 1007 正整数分组(类背包)

1007 正整数分组基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注将一堆正整数分为2组,要求2组的和相差最小。例如:1 2 3 4 5,将1 2 4分为1组,3 5分为1组,两组和相差1,是所有方案中相差最少的。Input第1行:一个数N,N为正整数的

2017-08-31 09:58:11 246

原创 算法模板之01背包问题

二维数组的写法:int w[N],p[N];int dp[M][N];for(int i=0; i<n; i++) for(int j=0; j<=m; j++) if(j<w[i]) dp[i+1][j]=dp[i][j]; else dp[i+1][j]=max(dp[i][j],dp[i][j-w

2017-08-29 16:46:01 355

原创 51nod 1050 循环数组的最大子段和

动态规划修改 隐藏话题1050 循环数组最大子段和基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连续的子段和的最大值(循环序列是指n个数围成一个圈

2017-08-29 10:10:12 393

原创 51nod 1010 只包含因子2 3 5的数(预处理+二分)

1010 只包含因子2 3 5的数基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注K的因子中只包含2 3 5。满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15。所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数。例如:n = 13,S中 >= 13的最小

2017-08-28 17:06:26 296

原创 lightoj 1024 - Eid (高精度乘法+n个数的最小公倍数)

1024 - Eid   PDF (English)StatisticsForumTime Limit: 2 second(s)Memory Limit: 32 MBIn a strange planet there are n races. They are completely differen

2017-08-28 16:28:16 395

原创 算法模板之次短路

给你N个点和R条边,问从起点到终点的次短路是多少。无向边,且可重复走。#include #include #include #include #define MAXN 100009#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;struct edge{ int to, cost;

2017-08-24 15:20:07 770

原创 lightoj1017 Brush (III) (dp)

1017 - Brush (III)   PDF (English)StatisticsForumTime Limit: 2 second(s)Memory Limit: 32 MBSamir returned home from the contest and got angry after se

2017-08-24 09:45:52 240

原创 lightoj 1013 Love Calculator (LCS+dp)

Yes, you are developing a 'Love calculator'. The software would be quite complex such that nobody could crack the exact behavior of the software.So, given two names your software will generate the p

2017-08-23 16:27:26 292

原创 算法模板之KM(带权的二分匹配)

KM模板(带权的二分匹配)int vx[N],vy[N],lx[N],ly[N],link[N],mat[N][N];int n;int dfs(int t){ int i; vx[t]=1; for(i=1; i<=n; i++) { if(vy[i]==0&&lx[t]+ly[i]==mat[t][i]) {

2017-08-22 21:05:36 274

原创 算法模板之二分匹配

二分匹配模板:int m,n;int used[N],link[N],mat[N][N];int dfs(int t){ int i; for(i=1; i<=n; i++) { if(used[i]==0&&mat[t][i]) { used[i]=1; if(link[i]==0|

2017-08-22 21:02:28 203

原创 lightoj 1011 Marriage Ceremonies (KM模板题)

You work in a company which organizes marriages. Marriages are not that easy to be made, so, the job is quite hard for you.The job gets more difficult when people come here and give their bio-data w

2017-08-22 20:59:05 256

原创 算法模板之并查集

int f[N];int Find(int x){ if(x==f[x]) return x; f[x]=Find(f[x]); return f[x];}void Union(int a,int b){ int ta=Find(a); int tb=Find(b); if(ta!=tb) f[ta]=tb

2017-08-22 16:09:56 224

原创 hihoCoder 1515 分数调查(带权并查集)

时间限制:10000ms单点时限:1000ms内存限制:256MB描述小Hi的学校总共有N名学生,编号1-N。学校刚刚进行了一场全校的古诗文水平测验。  学校没有公布测验的成绩,所以小Hi只能得到一些小道消息,例如X号同学的分数比Y号同学的分数高S分。  小Hi想知道利用这些消息,能不能判断出某两位同学之间的分数高低? 输入第一行包含三个整数N,

2017-08-22 16:06:54 287

原创 poj 1703 Find them, Catch them(种类并查集)

The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which g

2017-08-22 16:02:19 200

原创 lightoj 1009 Back to Underworld (种类并查集)

The Vampires and Lykans are fighting each other to death. The war has become so fierce that, none knows who will win. The humans want to know who will survive finally. But humans are afraid of going t

2017-08-22 15:58:40 251

原创 light oj 1008 Fibsieve`s Fantabulous Birthday (规律)

Fibsieve had a fantabulous (yes, it's an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.Among these gifts there was an N x

2017-08-21 18:47:12 221

原创 算法模板之欧拉函数

欧拉函数用希腊字母φ表示,φ(N)表示N的欧拉函数.对φ(N)的值,我们可以通俗地理解为小于N且与N互质的数的个数(包含1).下面两种方法求欧拉函数值,一种直接算出来的,另一种是通过筛选得来的。#define N 5000000+10typedef unsigned long long ll;ll Euler[N];ll init(int n)//根据定义直接算{

2017-08-21 17:33:19 214

原创 light oj 1007 Mathematically Hard (欧拉函数)

Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable.In this problem, you will be given two integers a and b. You have to find the summat

2017-08-21 17:27:07 214

原创 算法模板之组合数(小范围)

小范围的组合数,大概能算到30左右吧typedef long long ll;ll C[61][61];void init(){ memset(dp,0,sizeof(dp)); for(int i=1; i<=60; i++) { C[i][1]=i; C[i][0]=1; } for(int i=1; i<=

2017-08-21 15:22:28 209

原创 light oj 1005 Rooks(组合数)

A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move vertically or horizontally from its current position and two rooks attack each other if one

2017-08-21 15:15:10 277

原创 算法模板之RMQ

给定原序列和若干个区间,查询区间的最大值或者最小值。int dp[N][30],a[N];void rmq_init(int n){ for(int i=1; i<=n; i++) dp[i][0]=a[i]; for(int j=1; (1<<j)<=n; j++) for(int i=1; i+(1<<j)-1<=n; i++)

2017-08-20 15:29:52 206

原创 算法模板之拓扑排序

给定很多事件,做这些事件有先后顺序,输出合理的顺序。判断有向图是否存在环。int c[N],t,ans[N],n,m;vectorG[N];bool dfs(int u){ c[u]=-1; for(int i=0;i<G[u].size();i++) { if(c[G[u][i]]<0) return fa

2017-08-20 15:24:38 193

原创 hihoCoder 1558 H国的身份证号码I(dfs)

时间限制:10000ms单点时限:1000ms内存限制:256MB描述H国的身份证号码是一个N位的正整数(首位不能是0)。此外,由于防伪需要,一个N位正整数是合法的身份证号码当且仅当每位数字都小于等于K,并且任意相邻两位数字的乘积也小于等于K。例如对于K=5, 101、211、210等都是合法的号码,而106、123、421等都是非法的号码。给定一个正整

2017-08-20 15:08:17 862 2

原创 hihocoder 1323 回文字符串

时间限制:10000ms单点时限:1000ms内存限制:256MB描述给定一个字符串 S ,最少需要几次增删改操作可以把 S 变成一个回文字符串?一次操作可以在任意位置插入一个字符,或者删除任意一个字符,或者把任意一个字符修改成任意其他字符。 输入字符串 S。S 的长度不超过100, 只包含'A'-'Z'。输出最少的修改次数。样例输入

2017-08-17 21:02:00 461

原创 构造回文字符串

回文字符串时间限制:3000 ms  |  内存限制:65535 KB难度:4描述 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba"。当然,我们给你的问题不会再简单到判断一个字符串是不是回文字符串。现在要求你,给你一个字符串,可在任意位置添加字符,最少再添加几个字符,可以使这个字符串成为回文字符串。输入第一行给出整数N(0接下来的N行,每行

2017-08-17 20:10:41 1172

原创 51nod 1013 3的幂的和(快速幂+乘法逆元)

题目所给式子是个等比数列,利用等比数列求和公式,化简可得,求和的表达式为 ((3^(n+1)-1)/2)%Mod,注意题目所给下标从0开始。n的范围很大很大,所以应当用快速幂来计算。但是快速幂取模是只能进行乘法的同余取模,涉及到除以2,有除法运算,不能用同余定理那样来解决。所以应该将除法转换为乘法逆元。除以一个数取余就等于乘上这个数的逆元再取余,由此转换为乘法间的取余运算就可以用快速幂了#

2017-08-17 18:21:55 260

原创 算法模板之快速幂取模

求x的n次方对mod取余,利用快速幂来计算,降低时间复杂度。typedef long long LL;LL quick_mod(LL x,LL n){ LL res=1; while(n>0) { if(n & 1) res=(res*x)%Mod; x=(x*x)%Mod; n >>= 1;

2017-08-17 18:12:48 246

原创 百度之星初赛B 1002 Factory

Problem Description我们将A省简化为由N个城市组成,某些城市之间存在双向道路,而且A省的交通有一个特点就是任意两个城市之间都能通过道路相互到达,且在不重复经过城市的情况下任意两个城市之间的到达方案都是唯一的。聪明的你一定已经发现,这些城市构成了树这样一个结构。现在百度陆续开了许许多多的子公司。每家子公司又会在各城市中不断兴建属于该子公司的办公室。由于各个子公司

2017-08-14 20:39:45 269 1

原创 算法模板之最近公共祖先问题(LCA)

poj1330最近公共祖先问题模板:#include#include#include#include#include#include#include#include#define N 30000using namespace std;int id[N],vis[N],depth[N],in[N],dp[N][20],k;vectorG[N];int Min(

2017-08-10 17:34:19 271

原创 hdu 3183 A Magic Lamp(RMQ)

Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question, and then the genie will realize one of her dreams.The questio

2017-08-09 16:21:52 225

原创 hdu 1595 find the longest of the shortest

Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she doesn't live in the same city, she started preparing for the long journey.We know for every road how m

2017-08-02 14:17:52 206

原创 基于vector的邻接表解决最短路稀疏图的问题

在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?Input 输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是赛

2017-08-01 09:15:40 583

空空如也

空空如也

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

TA关注的人

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