快要毕业了。近期在阿里巴巴校园招聘面试,一面过了,感觉挺轻松,可能是运气好。面试官感觉比我腼腆一些。我俩从android绕到了spring mvc 到数据库悲观锁 到linux 然后又会到了android。这个面试收获挺大。多线程方面还得加强一下。但好在的是跟面试官谈了半个多小时源代码,可能这一点比較加分。继续准备二面。分析一些源代码吧

  1. public abstract class AsyncTask<Params, Progress, Result> {
  2. private static final String LOG_TAG = "AsyncTask";
  3.  
  4. //定义线程池的最小数量
  5. private static final int CORE_POOL_SIZE = 5;
  6. //定义线程池的最大数量
  7. private static final int MAXIMUM_POOL_SIZE = 128;
  8. //设置线程存活时间
  9. private static final int KEEP_ALIVE = 1;
  10.  
  11. //定义自己的线程创建project
  12. private static final ThreadFactory sThreadFactory = new ThreadFactory() {
  13. private final AtomicInteger mCount = new AtomicInteger(1);
  14.  
  15. public Thread newThread(Runnable r) {
  16. return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
  17. }
  18. };
  19.  
  20. //定义一个线程工作队列。当超过十个线程的工作的时候会导致堵塞效果
  21. private static final BlockingQueue<Runnable> sPoolWorkQueue =
  22. new LinkedBlockingQueue<Runnable>(10);
  23.  
  24. //主要使用来运行任务
  25. public static final Executor THREAD_POOL_EXECUTOR
  26. = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
  27. TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory);
  28.  
  29. /**
  30. * An {@link Executor} that executes tasks one at a time in serial
  31. * order. This serialization is global to a particular process.
  32. */
  33. //定义自己实现的一个Executor,在里面实现自己的一个ArrayDeque双端队列
  34. public static final Executor SERIAL_EXECUTOR = new SerialExecutor();
  35.  
  36. private static final int MESSAGE_POST_RESULT = 0x1;
  37. private static final int MESSAGE_POST_PROGRESS = 0x2;
  38. //实现一个自己的handler
  39. private static final InternalHandler sHandler = new InternalHandler();
  40.  
  41. private static volatile Executor sDefaultExecutor = SERIAL_EXECUTOR;
  42. //实现了Callable的一个抽象类。在里面封装
  43. private final WorkerRunnable<Params, Result> mWorker;
  44. //採用future模式运行任务
  45. private final FutureTask<Result> mFuture;
  46.  
  47. private volatile Status mStatus = Status.PENDING;
  48.  
  49. private final AtomicBoolean mTaskInvoked = new AtomicBoolean();
  50.  
  51. private static class SerialExecutor implements Executor {
  52. final ArrayDeque<Runnable> mTasks = new ArrayDeque<Runnable>();
  53. Runnable mActive;
  54.  
  55. //往队列里面提交runnable对象,然后调用scheduleNext去运行mActive , 开启一个线程,然后通过同步调用去运行一个runnable对象
  56. public synchronized void execute(final Runnable r) {
  57. mTasks.offer(new Runnable() {
  58. public void run() {
  59. try {
  60. r.run();
  61. } finally {
  62. scheduleNext();
  63. }
  64. }
  65. });
  66. if (mActive == null) {
  67. scheduleNext();
  68. }
  69. }
  70.  
  71. protected synchronized void scheduleNext() {
  72. if ((mActive = mTasks.poll()) != null) {
  73. THREAD_POOL_EXECUTOR.execute(mActive);
  74. }
  75. }
  76. }
  77.  
  78. /**
  79. * Indicates the current status of the task. Each status will be set only once
  80. * during the lifetime of a task.
  81. */
  82. public enum Status {
  83. /**
  84. * Indicates that the task has not been executed yet.
  85. */
  86. PENDING,
  87. /**
  88. * Indicates that the task is running.
  89. */
  90. RUNNING,
  91. /**
  92. * Indicates that {@link AsyncTask#onPostExecute} has finished.
  93. */
  94. FINISHED,
  95. }
  96.  
  97. /** @hide Used to force static handler to be created. */
  98. public static void init() {
  99. sHandler.getLooper();
  100. }
  101.  
  102. //设置自己的一个Executor对象,否则就採用系统默认的
  103. /** @hide */
  104. public static void setDefaultExecutor(Executor exec) {
  105. sDefaultExecutor = exec;
  106. }
  107. //初始化一个AsyncTask对象
  108. public AsyncTask() {
  109. //初始化一个Callable对象 实现call方法,而且设置mTaskInvoked为true 设置线程级别为后台线程
  110. //然后去调用子类实现的doInBackground来完毕耗时操作,完毕之后在调用postResult来发送消息给自己定义的hadnler
  111. mWorker = new WorkerRunnable<Params, Result>() {
  112. public Result call() throws Exception {
  113. mTaskInvoked.set(true);
  114.  
  115. Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
  116. return postResult(doInBackground(mParams));
  117. }
  118. };
  119.  
  120. //实现自己的FutureTask done方法 当此任务转换到状态 isDone(无论是正常地还是通过取消)时,调用受保护的方法
  121. mFuture = new FutureTask<Result>(mWorker) {
  122. @Override
  123. protected void done() {
  124. try {
  125. final Result result = get();
  126.  
  127. postResultIfNotInvoked(result);
  128. } catch (InterruptedException e) {
  129. android.util.Log.w(LOG_TAG, e);
  130. } catch (ExecutionException e) {
  131. throw new RuntimeException("An error occured while executing doInBackground()",
  132. e.getCause());
  133. } catch (CancellationException e) {
  134. postResultIfNotInvoked(null);
  135. } catch (Throwable t) {
  136. throw new RuntimeException("An error occured while executing "
  137. + "doInBackground()", t);
  138. }
  139. }
  140. };
  141. }
  142.  
  143. private void postResultIfNotInvoked(Result result) {
  144. final boolean wasTaskInvoked = mTaskInvoked.get();
  145. if (!wasTaskInvoked) {
  146. postResult(result);
  147. }
  148. }
  149.  
  150. //把result通过handler发送出去
  151. private Result postResult(Result result) {
  152. Message message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
  153. new AsyncTaskResult<Result>(this, result));
  154. message.sendToTarget();
  155. return result;
  156. }
  157.  
  158. /**
  159. * Returns the current status of this task.
  160. *
  161. * @return The current status.
  162. */
  163. public final Status getStatus() {
  164. return mStatus;
  165. }
  166.  
  167. /**
  168. * Override this method to perform a computation on a background thread. The
  169. * specified parameters are the parameters passed to {@link #execute}
  170. * by the caller of this task.
  171. *
  172. * This method can call {@link #publishProgress} to publish updates
  173. * on the UI thread.
  174. *
  175. * @param params The parameters of the task.
  176. *
  177. * @return A result, defined by the subclass of this task.
  178. *
  179. * @see #onPreExecute()
  180. * @see #onPostExecute
  181. * @see #publishProgress
  182. */
  183. //运行后台任务的方法
  184. protected abstract Result doInBackground(Params... params);
  185.  
  186. /**
  187. * Runs on the UI thread before {@link #doInBackground}.
  188. *
  189. * @see #onPostExecute
  190. * @see #doInBackground
  191. */
  192. //在运行doInBackground之前调用的
  193. protected void onPreExecute() {
  194. }
  195.  
  196. /**
  197. * <p>Runs on the UI thread after {@link #doInBackground}. The
  198. * specified result is the value returned by {@link #doInBackground}.</p>
  199. *
  200. * <p>This method won't be invoked if the task was cancelled.</p>
  201. *
  202. * @param result The result of the operation computed by {@link #doInBackground}.
  203. *
  204. * @see #onPreExecute
  205. * @see #doInBackground
  206. * @see #onCancelled(Object)
  207. */
  208. @SuppressWarnings({"UnusedDeclaration"})
  209. protected void onPostExecute(Result result) {
  210. }
  211.  
  212. /**
  213. * Runs on the UI thread after {@link #publishProgress} is invoked.
  214. * The specified values are the values passed to {@link #publishProgress}.
  215. *
  216. * @param values The values indicating progress.
  217. *
  218. * @see #publishProgress
  219. * @see #doInBackground
  220. */
  221. //进度刷新时候调用。在这里能够进行ui更新
  222. @SuppressWarnings({"UnusedDeclaration"})
  223. protected void onProgressUpdate(Progress... values) {
  224. }
  225.  
  226. /**
  227. * <p>Runs on the UI thread after {@link #cancel(boolean)} is invoked and
  228. * {@link #doInBackground(Object[])} has finished.</p>
  229. *
  230. * <p>The default implementation simply invokes {@link #onCancelled()} and
  231. * ignores the result. If you write your own implementation, do not call
  232. * <code>super.onCancelled(result)</code>.</p>
  233. *
  234. * @param result The result, if any, computed in
  235. * {@link #doInBackground(Object[])}, can be null
  236. *
  237. * @see #cancel(boolean)
  238. * @see #isCancelled()
  239. */
  240. @SuppressWarnings({"UnusedParameters"})
  241. protected void onCancelled(Result result) {
  242. onCancelled();
  243. }
  244.  
  245. /**
  246. * <p>Applications should preferably override {@link #onCancelled(Object)}.
  247. * This method is invoked by the default implementation of
  248. * {@link #onCancelled(Object)}.</p>
  249. *
  250. * <p>Runs on the UI thread after {@link #cancel(boolean)} is invoked and
  251. * {@link #doInBackground(Object[])} has finished.</p>
  252. *
  253. * @see #onCancelled(Object)
  254. * @see #cancel(boolean)
  255. * @see #isCancelled()
  256. */
  257. protected void onCancelled() {
  258. }
  259.  
  260. /**
  261. * Returns <tt>true</tt> if this task was cancelled before it completed
  262. * normally. If you are calling {@link #cancel(boolean)} on the task,
  263. * the value returned by this method should be checked periodically from
  264. * {@link #doInBackground(Object[])} to end the task as soon as possible.
  265. *
  266. * @return <tt>true</tt> if task was cancelled before it completed
  267. *
  268. * @see #cancel(boolean)
  269. */
  270. public final boolean isCancelled() {
  271. return mFuture.isCancelled();
  272. }
  273.  
  274. /**
  275. * <p>Attempts to cancel execution of this task. This attempt will
  276. * fail if the task has already completed, already been cancelled,
  277. * or could not be cancelled for some other reason. If successful,
  278. * and this task has not started when <tt>cancel</tt> is called,
  279. * this task should never run. If the task has already started,
  280. * then the <tt>mayInterruptIfRunning</tt> parameter determines
  281. * whether the thread executing this task should be interrupted in
  282. * an attempt to stop the task.</p>
  283. *
  284. * <p>Calling this method will result in {@link #onCancelled(Object)} being
  285. * invoked on the UI thread after {@link #doInBackground(Object[])}
  286. * returns. Calling this method guarantees that {@link #onPostExecute(Object)}
  287. * is never invoked. After invoking this method, you should check the
  288. * value returned by {@link #isCancelled()} periodically from
  289. * {@link #doInBackground(Object[])} to finish the task as early as
  290. * possible.</p>
  291. *
  292. * @param mayInterruptIfRunning <tt>true</tt> if the thread executing this
  293. * task should be interrupted; otherwise, in-progress tasks are allowed
  294. * to complete.
  295. *
  296. * @return <tt>false</tt> if the task could not be cancelled,
  297. * typically because it has already completed normally;
  298. * <tt>true</tt> otherwise
  299. *
  300. * @see #isCancelled()
  301. * @see #onCancelled(Object)
  302. */
  303. public final boolean cancel(boolean mayInterruptIfRunning) {
  304. return mFuture.cancel(mayInterruptIfRunning);
  305. }
  306.  
  307. /**
  308. * Waits if necessary for the computation to complete, and then
  309. * retrieves its result.
  310. *
  311. * @return The computed result.
  312. *
  313. * @throws CancellationException If the computation was cancelled.
  314. * @throws ExecutionException If the computation threw an exception.
  315. * @throws InterruptedException If the current thread was interrupted
  316. * while waiting.
  317. */
  318. public final Result get() throws InterruptedException, ExecutionException {
  319. return mFuture.get();
  320. }
  321.  
  322. /**
  323. * Waits if necessary for at most the given time for the computation
  324. * to complete, and then retrieves its result.
  325. *
  326. * @param timeout Time to wait before cancelling the operation.
  327. * @param unit The time unit for the timeout.
  328. *
  329. * @return The computed result.
  330. *
  331. * @throws CancellationException If the computation was cancelled.
  332. * @throws ExecutionException If the computation threw an exception.
  333. * @throws InterruptedException If the current thread was interrupted
  334. * while waiting.
  335. * @throws TimeoutException If the wait timed out.
  336. */
  337. public final Result get(long timeout, TimeUnit unit) throws InterruptedException,
  338. ExecutionException, TimeoutException {
  339. return mFuture.get(timeout, unit);
  340. }
  341.  
  342. /**
  343. * Executes the task with the specified parameters. The task returns
  344. * itself (this) so that the caller can keep a reference to it.
  345. *
  346. * <p>Note: this function schedules the task on a queue for a single background
  347. * thread or pool of threads depending on the platform version. When first
  348. * introduced, AsyncTasks were executed serially on a single background thread.
  349. * Starting with {@link android.os.Build.VERSION_CODES#DONUT}, this was changed
  350. * to a pool of threads allowing multiple tasks to operate in parallel. After
  351. * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, it is planned to change this
  352. * back to a single thread to avoid common application errors caused
  353. * by parallel execution. If you truly want parallel execution, you can use
  354. * the {@link #executeOnExecutor} version of this method
  355. * with {@link #THREAD_POOL_EXECUTOR}; however, see commentary there for warnings on
  356. * its use.
  357. *
  358. * <p>This method must be invoked on the UI thread.
  359. *
  360. * @param params The parameters of the task.
  361. *
  362. * @return This instance of AsyncTask.
  363. *
  364. * @throws IllegalStateException If {@link #getStatus()} returns either
  365. * {@link AsyncTask.Status#RUNNING} or {@link AsyncTask.Status#FINISHED}.
  366. */
  367. public final AsyncTask<Params, Progress, Result> execute(Params... params) {
  368. return executeOnExecutor(sDefaultExecutor, params);
  369. }
  370.  
  371. /**
  372. * Executes the task with the specified parameters. The task returns
  373. * itself (this) so that the caller can keep a reference to it.
  374. *
  375. * <p>This method is typically used with {@link #THREAD_POOL_EXECUTOR} to
  376. * allow multiple tasks to run in parallel on a pool of threads managed by
  377. * AsyncTask, however you can also use your own {@link Executor} for custom
  378. * behavior.
  379. *
  380. * <p><em>Warning:</em> Allowing multiple tasks to run in parallel from
  381. * a thread pool is generally <em>not</em> what one wants, because the order
  382. * of their operation is not defined. For example, if these tasks are used
  383. * to modify any state in common (such as writing a file due to a button click),
  384. * there are no guarantees on the order of the modifications.
  385. * Without careful work it is possible in rare cases for the newer version
  386. * of the data to be over-written by an older one, leading to obscure data
  387. * loss and stability issues. Such changes are best
  388. * executed in serial; to guarantee such work is serialized regardless of
  389. * platform version you can use this function with {@link #SERIAL_EXECUTOR}.
  390. *
  391. * <p>This method must be invoked on the UI thread.
  392. *
  393. * @param exec The executor to use. {@link #THREAD_POOL_EXECUTOR} is available as a
  394. * convenient process-wide thread pool for tasks that are loosely coupled.
  395. * @param params The parameters of the task.
  396. *
  397. * @return This instance of AsyncTask.
  398. *
  399. * @throws IllegalStateException If {@link #getStatus()} returns either
  400. * {@link AsyncTask.Status#RUNNING} or {@link AsyncTask.Status#FINISHED}.
  401. */
  402. public final AsyncTask<Params, Progress, Result> executeOnExecutor(Executor exec,
  403. Params... params) {
  404. if (mStatus != Status.PENDING) {
  405. switch (mStatus) {
  406. case RUNNING:
  407. throw new IllegalStateException("Cannot execute task:"
  408. + " the task is already running.");
  409. case FINISHED:
  410. throw new IllegalStateException("Cannot execute task:"
  411. + " the task has already been executed "
  412. + "(a task can be executed only once)");
  413. }
  414. }
  415.  
  416. mStatus = Status.RUNNING;
  417.  
  418. onPreExecute();
  419.  
  420. mWorker.mParams = params;
  421. exec.execute(mFuture);
  422.  
  423. return this;
  424. }
  425.  
  426. /**
  427. * Convenience version of {@link #execute(Object...)} for use with
  428. * a simple Runnable object.
  429. */
  430. public static void execute(Runnable runnable) {
  431. sDefaultExecutor.execute(runnable);
  432. }
  433.  
  434. /**
  435. * This method can be invoked from {@link #doInBackground} to
  436. * publish updates on the UI thread while the background computation is
  437. * still running. Each call to this method will trigger the execution of
  438. * {@link #onProgressUpdate} on the UI thread.
  439. *
  440. * {@link #onProgressUpdate} will note be called if the task has been
  441. * canceled.
  442. *
  443. * @param values The progress values to update the UI with.
  444. *
  445. * @see #onProgressUpdate
  446. * @see #doInBackground
  447. */
  448. protected final void publishProgress(Progress... values) {
  449. if (!isCancelled()) {
  450. sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
  451. new AsyncTaskResult<Progress>(this, values)).sendToTarget();
  452. }
  453. }
  454.  
  455. private void finish(Result result) {
  456. if (isCancelled()) {
  457. onCancelled(result);
  458. } else {
  459. onPostExecute(result);
  460. }
  461. mStatus = Status.FINISHED;
  462. }
  463.  
  464. //定义自己的handler
  465. private static class InternalHandler extends Handler {
  466. @SuppressWarnings({"unchecked", "RawUseOfParameterizedType"})
  467. @Override
  468. public void handleMessage(Message msg) {
  469. AsyncTaskResult result = (AsyncTaskResult) msg.obj;
  470. switch (msg.what) {
  471. case MESSAGE_POST_RESULT:
  472. // There is only one result
  473. result.mTask.finish(result.mData[0]);
  474. break;
  475. case MESSAGE_POST_PROGRESS:
  476. result.mTask.onProgressUpdate(result.mData);
  477. break;
  478. }
  479. }
  480. }
  481.  
  482. private static abstract class WorkerRunnable<Params, Result> implements Callable<Result> {
  483. Params[] mParams;
  484. }
  485.  
  486. @SuppressWarnings({"RawUseOfParameterizedType"})
  487. private static class AsyncTaskResult<Data> {
  488. final AsyncTask mTask;
  489. final Data[] mData;
  490.  
  491. AsyncTaskResult(AsyncTask task, Data... data) {
  492. mTask = task;
  493. mData = data;
  494. }
  495. }
  496. }

