BZOJ5012[ioi2017]Train

版权声明:...............转载说一声并注明出处qaq............... https://blog.csdn.net/L_0_Forever_LF/article/details/80747397

下面定义的能走到/不能走到都是在A,B采取最优决策下的

因为充一次电能跑n个点,所以A胜利的条件就是能走到一个有充电站的环,B反之

如果一个充电车站不能走到任何一个充电车站(包括自己),那么我们可以把它视为不能充电的
我们不断bfs求出哪些充电车站不能被其他充电走到,然后去掉他们,重复这个过程直到图中剩余所有充电车站都可以到达一个充电车站
然后看起点是否能走到某个充电车站就知道是否A赢了

bfs用博弈定义下的bfs倒着做,具体来说:
对每个充电车站求出一个能走到这个充电车站的集合S
然后对于其他点
如果他被A控制且有指向S的出边就把他加入S
如果他被B控制且所有出边都指向S就把他加入S
(注意这个充电车站要特殊处理)
不断加点直到无点可加

code:

#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define pb push_back
#define SZ(x) ((int)x.size())
using namespace std;

const int maxn = 5100;
const int maxm = 210000;

int n,m;
int col[maxn],s[maxn],d[maxn];
vector<int>E[maxn],iE[maxn];

int ok[maxn],nd[maxn];
queue<int>q;

int main()
{
    //freopen("tmp.in","r",stdin);
    //freopen("tmp.out","w",stdout);

    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) scanf("%d",&col[i]);
    for(int i=0;i<n;i++) scanf("%d",&s[i]);
    for(int i=1;i<=m;i++)
    {
        int x,y; scanf("%d%d",&x,&y);
        d[x]++;
        E[x].pb(y); iE[y].pb(x);
    }

    int mark=1;
    while(mark)
    {
        mark=0;
        for(int i=0;i<n;i++) ok[i]=0,nd[i]=d[i];
        for(int i=0;i<n;i++) if(s[i])
        {
            for(int j=0;j<SZ(iE[i]);j++)
            {
                int p=iE[i][j];
                nd[p]--;
                if(!ok[p]&&(col[p]||!nd[p])) q.push(p),ok[p]=1;
            }
        }
        while(!q.empty())
        {
            const int y=q.front(); q.pop();
            if(s[y]) continue;

            for(int j=0;j<SZ(iE[y]);j++)
            {
                int x=iE[y][j];
                nd[x]--;
                if(!ok[x]&&(col[x]||!nd[x])) q.push(x),ok[x]=1;
            }
        }

        for(int i=0;i<n;i++) if(s[i])
        {
            if(!ok[i]) mark=1;
            s[i]&=ok[i];
        }
    }
    for(int i=0;i<n;i++) printf("%d%c",ok[i],i!=n-1?' ':'\n');

    return 0;
}
阅读更多

Train Time

11-17

