- 博客(87)
- 收藏
- 关注
转载 Java线程(三):线程协作-生产者/消费者问题
上一篇讲述了线程的互斥(同步),但是在很多情况下,仅仅同步是不够的,还需要线程与线程协作(通信),生产者/消费者问题是一个经典的线程同步以及通信的案例。该问题描述了两个共享固定大小缓冲区的线程,即所谓的“生产者”和“消费者”在实际运行时会发生的问题。生产者的主要作用是生成一定量的数据放到缓冲区中,然后重复此过程。与此同时,消费者也在缓冲区消耗这些数据。该问题的关键就是要保证生产者不会在缓冲区满时加...
2018-05-18 11:23:57
172
转载 Java线程(二):线程同步synchronized和volatile
上篇通过一个简单的例子说明了线程安全与不安全,在例子中不安全的情况下输出的结果恰好是逐个递增的(其实是巧合,多运行几次,会产生不同的输出结果),为什么会产生这样的结果呢,因为建立的Count对象是线程共享的,一个线程改变了其成员变量num值,下一个线程正巧读到了修改后的num,所以会递增输出。要说明线程同步问题首先要说明Java线程的两个特性,可见性和有序性。多个线程之间是不能直接传递数据交互...
2018-05-17 11:06:58
314
转载 Java线程(一):线程安全与不安全
回归正题,当我们查看JDK API的时候,总会发现一些类说明写着,线程安全或者线程不安全,比如说StringBuilder中,有这么一句,“将StringBuilder 的实例用于多个线程是不安全的。如果需要这样的同步,则建议使用StringBuffer。 ”,那么下面手动创建一个线程不安全的类,然后在多线程中使用这个类,看看有什么效果。Count.java:public class Co...
2018-05-17 10:54:19
293
原创 【OAuth2.0】认识和使用OAuth2.0附OAuth实例
1.什么是OAuth2.0OAuth是一个关于授权(authorization)的开放网络标准,在全世界得到广泛应用,目前的版本是2.0版。 OAuth(开放授权)是一个开放标准。允许第三方网站在用户授权的前提下访问在用户在服务商那里存储的各种信息。而这种授权无需将用户提供用户名和密码提供给该第三方网站。OAuth允许用户提供一个令牌给第三方网站,一个令牌对应一个特定的第三方网站,同时该令牌只能在
2017-07-12 14:28:03
14784
2
原创 【Java Web开发】认识JSP 9个内置对象和序号方法说明
1.request对象【说明】: 客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。 【序号方法说明】:objectgetAttribute(Stringname) 返回指定属性的属性值EnumerationgetAttributeNames() 返回所有可用属性名的枚举StringgetChar
2017-06-12 17:05:34
780
原创 【CodeForce 734C 】Anton and Making Potions (枚举+二分)
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.Anton has a special kettle, that can prepare one potio
2016-11-18 21:35:02
427
原创 【POJ 1860】Currency Exchange(Bellman_Ford)
DescriptionSeveral currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies.
2016-08-18 15:09:19
491
原创 【POJ 2253】Frogger(Dijkstra)
DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tou
2016-08-15 17:01:49
385
原创 【HDU 2102】A计划(BFS)
Description可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。 现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输
2016-08-15 15:17:12
439
原创 【FJNU】周赛#2题解
A.58秒95!! 【LightOJ 1028 Trailing Zeroes 】题目大意给出一个n。问存在多少个m进制( m < n )使得在m进制下末尾为0。就是求n的因子个数。思路打表10^6以内的素数,然后枚举素数代码#include<iostream>#include<cstdio>#include<string.h>#include<algorithm>#include<queu
2016-08-12 19:32:58
649
原创 【HDU 3533】Escape(BFS)
DescriptionThe students of the HEU are maneuvering for their military training. The red army and the blue army are at war today. The blue army finds that Little A is the spy of the red army, so Littl
2016-08-10 16:09:41
404
原创 【HDU 2181】哈密顿绕行世界问题(DFS)
Description一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出. Output输出从第m个城市出发经过每个城市1次又回到m的所有路线,如有多条路线,按字典序输出,每行1条路线.每行首先输出是第
2016-08-10 15:48:29
367
原创 【HDU 1043】Eight(A*启发式搜索算法)
DescriptionThe 15-puzzle has been around for over 100 years; even if you don’t know it by that name, you’ve seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and
2016-08-04 15:52:59
1536
1
原创 【HDU 2612】Find a way(BFS)
DescriptionPass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki. Yifenfei’s home i
2016-08-03 10:35:35
529
原创 【POJ 3984】迷宫问题(BFS)
Description定义一个二维数组: int maze[5][5] = {0, 1, 0, 0, 0,0, 1, 0, 1, 0,0, 0, 0, 0, 0,0, 1, 1, 1, 0,0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。Input一个5 × 5的二维数组,表示一个迷宫。数
2016-08-02 20:19:52
1290
原创 【UVA 11624】Fire!(BFS)
DescriptionJoe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s locat
2016-08-02 20:14:22
307
原创 【FZU 2150】Fire Game(BFS)
DescriptionFat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then
2016-08-02 20:02:03
609
原创 【POJ 3414】Pots(BFS)
DescriptionYou are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap; DROP(i) empt
2016-08-02 19:51:42
672
原创 【POJ 2251】Dungeon Master(BFS)
DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit no
2016-08-02 19:39:29
386
原创 【POJ 1321】棋盘问题(DFS)
Description在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <=
2016-08-02 11:01:02
1111
原创 【POJ 3087】Shuffle'm Up(BFS,模拟,)
DescriptionA common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C
2016-08-01 10:30:37
440
原创 【POJ 3126】Prime Path(枚举+BFS)
DescriptionThe ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a m
2016-07-29 20:55:07
237
原创 【POJ 3279】Fliptile(状压DP+搜索)
DescriptionFarmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15;
2016-07-29 16:10:11
442
原创 【HDU 1506】Largest Rectangle in a Histogram(DP)
Problem DescriptionA histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure
2016-07-26 20:36:15
411
1
原创 【HDU 1950】Bridging signals(LIS算法求最长上升子序列)
Problem Description‘Oh no, they’ve done it again’, cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip con
2016-07-26 20:25:45
356
原创 【LightOJ 1013】Love Calculator(LCS+DP)
Problem DescriptionYes, 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 wil
2016-07-26 20:17:06
437
原创 【HDU 1159】Common Subsequence(最长公共序列LCS算法)
Problem DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = Sample Inputabcfbc abfcab programming contest abcd mnpSam
2016-07-26 09:26:30
400
原创 【HDU 1231】最大连续子序列(DP)
Problem Description给定K个整数的序列{ N1, N2, …, NK },其任意连续子序列可表示为{ Ni, Ni+1, …, Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个, 例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和 为20。 在今年
2016-07-25 21:25:43
386
1
原创 【HDU 1422】重温世界杯(DP)
Problem Description世界杯结束了,意大利人连本带利的收回了法国人6年前欠他们的债,捧起了大力神杯,成就了4星意大利. 世界杯虽然结束了,但是这界世界杯给我们还是留下许多值得回忆的东西.比如我们听到了黄名嘴的3分钟激情解说,我们懂得了原来可以向同一个人出示3张黄牌,我们还看到了齐达内的头不仅能顶球还能顶人………… 介于有这么多的精彩,xhd决定重温德国世界杯,当然只是去各个承办世
2016-07-25 21:16:07
331
原创 【HDU 2191】 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包)
Problem Description急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。 请问:你用有限的资金最多能采购多少公斤粮食呢?后记: 人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。 月有阴晴圆缺,人有旦夕祸福
2016-07-25 21:07:17
260
原创 【HDU 2602】Bone Collector(01背包)
Problem DescriptionMany years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …
2016-07-25 21:02:42
288
原创 【HDU 1069】Monkey and Banana(DP)
DescriptionA group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. I
2016-07-25 16:52:34
311
原创 【POJ 2533】Longest Ordered Subsequence(最长上升子序列LIS)
DescriptionA numeric sequence of ai is ordered if a1 < a2 < … < aN. Let the subsequence of the given numeric sequence ( a1, a2, …, aN) be any sequence ( ai1, ai2, …, aiK), where 1 <= i1 < i2 < … < iK <
2016-07-22 21:17:58
323
原创 【HDU 1025】Constructing Roads In JGShining's Kingdom(最长上升子序列LIS)
DescriptionJGShining’s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities are rich in resource (we call them rich cities) while
2016-07-22 21:14:53
457
原创 【HDU 1024】Max Sum Plus Plus(DP+滚动数组优化+最大m段字段之和)
DescriptionNow I think you have got an AC in Ignatius.L’s “Max Sum” problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult probl
2016-07-22 16:16:55
508
原创 【HDU 1231】最大连续子序列(DP)
Description给定K个整数的序列{ N1, N2, …, NK },其任意连续子序列可表示为{ Ni, Ni+1, …, Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个, 例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和 为20。 在今年的数据结构考卷中
2016-07-22 10:51:52
502
原创 【POJ 3259】Wormholes(最短路SPFA/Bellman_Ford)
DescriptionWhile exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a t
2016-07-21 21:31:29
1134
原创 【POJ 3268】Silver Cow Party(邻接矩阵+优先队列优化+dij)
DescriptionOne cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (
2016-07-21 21:22:16
700
原创 【POJ 2502】Subway(最短路dij)
DescriptionYou have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you d
2016-07-21 21:13:15
516
原创 【POJ 1797】Heavy Transportation(最短路dij)
DescriptionBackground Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the pl
2016-07-21 21:04:30
372
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人