以上是源代码大概一些方法的意思,关于AsyncTask的运行步骤例如以下

1.当我们在new 自己的异步任务时候会初始化实例化两个类WorkerRunnable 。FutureTask,而且重写WorkerRunnable call方法和FutureTask的done方法。

2.call方法主要运行子类复写的doInBackground,然后调用 postResult显示数据,在postResult里面去调用handler发送数据然后调用finish方法去调用子类的onPostExecute方法,这个时候我们就能够在自己复写的onPostExecute进行ui更新

3.我们须要调用自己异步任务对象的execute方法。execute去调用executeOnExecutor方法在这种方法里面首先会调用onPreExecute();这种方法主要是在doInBackground。方法之前进行调用,做一些初始化工作的,有必要的时候就进行重写就可以,方法里面并没有不论什么代码。第二步会设置mWorker的mParams为我们调用execute时候传进来的參数,最后通过系统默认的Executor 去运行我们自己定义的FutureTask,从而运行WorkerRunnable call方法的代码。

事实上感觉整个一个类的实现都很的简单,并不复杂

AsyncTask源代码解析的更多相关文章

  1. Android源代码解析之(三)--&gt;异步任务AsyncTask

    转载请标明出处:一片枫叶的专栏 上一篇文章中我们解说了android中的异步消息机制. 主要解说了Handler对象的使用方式.消息的发送流程等.android的异步消息机制是android中多任务处 ...

  2. Android源代码解析之(四)--&gt;HandlerThread

    转载请标明出处:一片枫叶的专栏 上一篇文章中我们解说了AsyncTast的基本使用以及实现原理,我们知道AsyncTask内部是通过线程池和Handler实现的.通过对线程池和handler的封装实现 ...

  3. Android源代码解析之(六)--&gt;Log日志

    转载请标明出处:一片枫叶的专栏 首先说点题外话,对于想学android framework源代码的同学,事实上能够在github中fork一份,详细地址:platform_frameworks_bas ...

  4. Android源代码解析之(七)--&gt;LruCache缓存类

    转载请标明出处:一片枫叶的专栏 android开发过程中常常会用到缓存.如今主流的app中图片等资源的缓存策略通常是分两级.一个是内存级别的缓存,一个是磁盘级别的缓存. 作为android系统的维护者 ...

  5. Android源代码解析之(十三)--&gt;apk安装流程

    转载请标明出处:一片枫叶的专栏 上一篇文章中给大家分析了一下android系统启动之后调用PackageManagerService服务并解析系统特定文件夹.解析apk文件并安装的过程,这个安装过程实 ...

  6. Spring源代码解析

    Spring源代码解析(一):IOC容器:http://www.iteye.com/topic/86339 Spring源代码解析(二):IoC容器在Web容器中的启动:http://www.itey ...

  7. Arrays.sort源代码解析

    Java Arrays.sort源代码解析 Java Arrays中提供了对所有类型的排序.其中主要分为Primitive(8种基本类型)和Object两大类. 基本类型:采用调优的快速排序: 对象类 ...

  8. Spring源代码解析(收藏)

    Spring源代码解析(收藏)   Spring源代码解析(一):IOC容器:http://www.iteye.com/topic/86339 Spring源代码解析(二):IoC容器在Web容器中的 ...

  9. volley源代码解析(七)--终于目的之Response&lt;T&gt;

    在上篇文章中,我们终于通过网络,获取到了HttpResponse对象 HttpResponse是android包里面的一个类.然后为了更高的扩展性,我们在BasicNetwork类里面看到.Volle ...

