UVAlive 5867 Finding Feasible Paths 题解

阅读: 评论:0

UVAlive 5867 Finding Feasible Paths 题解

UVAlive 5867 Finding Feasible Paths 题解

题目

Tri_integral Summer Training 4

题意:

一个程序,按照当前的参数执行的顺序也不一样。对于所有可能的参数,检测题目给出的执行顺序是否可能。

题解:

模拟……有2种infeasible的情况:

1、没有数据能满足执行顺序(前后矛盾)。

2、没有正确返回,比如返回后应该执行11的,却跑到21去了,反过来也一样。


//Time:46ms
//Memory:0KB
//Length:2184B
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define MAXN (1<<17)
int pr[MAXN],ptop;
bool check(int a,int b,int &v,int &h)
{for(++h;;++h)switch(pr[h]){case 3:if(a>2)return false;v=b+1;break;case 4:if(a<=2)return false;break;case 6:if(a<=b)return false;++v;break;case 7:if(a>b)return false;break;case 8:--v;break;case 10:if(a>=b+1)return false;if(!check(a-1,b,v,h)) return false;if(pr[h+1]!=11)    return false;break;case 11:return false;if(!check(a-2,v,v,h)) return false;if(pr[h+1]!=14)    return false;break;case 12:if(a<b+1)return false;break;case 13:if(!check(a-3,v,v,h)) return false;if(pr[h+1]!=14)    return false;break;case 15:return true;}return false;
}
int main()
{//freopen("/home/moor/Code/input","r",stdin);int ncase,tmp;bool flag;scanf("%d",&ncase);while(ncase--){flag=0;for(int i=0;i<5;++i)scanf("%d",&pr[i]);for(ptop=0;;++ptop){scanf("%d",&pr[ptop]);if(pr[ptop]==21)break;}for(int x=0;x<=20&&!flag;++x)for(int y=0;y<=100&&!flag;++y){int th=-1;tmp=0;flag=check(x,y,tmp,th);if(pr[th+1]!=21)flag=0;}printf("%sn",flag?"feasible":"infeasible");}return 0;
}


本文发布于:2024-01-28 08:55:28,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17064033306262.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:题解   UVAlive   Finding   Paths   Feasible
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23