DescriptionnnCity transportation planners are developing a light rail transit system to carry commuters between the suburbs and the downtown area. Part of their task includes scheduling trains on different routes between the outermost stations and the metro center hub. nnnPart of the planning process consists of a simple simulation of train travel. A simulation consists of a series of scenarios in which two trains, one starting at the metro center and one starting at the outermost station of the same route, travel toward each other along the route. The transportation planners want to find out where and when the two trains meet. You are to write a program to determine those results. nnnThis model of train travel is necessarily simplified. All scenarios are based on the following assumptions. nnAll trains spend a fixed amount of time at each station. nAll trains accelerate and decelerate at the same constant rate. All trains have the same maximum possible velocity. nWhen a train leaves a station, it accelerates (at a constant rate) until it reaches its maximum velocity. It remains at that maximum velocity until it begins to decelerate (at the same constant rate) as it approaches the next station. Trains leave stations with an initial velocity of zero (0.0) and they arrive at stations with terminal velocity zero. Adjacent stations on each route are far enough apart to allow a train to accelerate to its maximum velocity before beginning to decelerate. nBoth trains in each scenario make their initial departure at the same time. nThere are at most 30 stations along any route. nInputnnAll input values are real numbers. Data for each scenario are in the following format. nd1 d2 ... dn 0.0nFor a single route, the list of distances (in miles--there are 5,280 feet in a mile) from each station to the metro center hub,separated by one or more spaces. Stations are listed in ascending order, starting with the station closest to the metro center hub (station 1) and continuing to the outermost station. All distances are greater than zero. The list is terminated by the sentinel value 0.0.nvnThe maximum train velocity, in feet/minute.nsnThe constant train acceleration rate in feet/minute².nmnThe number of minutes a train stays in a station.nnThe series of runs is terminated by a data set which begins with the number -1.0.nOutputnnFor each scenario, output consists of the following labeled data. nnnThe number of the scenario (numbered consecutively, starting with Scenario #1). nThe time when the two trains meet in terms of minutes from starting time. All times must be displayed to one decimal place. nThe distance in miles between the metro center hub and the place where the two trains meet. Distances must be displayed to three decimal places. Also, if the trains meet in a station, output the number of the station where they meet. nPrint a blank line after each scenario.nSample Inputnn15.0 0.0n5280.0n10560.0n5.0n3.5 7.0 0.0n5280.0n10560.0n2.0n3.4 7.0 0.0n5280.0n10560.0n2.0n-1.0nSample OutputnnScenario #1n Meeting time: 7.8 minutesn Meeting distance: 7.500 miles from metro center hubnnScenario #2n Meeting time: 4.0 minutesn Meeting distance: 3.500 miles from metro center hub, in station 1nnScenario #3n Meeting time: 4.1 minutesn Meeting distance: 3.400 miles from metro center hub, in station 1

Train Scheduling

02-05

Elihc is a strange country occupying a long, narrow strip of land from north to south. There is only one main railway line in this country. This railway line is a straight line. It starts from the northernmost station, traverses the whole country southward, and finishes at the southernmost station. nnUnfortunately, there are too many trains travelling on this railway line all the time. Long delays, even serious railway accidents are quite common here. Now, Railways Bureau of Elihc decides to solve these problems by scheduling the train in a better way, and hires you to write the program. nnThere are (N+1) stations on this railway line, and they are numbered from 0 to N from north to south. There are also M trains numbered from 0 to M-1. Each train has an initial station, a terminal station, expected time of departure and speed limit. Initially, it parks at its initial station. It departs at the expected time or after the expected time, and is bound for its terminal station. The train has to stop at every station on its route. Different trains may have different speed limits. During the journey, a train should always run within its own speed limit (it is allowed to run at any speed not exceeding the limit anywhere). Compared with the railway line, both stations and trains are so small that they can be regarded as points in your scheduling program. nnFor each pair of adjacent stations, the part of the railway line between them is called a section (stations are not included). The positions of the stations are well designed so that the length of each section is exactly S kilometer. All stations are sufficient to park any number of trains. However, due to some financial difficulties, there is just one track for each section. For safety reasons, trains running on the same section should always follow the rules below. nn1. They are running in the same direction. n2. A train can catch up with, but can never pass any other trains in front of it. nnAn officer of Railways Bureau provides you some scheduling strategies, which you have to use in your program: nn1. During scheduling, trains that are not expected to depart yet should be ignored. If a train has already arrived at its terminal station, it will be ignored forever. n2. Once a train is expected to depart from the original station, or arrives at a station except the terminal one, it stops and waits to move on the next section immediately. n3. When a train is stopping in some station, it will not start to move to the next section until (1) no running train is coming from the opposite direction on this section, and (2) No train with smaller number is stopping and waiting to move on this section from station at either end of this section. n4. A train should always run as fast as it can, without passing any train in front running on the same section. nnNow, please help Railways Bureau to schedule the trains and figure out when each train will reach its terminal station. n输入描述:nnThere are several test cases in the input.n nn The first line contains an integer C (1 ≤ C ≤ 10) -- the number of test cases.n nn Each test case begins with three integers N, M, S (1 ≤ N ≤ 10, 1 ≤ M ≤ 10, 1 ≤ S ≤ 1000), indicating the number of stations, the number of trains and the length of section (in kilometer).n nn Then M lines follow, describing trains from number 0 to M-1 in order, one per line. Each line contains four integers O, T, E, L (0 ≤ O ≤ N, 0 ≤ T ≤ N, O ≠ T, 0 ≤ E ≤ 10000, 1 ≤ L ≤ S), indicate that this train travels from station O to station T, expected to depart at minute E, and its speed limit is L kilometer per minute.nnn输出描述:nnFor each test case, output the arrival time (in minute) of each train one per line, in ascending order of train number. Your answers should be rounded up to the nearest integer.nn输入例子:nn2n1 3 100n0 1 0 5n0 1 20 5n1 0 0 5n2 2 100n0 2 0 4n0 2 2 5nn输出例子:nn20n40n60n50n50

没有更多推荐了,返回首页