随机推荐

  1. 解决Failed with error: unable to access 'https://git.coding.net/chenmi1234/lianpos.git/': Couldn't resolve host 'git.coding.net'

    代码改变世界 github push 出现问题 Failed with error: unable to access 'https://git.coding.net/chenmi1234/lianp ...

  2. Problem 1004: 蛤玮打扫教室(区间覆盖端点记录)

    Problem 1004: 蛤玮打扫教室 Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  %l ...

  3. 【库存】NOI笔试习题集

    https://wenku.baidu.com/view/2dc9d10854270722192e453610661ed9ad5155ba.html

  4. Caused by: java.io.FileNotFoundException: class path resource

    异常: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.c ...

  5. [AHOI2008]逆序对(dp)

    小可可和小卡卡想到Y岛上旅游,但是他们不知道Y岛有多远.好在,他们找到一本古老的书,上面是这样说的: 下面是N个正整数,每个都在1~K之间.如果有两个数A和B,A在B左边且A大于B,我们就称这两个数为 ...

  6. docker基础——自定义镜像、创建私有仓库、查看 docker 运行状态

    一.自定义镜像 1,案例1 要求:请自定义一个 docker 镜像,基于 hub.c.163.com/library/centos,要求创建出来的镜像在生成容器的时候,可以直接使用 ifconfig ...

  7. 在Ubuntu / Ubuntu Kylin下安装和卸载 Nodepadqq

    在Ubuntu / Ubuntu Kylin下安装和卸载 Nodepadqq         对于Ubuntu发行版本可以通过PPA安装,命令如下: sudo add-apt-repository p ...

  8. LeetCode OJ--Best Time to Buy and Sell Stock II

    http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ 第二问,是说可以进行无数次买卖. 贪心法 #include &l ...

  9. 嗅探X-Windows服务按键工具xspy

    嗅探X-Windows服务按键工具xspy   X-Windows完整名字是X Windows图形用户接口.它是一种计算机软件系统和网络协议.它为联网计算机提供了一个基础的图形用户界面(GUI)和丰富 ...

  10. POJ 3259 Wormholes 最短路+负环

    原题链接:http://poj.org/problem?id=3259 题意 有个很厉害的农民,它可以穿越虫洞去他的农场,当然他也可以通过道路,虫洞都是单向的,道路都是双向的,道路会花时间,虫洞会倒退 ...