这道题屡交屡错,什么鬼!!!!明明就是一个简单的BFS,啊~!!!!!~~~~~~就是一个简单的BFS!!!!~~~~~什么鬼!!!!!!!

FUCK,在discuss里也很多人吐槽,怪不得那么少人做,什么鬼。。。为了不辜负自己写了一晚,把别人的贴过算了,什么鬼!!!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string.h>
#include <queue>
using namespace std;
bool vis[105][105][310];
struct Stat{
int pos,sec,pass_light,speed;
Stat(){}
Stat(int p,int s,int pl,int sp){pos=p,sec=s,pass_light=pl;speed=sp;}
};
queue<Stat>que;
struct traffic{
int pos,tg,tr;
int init,ts;
bool operator<(const traffic &a)const{
if(pos<a.pos) return true;
return false;
}
};
int l,n;
traffic light[110]; bool judge(Stat &t,int k){
if(light[k].init==0){
int tl=t.sec+light[k].ts+1;
tl=tl%(light[k].tr+light[k].tg);
if(tl<light[k].tr&&tl!=0){
if(t.speed==0) return true;
return false;
}
return true;
}
else{
int tl=t.sec+light[k].ts+1;
tl=tl%(light[k].tr+light[k].tg);
if(tl>=light[k].tg||tl==0){
if(t.speed==0) return true;
return false;
}
return true;
}
} int main(){
int pos,tg,tr,ts; char st;
while(scanf("%d%d",&l,&n)!=EOF){
memset(vis,false,sizeof(vis));
for(int i=1;i<=n;i++){
scanf("%d %d %d %c %d",&light[i].pos,&light[i].tg,&light[i].tr,&st,&light[i].ts);
light[i].init=st=='R'?0:1;
}
sort(light+1,light+n+1);
Stat tmp(0,0,1,0); Stat f; bool flag; int k;
vis[0][0][0]=true;
que.push(tmp);
while(!que.empty()){
f=que.front();
que.pop();
// cout<<f.pos<<" "<<f.sec<<" "<<f.speed<<endl;
if(f.pos==l&&f.speed==1){
break;
}
int pos=f.pos+f.speed;
if(pos>l) continue;
k=f.pass_light;
flag=true;
while(pos>=light[k].pos&&k<=n){
if(!judge(f,k)){
flag=false;
break;
}
k++;
}
if(flag){
for(int i=-1;i<=1;i++){
if(f.speed==0&&i==-1) continue;
tmp.pos=f.pos+f.speed;
tmp.sec=f.sec+1;
tmp.speed=f.speed+i;
tmp.pass_light=k;
if(!vis[tmp.pos][tmp.speed][tmp.sec]){
vis[tmp.pos][tmp.speed][tmp.sec]=true;
que.push(tmp);
}
}
}
}
printf("%d\n",f.sec);
while(!que.empty()) que.pop();
}
return 0;
}

  

别人的

#include <stdio.h>
#include <cstring>
typedef struct { int tg, tr, init, tc; } tralight;
typedef struct { int place, speed, time; } cmd;
tralight list[110];
int ltpos[110];
cmd queue[30010]; int now, add;
char sch[110][110][310]; int situ (tralight a, int time)
{
int t = a.tc + time;
t %= (a.tg + a.tr);
if (a.init == 0)
{
if (t >= a.tr) return 1;
else return 0;
}
else
{
if (t >= a.tg) return 0;
else return 1;
}
} int main ()
{
int l, n, i, cp, cs, ct, tp, ts, p, fl, ans; char ar[5];
scanf("%d %d", &l, &n);
memset(ltpos, -1, sizeof(ltpos));
memset(sch, 0, sizeof(sch));
for (i = 0; i < n; i++)
{
scanf("%d %d %d %s %d", &p, &list[i].tg, &list[i].tr, ar, &list[i].tc);
if (ar[0] == 'R') list[i].init = 0;
else list[i].init = 1;
ltpos[p] = i;
}
now = add = 0;
queue[add].place = 0, queue[add].speed = 0, queue[add].time = 0; add++;
sch[0][0][0] = 1;
while (now != add)
{
cp = queue[now].place, cs = queue[now].speed, ct = queue[now].time; now++;
if (cp == l && cs == 1)
{
ans = ct;
break;
}
ts = cs - 1;
if (ts < 0) ts = 0;
tp = cp + cs;
if (ltpos[cp] != -1)
{
if (situ(list[ltpos[cp]], ct) == 0 && cs != 0)
continue;
}
for (i = cp + 1, fl = 0; i < tp; i++)
{
if (ltpos[i] != -1)
{
if (situ(list[ltpos[i]], ct) == 0)
{
fl = 1;
break;
}
}
}
if (fl == 1) continue;
else if (sch[tp][ts][ct + 1] == 0)
{
queue[add].place = tp, queue[add].speed = ts, queue[add].time = ct + 1;
sch[tp][ts][ct + 1] = 1;
add++;
}
ts++;
if (sch[tp][ts][ct + 1] == 0)
{
queue[add].place = tp, queue[add].speed = ts, queue[add].time = ct + 1;
sch[tp][ts][ct + 1] = 1;
add++;
}
ts++;
if (ts > cs + 1) continue;
if (sch[tp][ts][ct + 1] == 0)
{
queue[add].place = tp, queue[add].speed = ts, queue[add].time = ct + 1;
sch[tp][ts][ct + 1] = 1;
add++;
}
}
printf("%d\n", ans);
return 0;
}

  

最新文章

  1. 学习笔记 HTTP参数污染注入
  2. 前端组件化Polymer入门教程(8)——事件
  3. iOS 查询数组中的对象
  4. IT架构之IT架构模型——思维导图
  5. sql2012安装过程中出现个一个问题
  6. Vim Cscope安装与使用
  7. jquery-ui 中treegird 逐步加载
  8. spring cloud官方文档提到的服务开发的12项要素。
  9. PHP面向对象编程学习之对象基础
  10. Coursera 机器学习笔记(三)
  11. python 面向对象之多态与绑定方法
  12. 洛谷 P2345 奶牛集会 解题报告
  13. python os.path模块常用方法详解(转)
  14. JS 为什么在涉及到模块开发this的时候使用类似 self = this 的形式 p7
  15. Problem A: 道路建设 解题报告
  16. Json模块dumps、loads、dump、load函数介绍
  17. IOS项目之弹出动画一
  18. 本地调试 谷歌浏览器报错:跨域问题处理 Access-Control-Allow-Origin
  19. iOS- UIPickerView餐厅点餐系统
  20. openfaas 简单试用

热门文章

  1. cocos2dx 自己主动绑定js
  2. 自己定义隐式转换和显式转换c#简单样例
  3. xcode打包测试
  4. c16---字符串
  5. RDS中的.frm和.ibd文件转换为sql文件
  6. listview 控件
  7. Mac使用ssh登录远程linux系统查看jetty日志及同时使用github工具
  8. matplotlib简介-高质量图形输出
  9. CorelDRAW快速制作绚丽的彩色透明心形
  10. 前端开发—jQuery