码迷,mamicode.com
首页 > 其他好文 > 详细

Game

时间:2015-11-01 15:17:30      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

 

poj 5523

 

这个题目属于事件分析,只要把主要的条理弄清了也就能写了,程序的结果无非4种:-1 0 1 2

首先要知道在n个数中选择任意两个s和t会有很多种,所以应该要减少复杂程度,其中答案属于2的情况最多,因此要先判断 -1 0 1的情况,剩下的就都属于2了

首先如果出口和入口重合的话,那就为-1,不过有一种特殊:n==0时应该是0

其余如果出口在1位置或者n位置,再或者出口和入口相邻应该是1

其余都为2(不可能还存在其他走不出来的情况)

 

 

技术分享
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int solve(int n,int s,int t)
{
    if(n==1) return 0;
    if(s==t) return -1;
    if((s==1&&t==n)||(s==n&&t==1)) return 0;
    if((s==1&&t!=n)||(s==n&&t!=1)||(abs(s-t)==1)) return 1;
    return 2;
}

int main()
{
    int n,s,t;
    while(cin>>n>>s>>t)
        printf("%d\n",solve(n,s,t));
    return 0;
}
View Code

 

Game

标签:

原文地址:http://www.cnblogs.com/zsyacm666666/p/4927684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!