这道题屡交屡错,什么鬼!!!!明明就是一个简单的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;
}

  

POJ 2134的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

随机推荐

  1. Cocos2d-x《雷电大战》(3)-子弹无限发射

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 本文要实现雷电游戏中,游戏一開始,英雄飞机就无限发射子弹的功能. 这里的思想是单独给子弹弄一个 ...

  2. 黑马day01 笔记

    一.xml语法   1.文档声明     用来声明xml的基本属性,用来指挥解析引擎怎样去解析当前xml     通常一个xml都要包括而且仅仅能包括一个文档声明     xml的文档必须在整个xml ...

  3. Unsupported major.minor version 52.0 (unable to load class XXX

    java项目构建从高版本JDK改为低版本JDK报错.这是再次编译时使用的JDK版本比你原来编译的版本低所导致的. 转自:http://blog.csdn.net/zixiao217 maven项目在服 ...

  4. [ASPX] 模版引擎XTemplate与代码生成器XCoder(源码)

    模版引擎XTemplate是一个仿T4设计的引擎,功能上基本与T4一致(模版语法上完全兼容T4,模版头指令部分兼容). 自己设计模版引擎,就是为了代码生成器.网站模版.邮件模版等多种场合,也就是要能拿 ...

  5. this关键字和super关键字

    一.this Java中为了解决变量的命名冲突和不确定性问题,引入了关键字this.this代表当前类的一个实例,它经常出现在方法和构造方法中,具体使用情况有以下三种: 1,返回调用当前方法的对象的引 ...

  6. springboot @WebFilter过滤器的使用

    过滤器的用法就不多说了 新建Filter的继承类:MemberFilter(放置包需要注意) @WebFilter(urlPatterns = "/*") @Order(1) pu ...

  7. npm中的 --save-dev

    当你为你的模块安装一个依赖模块时,正常情况下你得先安装他们(在模块根目录下npm install module-name),然后连同版本号手动将他们添加到模块配置文件package.json中的依赖里 ...

  8. SwiftUI 官方教程(七)

    7. 给子 View 传递数据 LandmarkDetail 现在依然使用硬编码的数据来显示地标.像 LandmarkRow 一样,LandmarkDetail 类型和它组合的其他 view 都需要一 ...

  9. c++对象关系映射(ORM)框架

    ORM(Object Relational Mapping, 对象关系映射),用来将基于对象的数据结构映射到SQL的数据结构中,即将基于对象的数据映射到关系表中的字段,然后我们可以通过对象提供的接口来 ...

  10. Codeforces Round #451 & Codeforces Round #452

    Rounding Solution Proper Nutrition 枚举 Solution Phone Numbers 模拟 Solution Alarm Clock 贪心,好像不用线段树也可以,事 ...