POJ 2134

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

  

时间: 2024-10-15 13:39:56

POJ 2134的相关文章

poj 1062 -- 昂贵的聘礼

昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35515   Accepted: 10163 Description 年 轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿 不出这么多金币,便请求酋长降低要求.酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币.如果你能够弄来他的水晶球,那么只要 5

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)

POJ——T2271 Guardian of Decency

http://poj.org/problem?id=2771 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5932   Accepted: 2463 Description Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is

POJ——T2446 Chessboard

http://poj.org/problem?id=2446 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18560   Accepted: 5857 Description Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of c

poj 1088 滑雪 DP(dfs的记忆化搜索)

题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 求最大的下滑路径 分析:因为只能从高峰滑到低峰,无后效性,所以每个点都可以找到自己的最长下滑距离(只与自己高度有关).记忆每个点的最长下滑距离,当有另一个点的下滑路径遇到这个点的时候,直接加上这个点的最长下滑距离. dp递推式是,dp[x][y] = max(dp[x][y],dp[x+1][y]+

POJ 1385 计算几何 多边形重心

链接: http://poj.org/problem?id=1385 题意: 给你一个多边形,求它的重心 题解: 模板题,但是不知道为啥我的结果输出的确是-0.00 -0.00 所以我又写了个 if (ans.x == 0) ans.x = 0 感觉好傻逼 代码: 1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <queue> 5 #include <stack> 6

POJ 1741 Tree(树的点分治,入门题)

Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21357   Accepted: 7006 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001).Define dist(u,v)=The min distance between node u and v.Give an in

poj 1655 树的重心

Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13178   Accepted: 5565 Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the tree yields a forest: a collection of one or m